primakov/ML4SE2023_Group4_Dataset.csv huggingface dataset:
Functionality: Zip Files
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
public static void main (String [] args) throws IOException {
    FileOutputStream f = new FileOutputStream ("test.zip");
    CheckedOutputStream csum = new CheckedOutputStream (f, new Adler32 ());
    ZipOutputStream zos = new ZipOutputStream (csum);
    BufferedOutputStream out = new BufferedOutputStream (zos);
    zos.setComment ("A test of Java Zipping");
    for (String arg : args) {
        print ("Writing file " + arg);
        BufferedReader in = new BufferedReader (new FileReader (arg));
        zos.putNextEntry (new ZipEntry (arg));
        int c;
        while ((c = in.read ()) != - 1) out.write (c);

        in.close ();
        out.flush ();
    }
    out.close ();
    print ("Checksum: " + csum.getChecksum ().getValue ());
    print ("Reading file");
    FileInputStream fi = new FileInputStream ("test.zip");
    CheckedInputStream csumi = new CheckedInputStream (fi, new Adler32 ());
    ZipInputStream in2 = new ZipInputStream (csumi);
    BufferedInputStream bis = new BufferedInputStream (in2);
    ZipEntry ze;
    while ((ze = in2.getNextEntry ()) != null) {
        print ("Reading file " + ze);
        int x;
        while ((x = bis.read ()) != - 1) System.out.write (x);

    }
    if (args.length == 1) print ("Checksum: " + csumi.getChecksum ().getValue ());

    bis.close ();
    ZipFile zf = new ZipFile ("test.zip");
    Enumeration e = zf.entries ();
    while (e.hasMoreElements ()) {
        ZipEntry ze2 = (ZipEntry) e.nextElement ();
        print ("File: " + ze2);
    }
}

Function 2:
private static void zipDirectory (ZipOutputStream zos, File files, String entry) throws IOException {
    if (files.isDirectory ()) {
        if (entry != null) {
            zos.putNextEntry (new ZipEntry (entry + "/"));
            entry = entry + "/";
        } else {
            zos.putNextEntry (new ZipEntry ("/"));
            entry = "/";
        }
        String [] names = files.list ();
        File [] files0 = files.listFiles ();
        for (int i = 0;
        i < files0.length; i ++) {
            zipDirectory (zos, files0 [i], entry + names [i]);
        }
        zos.closeEntry ();
    } else {
        if (entry != null) {
            zos.putNextEntry (new ZipEntry (entry));
        }
        byte [] data = new byte [1000];
        BufferedInputStream in = new BufferedInputStream (new FileInputStream (files), 1000);
        int count;
        while ((count = in.read (data, 0, 1000)) != - 1) {
            zos.write (data, 0, count);
        }
        zos.closeEntry ();
        in.close ();
    }
}
Functionality: Zip Files
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
public void saveAttributes (Attributes a) throws IOException {
    String extension = fileResourceExtent.getUpperCaseExtension ();
    if ("XML".equals (extension)) {
        this.saveExtentsXML (a);
    } else {
        File file = new File (fileResourceExtent.getAbsoluteFilename ());
        FileOutputStream fos = new FileOutputStream (file);
        ZipOutputStream zout = new ZipOutputStream (fos);
        zout.putNextEntry (new ZipEntry ("Extents"));
        DataOutputStream out = new DataOutputStream (zout);
        saveExtentsBinary (out, a);
        out.close ();
        fos.close ();
    }
    extension = fileResourceMatrix.getUpperCaseExtension ();
    if ("XML".equals (extension)) {
    } else {
        File file = new File (fileResourceMatrix.getAbsoluteFilename ());
        FileOutputStream fos = new FileOutputStream (file);
        ZipOutputStream zout = new ZipOutputStream (fos);
        zout.putNextEntry (new ZipEntry ("Matrix"));
        DataOutputStream out = new DataOutputStream (zout);
        saveMatrixBinary (out, a);
        out.close ();
        fos.close ();
    }
    extension = fileResourceAttributes.getUpperCaseExtension ();
    if ("XML".equals (extension)) {
        this.saveAttributeXML (a);
    } else {
        File file = new File (fileResourceAttributes.getAbsoluteFilename ());
        FileOutputStream fos = new FileOutputStream (file);
        ZipOutputStream zout = new ZipOutputStream (fos);
        zout.putNextEntry (new ZipEntry ("Attributes"));
        DataOutputStream out = new DataOutputStream (zout);
        saveAttributesBinary (out, a);
        out.close ();
        fos.close ();
    }
    String extent_tree_filename_stem = "extent_tree_";
    for (int i = 0;
    i < a.getExtents ().size (); i ++) {
        try {
            saveXMLDocument (extent_tree_filename_stem + i + ".xml", a.getExtents ().at (i).getExtentXML ());
        } catch (Exception e) {
        }
    }
}

Function 2:
public static File zipFile (String pathToBeZipped, String pathZippedFile) throws IOException {
    if (pathZippedFile.indexOf (".zip") < 0) {
        pathZippedFile += ".zip";
    }
    File fileASerZipado = new File (pathToBeZipped);
    byte [] buf = new byte [BUFFER_SIZE];
    ZipOutputStream out = new ZipOutputStream (new FileOutputStream (pathZippedFile));
    FileInputStream in = new FileInputStream (pathToBeZipped);
    out.putNextEntry (new ZipEntry (fileASerZipado.getName ()));
    int len;
    while ((len = in.read (buf)) > 0) {
        out.write (buf, 0, len);
    }
    out.closeEntry ();
    in.close ();
    out.close ();
    return new File (pathZippedFile);
}
Functionality: Zip Files
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
private void packFile (final File file, final ZipOutputStream out, final String name, final FileFilter filter) throws IOException {
    if (filter != null && ! filter.accept (file)) return;

    if (file.isDirectory ()) {
        final File [] list = file.listFiles ();
        if (list == null) return;

        for (final File element : list) if (name == null) packFile (element, out, file.getName (), filter);
        else packFile (element, out, name + "/" + file.getName (), filter);

    } else {
        ZipEntry entry = null;
        if (name == null) entry = new ZipEntry (file.getName ());
        else entry = new ZipEntry (name + "/" + file.getName ());

        try {
            out.putNextEntry (entry);
        } catch (final ZipException e) {
            throw new C4JRuntimeException (format ("Could not pack file ‘%s’.", file.getPath ()), e);
        }
        InputStream fileIn = null;
        try {
            fileIn = new FileInputStream (file);
            use_filetools ().copyStream2Stream (fileIn, out);
        } finally {
            if (fileIn != null) fileIn.close ();

        }
        out.closeEntry ();
    }
}

Function 2:
private void writeDynData (int time_s) throws IOException {
    this.zos.putNextEntry (new ZipEntry ("step." + time_s + ".bin"));
    this.outFile = new DataOutputStream (this.zos);
    this.buf.position (0);
    this.outFile.writeDouble (time_s);
    this.quad.writeDynData (null, this.buf);
    this.outFile.writeInt (this.buf.position ());
    this.outFile.write (this.buf.array (), 0, this.buf.position ());
    this.zos.closeEntry ();
}
Functionality: Copy File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public static void copy (File src, File dst) throws IOException {
    FileChannel inChannel;
    FileChannel outChannel;
    inChannel = new FileInputStream (src).getChannel ();
    outChannel = new FileOutputStream (dst).getChannel ();
    outChannel.transferFrom (inChannel, 0, inChannel.size ());
    inChannel.close ();
    outChannel.close ();
}

Function 2:
public static void main (String [] args) throws ParseException, FileNotFoundException, IOException {
    InputStream input = new BufferedInputStream (UpdateLanguages.class.getResourceAsStream ("definition_template"));
    Translator t = new Translator (input, "UTF8");
    Node template = Translator.Start ();
    File langs = new File ("support/support/translate/languages");
    for (File f : langs.listFiles ()) {
        if (f.getName ().endsWith (".lng")) {
            input = new BufferedInputStream (new FileInputStream (f));
            try {
                Translator.ReInit (input, "UTF8");
            } catch (java.lang.NullPointerException e) {
                new Translator (input, "UTF8");
            }
            Node newFile = Translator.Start ();
            ArrayList < Addition > additions = new ArrayList < Addition > ();
            syncKeys (template, newFile, additions);
            ArrayList < String > fileLines = new ArrayList < String > ();
            Scanner scanner = new Scanner (new BufferedReader (new FileReader (f)));
            while (scanner.hasNextLine ()) {
                fileLines.add (scanner.nextLine ());
            }
            int offset = 0;
            for (Addition a : additions) {
                System.out.println ("Key added " + a + " to " + f.getName ());
                if (a.afterLine < 0 || a.afterLine >= fileLines.size ()) {
                    fileLines.add (a.getAddition (0));
                } else {
                    fileLines.add (a.afterLine + (offset ++) + 1, a.getAddition (0));
                }
            }
            f.delete ();
            Writer writer = new BufferedWriter (new FileWriter (f));
            for (String s : fileLines) writer.write (s + "\n");

            writer.close ();
            System.out.println ("Language " + f.getName () + " had " + additions.size () + " additions");
        }
    }
    File defFile = new File (langs, "language.lng");
    defFile.delete ();
    defFile.createNewFile ();
    InputStream copyStream = new BufferedInputStream (UpdateLanguages.class.getResourceAsStream ("definition_template"));
    OutputStream out = new BufferedOutputStream (new FileOutputStream (defFile));
    int c = 0;
    while ((c = copyStream.read ()) >= 0) out.write (c);

    out.close ();
    System.out.println ("Languages updated.");
}
Functionality: Copy File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public String openFileAsText (String resource) throws IOException {
    StringWriter wtr = new StringWriter ();
    InputStreamReader rdr = new InputStreamReader (openFile (resource));
    try {
        IOUtils.copy (rdr, wtr);
    } finally {
        IOUtils.closeQuietly (rdr);
    }
    return wtr.toString ();
}

Function 2:
public static boolean decodeFileToFile (String infile, String outfile) {
    boolean success = false;
    java.io.InputStream in = null;
    java.io.OutputStream out = null;
    try {
        in = new Base64.InputStream (new java.io.BufferedInputStream (new java.io.FileInputStream (infile)), Base64.DECODE);
        out = new java.io.BufferedOutputStream (new java.io.FileOutputStream (outfile));
        byte [] buffer = new byte [65536];
        int read = - 1;
        while ((read = in.read (buffer)) >= 0) {
            out.write (buffer, 0, read);
        }
        success = true;
    } catch (java.io.IOException exc) {
        exc.printStackTrace ();
    } finally {
        try {
            in.close ();
        } catch (Exception exc) {
        }
        try {
            out.close ();
        } catch (Exception exc) {
        }
    }
    return success;
}
Functionality: CRC32 File Checksum
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
public int checksum () {
    if (checksumset) return checksum_value;

    CRC32 crc32 = new CRC32 ();
    crc32.update ((byte) channel);
    crc32.update ((byte) program);
    crc32.update ((byte) pitchbend_data1);
    crc32.update ((byte) pitchbend_data2);
    for (int i = 0;
    i < events.length; i ++) {
        crc32.update (events [i].getMessage ().getMessage ());
    }
    if (controls != null) {
        int [] sorted = new int [controls.length];
        for (int i = 0;
        i < controls.length; i ++) {
            sorted [i] = (controls [i] << 2) + controls_values [i];
        }
        Arrays.sort (sorted);
        for (int i = 0;
        i < sorted.length; i ++) {
            crc32.update ((byte) (sorted [i] & 0xFF));
            crc32.update ((byte) ((sorted [i] & 0xFF00)>> 2));
        }
    }
    if (activenotes != null) {
        int [] sorted = new int [activenotes.length];
        for (int i = 0;
        i < activenotes.length; i ++) {
            sorted [i] = (activenotes [i] << 2) + activenotes_velocity [i];
        }
        Arrays.sort (sorted);
        for (int i = 0;
        i < sorted.length; i ++) {
            crc32.update ((byte) (sorted [i] & 0xFF));
            crc32.update ((byte) ((sorted [i] & 0xFF00)>> 2));
        }
    }
    checksumset = true;
    checksum_value = (int) crc32.getValue ();
    return checksum_value;
}

Function 2:
private long getCRC (InputStream stream) {
    CRC32 crc = new CRC32 ();
    try {
        byte [] buffer = new byte [1024];
        int length;
        while ((length = stream.read (buffer)) != - 1) {
            crc.update (buffer, 0, length);
        }
    } catch (IOException e) {
        IdeLog.logError (SyncingPlugin.getDefault (), "Error retrieving CRC", e);
    }
    return crc.getValue ();
}
Functionality: CRC32 File Checksum
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
public ActionForward downloadDS (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    if (log.isDebugEnabled ()) {
        log.debug ("Entering 'datastore download' method");
    }
    DocServiceManager mgr = (DocServiceManager) getBean ("docServiceManager");
    List < Document > docsInDS = mgr.listDocuments ();
    response.setContentType ("application/zip");
    response.setHeader ("Content-Disposition", "attachment; filename=\"" + "safe-ds.zip\"");
    ZipOutputStream zipOut = new ZipOutputStream (response.getOutputStream ());
    try {
        CRC32 crc = new CRC32 ();
        for (Document doc : docsInDS) {
            String fileName = doc.getDocumentID ();
            if (! fileName.endsWith (".xml")) {
                fileName += ".xml";
            }
            byte [] docData = mgr.getDocXML (doc.getDocumentID ());
            ZipEntry entry = new ZipEntry (fileName);
            entry.setSize (docData.length);
            crc.reset ();
            crc.update (docData);
            entry.setCrc (crc.getValue ());
            zipOut.putNextEntry (entry);
            try {
                zipOut.write (docData);
            } finally {
                zipOut.closeEntry ();
            }
        }
    } finally {
        zipOut.close ();
    }
    return null;
}

Function 2:
protected void commonInit (String displayName, IDataSource [] dataSource, Unit unit) {
    this.displayName = displayName;
    CRC32 crc = new CRC32 ();
    crc.update (canonicalName.getBytes ());
    this.hashedId = crc.getValue ();
    this.unit = unit;
    this.cursors = new long [this.dataSources.length];
    getStreamManager ().addStream (this);
}
Functionality: Zip Files
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
public void streamDataToZip (VolumeTimeSeries vol, ZipOutputStream zout) throws Exception {
    ZipEntry entry = new ZipEntry (vol.getId () + ".dat");
    zout.putNextEntry (entry);
    if (vol instanceof FloatVolumeTimeSeries) {
        streamData (((FloatVolumeTimeSeries) vol).getData (), zout);
    } else if (vol instanceof RGBVolumeTimeSeries) {
        streamData (((RGBVolumeTimeSeries) vol).getARGBData (), zout);
    } else if (vol instanceof BinaryVolumeTimeSeries) {
        streamData (((BinaryVolumeTimeSeries) vol).getBinaryData (), zout);
    }

}

Function 2:
private void storeProcessList (Date date, List < ProcessList > processListes, boolean doNotOverrideFile) {
    final int BUFFER = 2048;
    String filename = BASE_FILES_PATH + serverGroup + "/processlist/" + sdf.format (date) + ".zip";
    if (doNotOverrideFile && new File (filename).exists ()) return;

    try {
        FileOutputStream dest = new FileOutputStream (filename);
        ZipOutputStream out = new ZipOutputStream (new BufferedOutputStream (dest));
        byte data [] = new byte [BUFFER];
        for (ProcessList processList : processListes) {
            ByteArrayInputStream fi = new ByteArrayInputStream (buildProcessListText (processList).getBytes ());
            BufferedInputStream origin = new BufferedInputStream (fi, BUFFER);
            ZipEntry entry = new ZipEntry (processList.getMysqlServer ().getName () + ".txt");
            out.putNextEntry (entry);
            int count;
            while ((count = origin.read (data, 0, BUFFER)) != - 1) {
                out.write (data, 0, count);
            }
            origin.close ();
        }
        out.close ();
    } catch (Exception e) {
        e.printStackTrace ();
    }
}
Functionality: Copy File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
private static void readAndRewrite (File inFile, File outFile) throws IOException {
    ImageInputStream iis = ImageIO.createImageInputStream (new BufferedInputStream (new FileInputStream (inFile)));
    DcmParser dcmParser = DcmParserFactory.getInstance ().newDcmParser (iis);
    Dataset ds = DcmObjectFactory.getInstance ().newDataset ();
    dcmParser.setDcmHandler (ds.getDcmHandler ());
    dcmParser.parseDcmFile (null, Tags.PixelData);
    PixelDataReader pdReader = pdFact.newReader (ds, iis, dcmParser.getDcmDecodeParam ().byteOrder, dcmParser.getReadVR ());
    System.out.println ("reading " + inFile + "...");
    pdReader.readPixelData (false);
    ImageOutputStream out = ImageIO.createImageOutputStream (new BufferedOutputStream (new FileOutputStream (outFile)));
    DcmEncodeParam dcmEncParam = DcmEncodeParam.IVR_LE;
    ds.writeDataset (out, dcmEncParam);
    ds.writeHeader (out, dcmEncParam, Tags.PixelData, dcmParser.getReadVR (), dcmParser.getReadLength ());
    System.out.println ("writing " + outFile + "...");
    PixelDataWriter pdWriter = pdFact.newWriter (pdReader.getPixelDataArray (), false, ds, out, dcmParser.getDcmDecodeParam ().byteOrder, dcmParser.getReadVR ());
    pdWriter.writePixelData ();
    out.flush ();
    out.close ();
    System.out.println ("done!");
}

Function 2:
public static void moveOutputAsmFile (File inputLocation, File outputLocation) throws Exception {
    FileInputStream inputStream = null;
    FileOutputStream outputStream = null;
    try {
        inputStream = new FileInputStream (inputLocation);
        outputStream = new FileOutputStream (outputLocation);
        byte buffer [] = new byte [1024];
        while (inputStream.available () > 0) {
            int read = inputStream.read (buffer);
            outputStream.write (buffer, 0, read);
        }
        inputLocation.delete ();
    } finally {
        IOUtil.closeAndIgnoreErrors (inputStream);
        IOUtil.closeAndIgnoreErrors (outputStream);
    }
}
Functionality: Secure Hash
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
private String generate (String value) throws Exception {
    String resStr = null;
    try {
        MessageDigest md = MessageDigest.getInstance ("MD5");
        md.update (value.getBytes ("utf-8"), 0, value.length ());
        byte [] result = md.digest ();
        resStr = FTGenerate.convertToHex (result);
        md.reset ();
    } catch (NoSuchAlgorithmException nae) {
        this.getLog ().severe ("Hash no funcionando");
        nae.printStackTrace ();
        throw new Exception ("Hash no funcionando");
    } catch (UnsupportedEncodingException ee) {
        this.getLog ().severe ("Encoding no funcionando");
        ee.printStackTrace ();
        throw new Exception ("Encoding no funcionando");
    }
    return resStr;
}

Function 2:
private JeeObserverServerContext (JeeObserverServerContextProperties properties) throws DatabaseException, ServerException {
    super ();
    try {
        final MessageDigest md5 = MessageDigest.getInstance ("MD5");
        md5.update (("JE" + System.currentTimeMillis ()).getBytes ());
        final BigInteger hash = new BigInteger (1, md5.digest ());
        this.sessionId = hash.toString (16).toUpperCase ();
    } catch (final Exception e) {
        this.sessionId = "JE" + System.currentTimeMillis ();
        JeeObserverServerContext.logger.log (Level.WARNING, "JeeObserver Server session ID MD5 error: {0}", this.sessionId);
        JeeObserverServerContext.logger.log (Level.FINEST, e.getMessage (), e);
    }
    try {
        @SuppressWarnings("unchecked")
        final Class < DatabaseHandler > databaseHandlerClass = (Class < DatabaseHandler >) Class.forName (properties.getDatabaseHandler ());
        final Constructor < DatabaseHandler > handlerConstructor = databaseHandlerClass.getConstructor (new Class < ? > [] {String.class, String.class, String.class, String.class, String.class, Integer.class});
        this.databaseHandler = handlerConstructor.newInstance (new Object [] {properties.getDatabaseDriver (), properties.getDatabaseUrl (), properties.getDatabaseUser (), properties.getDatabasePassword (), properties.getDatabaseSchema (), new Integer (properties.getDatabaseConnectionPoolSize ())});
    } catch (final Exception e) {
        throw new ServerException ("Database handler loading exception.", e);
    }
    this.databaseHandlerTimer = new Timer (JeeObserverServerContext.DATABASE_HANDLER_TASK_NAME, true);
    this.server = new JeeObserverServer (properties.getServerPort ());
    this.enabled = true;
    this.properties = properties;
    this.startTimestamp = new Date ();
    try {
        this.ip = InetAddress.getLocalHost ().getHostAddress ();
    } catch (final UnknownHostException e) {
        JeeObserverServerContext.logger.log (Level.SEVERE, e.getMessage (), e);
    }
    this.operatingSystemName = System.getProperty ("os.name");
    this.operatingSystemVersion = System.getProperty ("os.version");
    this.operatingSystemArchitecture = System.getProperty ("os.arch");
    this.javaVersion = System.getProperty ("java.version");
    this.javaVendor = System.getProperty ("java.vendor");
}
Functionality: Secure Hash
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public static byte [] SHA1 (String text) throws NoSuchAlgorithmException, UnsupportedEncodingException {
    MessageDigest md;
    md = MessageDigest.getInstance ("SHA-1");
    byte [] sha1hash = new byte [40];
    md.update (text.getBytes ("iso-8859-1"), 0, text.length ());
    sha1hash = md.digest ();
    return sha1hash;
}

Function 2:
public static String encrypt (String password, String algorithm, byte [] salt) {
    StringBuffer buffer = new StringBuffer ();
    MessageDigest digest = null;
    int size = 0;
    if ("CRYPT".equalsIgnoreCase (algorithm)) {
        throw new InternalError ("Not implemented");
    } else if ("SHA".equalsIgnoreCase (algorithm) || "SSHA".equalsIgnoreCase (algorithm)) {
        size = 20;
        if (salt != null && salt.length > 0) {
            buffer.append ("{SSHA}");
        } else {
            buffer.append ("{SHA}");
        }
        try {
            digest = MessageDigest.getInstance ("SHA-1");
        } catch (NoSuchAlgorithmException e) {
            throw new InternalError ("Invalid algorithm");
        }
    } else if ("MD5".equalsIgnoreCase (algorithm) || "SMD5".equalsIgnoreCase (algorithm)) {
        size = 16;
        if (salt != null && salt.length > 0) {
            buffer.append ("{SMD5}");
        } else {
            buffer.append ("{MD5}");
        }
        try {
            digest = MessageDigest.getInstance ("MD5");
        } catch (NoSuchAlgorithmException e) {
            throw new InternalError ("Invalid algorithm");
        }
    }

    int outSize = size;
    digest.reset ();
    digest.update (password.getBytes ());
    if (salt != null && salt.length > 0) {
        digest.update (salt);
        outSize += salt.length;
    }
    byte [] out = new byte [outSize];
    System.arraycopy (digest.digest (), 0, out, 0, size);
    if (salt != null && salt.length > 0) {
        System.arraycopy (salt, 0, out, size, salt.length);
    }
    buffer.append (Base64.encode (out));
    return buffer.toString ();
}