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

Function 1:
private void writeInfos () throws IOException {
    zos.putNextEntry (new ZipEntry ("info.bin"));
    outFile = new DataOutputStream (zos);
    outFile.writeInt (VERSION);
    outFile.writeInt (MINORVERSION);
    outFile.writeDouble (intervall_s);
    zos.closeEntry ();
}

Function 2:
public static boolean zipFiles (File output, File...input) {
    if (output == null || input == null || input.length == 0) {
        return false;
    }
    if (! deleteFile (output)) {
        return false;
    }
    byte [] buf = new byte [1024];
    ZipOutputStream out = null;
    try {
        out = new ZipOutputStream (new FileOutputStream (output));
        for (int i = 0;
        i < input.length; i ++) {
            FileInputStream in = null;
            try {
                in = new FileInputStream (input [i]);
                out.putNextEntry (new ZipEntry (input [i].getName ()));
                int len;
                while ((len = in.read (buf)) > 0) {
                    out.write (buf, 0, len);
                }
                out.closeEntry ();
            } finally {
                FileUtil.close (in);
            }
        }
    } catch (IOException ex) {
        ShowDownLog.getInstance ().logError (ex.getLocalizedMessage (), ex);
        return false;
    } finally {
        FileUtil.close (out);
    }
    return true;
}
Functionality: Copy File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public static void fastBackup (File file) {
    FileChannel in = null;
    FileChannel out = null;
    FileInputStream fin = null;
    FileOutputStream fout = null;
    try {
        in = (fin = new FileInputStream (file)).getChannel ();
        out = (fout = new FileOutputStream (file.getAbsolutePath () + ".bak")).getChannel ();
        in.transferTo (0, in.size (), out);
    } catch (IOException e) {
        Logging.getErrorLog ().reportError ("Fast backup failure (" + file.getAbsolutePath () + "): " + e.getMessage ());
    } finally {
        if (fin != null) {
            try {
                fin.close ();
            } catch (IOException e) {
                Logging.getErrorLog ().reportException ("Failed to close file input stream", e);
            }
        }
        if (fout != null) {
            try {
                fout.close ();
            } catch (IOException e) {
                Logging.getErrorLog ().reportException ("Failed to close file output stream", e);
            }
        }
        if (in != null) {
            try {
                in.close ();
            } catch (IOException e) {
                Logging.getErrorLog ().reportException ("Failed to close file channel", e);
            }
        }
        if (out != null) {
            try {
                out.close ();
            } catch (IOException e) {
                Logging.getErrorLog ().reportException ("Failed to close file channel", e);
            }
        }
    }
}

Function 2:
public static File copy (String inFileName, String outFileName) throws IOException {
    File inputFile = new File (inFileName);
    File outputFile = new File (outFileName);
    FileReader in = new FileReader (inputFile);
    FileWriter out = new FileWriter (outputFile);
    int c;
    while ((c = in.read ()) != - 1) out.write (c);

    in.close ();
    out.close ();
    return outputFile;
}
Functionality: CRC32 File Checksum
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
@Override
public void run () {
    final Random r = new Random ();
    final Counter counter = new Counter ("TRANSMIT", plotter);
    counter.start ();
    try {
        final DataOutputStream dos = new DataOutputStream (new BufferedOutputStream (s.getOutputStream ()));
        while (! Thread.interrupted ()) {
            if (! running.get ()) {
                Thread.sleep (1000);
                continue;
            }
            final int packetSize = r.nextInt (8192) + 2048;
            final byte [] packet = new byte [packetSize];
            r.nextBytes (packet);
            final CRC32 crc = new CRC32 ();
            crc.update (packet);
            dos.writeInt (packetSize);
            counter.addBytes (INTEGER_BYTES);
            dos.write (packet);
            counter.addBytes (packetSize);
            dos.writeLong (crc.getValue ());
            counter.addBytes (CRC_BYTES);
            dos.flush ();
        }
    } catch (InterruptedException e) {
        System.out.println ("Transmitter thread interrupted!");
    } catch (Exception e) {
        System.err.println ("Unexpected error in transmitter thread: " + e.getMessage ());
    } finally {
        abortLatch.countDown ();
        counter.interrupt ();
    }
}

Function 2:
private void cRC32Test (byte [] values, long expected) {
    CRC32 crc = new CRC32 ();
    crc.update (values);
    assertEquals (crc.getValue (), expected);
    crc.reset ();
    for (int i = 0;
    i < values.length; i ++) {
        crc.update (values [i]);
    }
    assertEquals (crc.getValue (), expected);
}
Functionality: Zip Files
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
public BufferedWriter createOutputStream (String inFile, String outFile) throws IOException {
    int k_blockSize = 1024;
    int byteCount;
    char [] buf = new char [k_blockSize];
    File ofp = new File (outFile);
    ZipOutputStream zos = new ZipOutputStream (new FileOutputStream (ofp));
    zos.setMethod (ZipOutputStream.DEFLATED);
    OutputStreamWriter osw = new OutputStreamWriter (zos, "ISO-8859-1");
    BufferedWriter bw = new BufferedWriter (osw);
    ZipEntry zot = null;
    File ifp = new File (inFile);
    ZipInputStream zis = new ZipInputStream (new FileInputStream (ifp));
    InputStreamReader isr = new InputStreamReader (zis, "ISO-8859-1");
    BufferedReader br = new BufferedReader (isr);
    ZipEntry zit = null;
    while ((zit = zis.getNextEntry ()) != null) {
        if (zit.getName ().equals ("content.xml")) {
            continue;
        }
        zot = new ZipEntry (zit.getName ());
        zos.putNextEntry (zot);
        while ((byteCount = br.read (buf, 0, k_blockSize)) >= 0) bw.write (buf, 0, byteCount);

        bw.flush ();
        zos.closeEntry ();
    }
    zos.putNextEntry (new ZipEntry ("content.xml"));
    bw.flush ();
    osw = new OutputStreamWriter (zos, "UTF8");
    bw = new BufferedWriter (osw);
    return bw;
}

Function 2:
private static String addFile (File ff, ZipOutputStream zipOutPic, String filename) throws Exception {
    FileInputStream file = new FileInputStream (ff);
    String ext = getFileExt (ff.getName ());
    if (! ext.equals ("")) {
        ext = "." + ext;
    }
    int randomString = ((int) (Math.random () * 1000000));
    while (randomList.contains (randomString)) {
        randomString = ((int) (Math.random () * 1000000));
    }
    randomList.add (randomString);
    String newFilename = filename == null ? randomString + ext : filename;
    ZipEntry entryPic = new ZipEntry (newFilename);
    zipOutPic.putNextEntry (entryPic);
    byte [] buf = new byte [1024];
    int len;
    while ((len = file.read (buf)) > 0) {
        zipOutPic.write (buf, 0, len);
    }
    zipOutPic.closeEntry ();
    return newFilename;
}
Functionality: Zip Files
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
public BufferedWriter createOutputStream (String inFile, String outFile) throws IOException {
    int k_blockSize = 1024;
    int byteCount;
    char [] buf = new char [k_blockSize];
    File ofp = new File (outFile);
    ZipOutputStream zos = new ZipOutputStream (new FileOutputStream (ofp));
    zos.setMethod (ZipOutputStream.DEFLATED);
    OutputStreamWriter osw = new OutputStreamWriter (zos, "ISO-8859-1");
    BufferedWriter bw = new BufferedWriter (osw);
    ZipEntry zot = null;
    File ifp = new File (inFile);
    ZipInputStream zis = new ZipInputStream (new FileInputStream (ifp));
    InputStreamReader isr = new InputStreamReader (zis, "ISO-8859-1");
    BufferedReader br = new BufferedReader (isr);
    ZipEntry zit = null;
    while ((zit = zis.getNextEntry ()) != null) {
        if (zit.getName ().equals ("content.xml")) {
            continue;
        }
        zot = new ZipEntry (zit.getName ());
        zos.putNextEntry (zot);
        while ((byteCount = br.read (buf, 0, k_blockSize)) >= 0) bw.write (buf, 0, byteCount);

        bw.flush ();
        zos.closeEntry ();
    }
    zos.putNextEntry (new ZipEntry ("content.xml"));
    bw.flush ();
    osw = new OutputStreamWriter (zos, "UTF8");
    bw = new BufferedWriter (osw);
    return bw;
}

Function 2:
private void writeIntoZip (ZipOutputStream output, String name, InputStream input) throws Exception {
    output.putNextEntry (new ZipEntry (name));
    int size = 0;
    byte [] buffer = new byte [1024];
    while ((size = input.read (buffer, 0, buffer.length)) > 0) {
        output.write (buffer, 0, size);
    }
    output.closeEntry ();
    input.close ();
}
Functionality: Zip Files
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
private static void addFileToZip (String path, String srcFile, ZipOutputStream zip) throws Exception {
    File folder = new File (srcFile);
    if (folder.isDirectory ()) {
        addFolderToZip (path, srcFile, zip);
    } else {
        byte [] buf = new byte [1024];
        int len;
        FileInputStream in = new FileInputStream (srcFile);
        zip.putNextEntry (new ZipEntry (path + "\\" + folder.getName ()));
        while ((len = in.read (buf)) > 0) {
            zip.write (buf, 0, len);
        }
    }
}

Function 2:
public static void insertModuleinfo (ZipOutputStream dest, ModuleInfo info) throws IOException {
    ZipEntry zse = new ZipEntry (ModuleInfo.MODULEINFO_RAK);
    dest.putNextEntry (zse);
    info.write (dest);
    dest.flush ();
}
Functionality: Zip Files
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
private void backupDiskFile (ZipOutputStream out, String fileName, DiskFile file) throws SQLException, IOException {
    Database db = session.getDatabase ();
    fileName = FileUtils.getFileName (fileName);
    out.putNextEntry (new ZipEntry (fileName));
    int pos = - 1;
    int max = file.getReadCount ();
    while (true) {
        pos = file.copyDirect (pos, out);
        if (pos < 0) {
            break;
        }
        db.setProgress (DatabaseEventListener.STATE_BACKUP_FILE, fileName, pos, max);
    }
    out.closeEntry ();
}

Function 2:
private void addToArchive (ZipOutputStream stream, File file, FileFilter filter, String entryName, int recurseDepth) throws IOException {
    if (file.exists ()) {
        if (file.isDirectory ()) {
            File [] ls = file.listFiles (filter);
            if (ls.length == 0) {
                if (archiveEntryList_.contains (entryName + "/")) {
                    System.err.println ("  warning: duplicate entry: " + entryName + "/" + ". Skipping.");
                } else {
                    System.out.println ("  " + file);
                    ZipEntry newEntry = new ZipEntry (entryName + "/");
                    stream.putNextEntry (newEntry);
                    stream.closeEntry ();
                    archiveEntryList_.add (entryName + "/");
                }
            }
            for (int i = 0;
            i < ls.length; i ++) {
                String ename = ls [i].getAbsolutePath ();
                ename = entryName + ename.substring (file.getAbsolutePath ().length ());
                ename = convertToGenericPath (ename);
                if (ename.startsWith ("/")) ename = ename.substring (1);

                if (recurseDepth > 0) addToArchive (stream, ls [i], filter, ename, recurseDepth - 1);

            }
        } else if (archiveEntryList_.contains (entryName)) {
            System.err.println ("  warning: duplicate entry: " + entryName + ". Skipping.");
        } else {
            System.out.println ("  " + file);
            archivecount_ ++;
            ZipEntry newEntry = new ZipEntry (entryName);
            stream.putNextEntry (newEntry);
            FileInputStream in = new FileInputStream (file);
            byte [] buf = new byte [2048];
            int read = in.read (buf, 0, buf.length);
            while (read > 0) {
                stream.write (buf, 0, read);
                read = in.read (buf, 0, buf.length);
            }
            in.close ();
            stream.closeEntry ();
            archiveEntryList_.add (entryName);
        }

    } else {
        System.err.println ("  error: file " + file + " does not exist. Skipping.");
    }
}
Functionality: Secure Hash
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
private static byte [] createMD5 (String seed) throws UnsupportedEncodingException, NoSuchAlgorithmException {
    MessageDigest md5 = MessageDigest.getInstance ("MD5");
    md5.reset ();
    md5.update (seed.getBytes ("UTF-8"));
    return md5.digest ();
}

Function 2:
private void getRandomGUID (boolean secure) {
    MessageDigest md5 = null;
    StringBuffer sbValueBeforeMD5 = new StringBuffer ();
    try {
        md5 = MessageDigest.getInstance ("MD5");
    } catch (NoSuchAlgorithmException e) {
        System.out.println ("Error: " + e);
    }
    try {
        long time = System.currentTimeMillis ();
        long rand = 0;
        if (secure) {
            rand = mySecureRand.nextLong ();
        } else {
            rand = myRand.nextLong ();
        }
        sbValueBeforeMD5.append (s_id);
        sbValueBeforeMD5.append (":");
        sbValueBeforeMD5.append (Long.toString (time));
        sbValueBeforeMD5.append (":");
        sbValueBeforeMD5.append (Long.toString (rand));
        valueBeforeMD5 = sbValueBeforeMD5.toString ();
        md5.update (valueBeforeMD5.getBytes ());
        byte [] array = md5.digest ();
        StringBuffer sb = new StringBuffer ();
        for (int j = 0;
        j < array.length; ++ j) {
            int b = array [j] & 0xFF;
            if (b < 0x10) sb.append ('0');

            sb.append (Integer.toHexString (b));
        }
        valueAfterMD5 = sb.toString ();
    } catch (Exception e) {
        System.out.println ("Error:" + e);
    }
}
Functionality: Delete Folder and Contents
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
protected void flatten (File dir) {
    assert dir.isDirectory ();
    File [] files = dir.listFiles ();
    for (int i = 0;
    i < files.length; i ++) {
        File subfile = files [i];
        if (subfile.isFile ()) {
            continue;
        } else {
            flatten (subfile);
            File [] subfiles = subfile.listFiles ();
            for (int j = 0;
            j < subfiles.length; j ++) {
                File f = subfiles [j];
                File temp = new File (subfile.getParent () + '\\' + subfile.getName () + '_' + f.getName ());
                if (f.renameTo (temp) == false) {
                    throw new RuntimeException ("Cannot rename: " + f.toString ());
                } else {
                    System.out.println (f.toString () + ". Rename OK!");
                }
            }
            if (subfile.delete () == false) {
                throw new RuntimeException ("Cannot delete: " + subfile.toString ());
            }
        }
    }
}

Function 2:
public static boolean deleteDirectory (File path) {
    if (path.exists ()) {
        File [] files = path.listFiles ();
        for (int i = 0;
        i < files.length; i ++) {
            if (files [i].isDirectory ()) {
                deleteDirectory (files [i]);
            } else {
                files [i].delete ();
            }
        }
    }
    return (path.delete ());
}
Functionality: Copy File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public static void copyFile (File srcFile, File destFolder) {
    try {
        File destFile = new File (destFolder, srcFile.getName ());
        if (destFile.exists ()) {
            throw new BuildException ("Could not copy " + srcFile + " to " + destFolder + " as " + destFile + " already exists");
        }
        FileChannel srcChannel = null;
        FileChannel destChannel = null;
        try {
            srcChannel = new FileInputStream (srcFile).getChannel ();
            destChannel = new FileOutputStream (destFile).getChannel ();
            destChannel.transferFrom (srcChannel, 0, srcChannel.size ());
        } finally {
            if (srcChannel != null) {
                srcChannel.close ();
            }
            if (destChannel != null) {
                destChannel.close ();
            }
        }
        destFile.setLastModified ((srcFile.lastModified ()));
    } catch (IOException e) {
        throw new BuildException ("Could not copy " + srcFile + " to " + destFolder + ": " + e, e);
    }
}

Function 2:
private void copyOneFile (String oldPath, String newPath) {
    File copiedFile = new File (newPath);
    try {
        FileInputStream source = new FileInputStream (oldPath);
        FileOutputStream destination = new FileOutputStream (copiedFile);
        FileChannel sourceFileChannel = source.getChannel ();
        FileChannel destinationFileChannel = destination.getChannel ();
        long size = sourceFileChannel.size ();
        sourceFileChannel.transferTo (0, size, destinationFileChannel);
        source.close ();
        destination.close ();
    } catch (Exception exc) {
        exc.printStackTrace ();
    }
}
Functionality: Zip Files
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
private void ZipCode (NpsContext ctxt, ZipOutputStream out) throws Exception {
    String filename = "JOB" + GetId () + ".data";
    out.putNextEntry (new ZipEntry (filename));
    try {
        ZipWriter writer = new ZipWriter (out);
        writer.print (code);
    } finally {
        out.closeEntry ();
    }
}

Function 2:
public synchronized void backupStore (String name) throws IOException {
    if (null != name && name.length () > 0) {
        String path = this.directoryPath + File.separator + name;
        File file = new File (path);
        if (file.exists () && file.isDirectory ()) {
            String list [] = file.list ();
            byte [] buf = new byte [1024];
            ZipOutputStream out = null;
            String zipFileName = null;
            try {
                zipFileName = this.directoryPath + File.separator + "backup_" + System.currentTimeMillis () + "_" + name + ".zip";
                out = new ZipOutputStream (new FileOutputStream (zipFileName));
            } catch (FileNotFoundException x) {
                getLogger ().error ("This should never happen", x);
                throw new IOException ("Couldn't get ZipFile (" + zipFileName + ")!");
            }
            for (int i = 0;
            i < list.length; i ++) {
                try {
                    FileInputStream in = new FileInputStream (path + File.separator + list [i]);
                    out.putNextEntry (new ZipEntry (list [i]));
                    int len;
                    while ((len = in.read (buf)) > 0) {
                        out.write (buf, 0, len);
                    }
                    out.closeEntry ();
                    in.close ();
                } catch (IOException x) {
                    getLogger ().error (x.getMessage (), x);
                }
            }
            out.close ();
        } else {
            throw new IOException ("Invalid Store (" + name + ")!");
        }
    } else {
        throw new IOException ("Invalid Store (" + name + ")!");
    }
}
Functionality: Copy File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public static void copyFile (String source, String destination, TimeSlotTracker timeSlotTracker) {
    LOG.info ("copying [" + source + "] to [" + destination + "]");
    BufferedInputStream sourceStream = null;
    BufferedOutputStream destStream = null;
    try {
        File destinationFile = new File (destination);
        if (destinationFile.exists ()) {
            destinationFile.delete ();
        }
        sourceStream = new BufferedInputStream (new FileInputStream (source));
        destStream = new BufferedOutputStream (new FileOutputStream (destinationFile));
        int readByte;
        while ((readByte = sourceStream.read ()) > 0) {
            destStream.write (readByte);
        }
        Object [] arg = {destinationFile.getName ()};
        String msg = timeSlotTracker.getString ("datasource.xml.copyFile.copied", arg);
        LOG.fine (msg);
    } catch (Exception e) {
        Object [] expArgs = {e.getMessage ()};
        String expMsg = timeSlotTracker.getString ("datasource.xml.copyFile.exception", expArgs);
        timeSlotTracker.errorLog (expMsg);
        timeSlotTracker.errorLog (e);
    } finally {
        try {
            if (destStream != null) {
                destStream.close ();
            }
            if (sourceStream != null) {
                sourceStream.close ();
            }
        } catch (Exception e) {
            Object [] expArgs = {e.getMessage ()};
            String expMsg = timeSlotTracker.getString ("datasource.xml.copyFile.exception", expArgs);
            timeSlotTracker.errorLog (expMsg);
            timeSlotTracker.errorLog (e);
        }
    }
}

Function 2:
public static boolean copy (InputStream is, File file) {
    try {
        FileOutputStream fos = new FileOutputStream (file);
        IOUtils.copy (is, fos);
        is.close ();
        fos.close ();
        return true;
    } catch (Exception e) {
        System.err.println (e.getMessage ());
        return false;
    }
}
Functionality: Secure Hash
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public static final String encryptMD5 (String decrypted) {
    try {
        MessageDigest md5 = MessageDigest.getInstance ("MD5");
        md5.update (decrypted.getBytes ());
        byte hash [] = md5.digest ();
        md5.reset ();
        return hashToHex (hash);
    } catch (NoSuchAlgorithmException _ex) {
        return null;
    }
}

Function 2:
public static String createMD5 (String str) {
    String sig = null;
    String strSalt = str + sSalt;
    try {
        MessageDigest md5 = MessageDigest.getInstance ("MD5");
        md5.update (strSalt.getBytes (), 0, strSalt.length ());
        byte byteData [] = md5.digest ();
        StringBuffer sb = new StringBuffer ();
        for (int i = 0;
        i < byteData.length; i ++) {
            sb.append (Integer.toString ((byteData [i] & 0xff) + 0x100, 16).substring (1));
        }
        sig = sb.toString ();
    } catch (NoSuchAlgorithmException e) {
        System.err.println ("Can not use md5 algorithm");
    }
    return sig;
}
Functionality: Copy File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public static void copyFile (File from, File to) throws IOException {
    ensureFile (to);
    FileChannel srcChannel = new FileInputStream (from).getChannel ();
    FileChannel dstChannel = new FileOutputStream (to).getChannel ();
    dstChannel.transferFrom (srcChannel, 0, srcChannel.size ());
    srcChannel.close ();
    dstChannel.close ();
}

Function 2:
private void zip (FileHolder fileHolder, int zipCompressionLevel) {
    byte [] buffer = new byte [BUFFER_SIZE];
    int bytes_read;
    if (fileHolder.selectedFileList.size () == 0) {
        return;
    }
    File zipDestFile = new File (fileHolder.destFiles [0]);
    try {
        ZipOutputStream outStream = new ZipOutputStream (new FileOutputStream (zipDestFile));
        for (int i = 0;
        i < fileHolder.selectedFileList.size (); i ++) {
            File selectedFile = fileHolder.selectedFileList.get (i);
            super.currentObjBeingProcessed = selectedFile;
            this.inStream = new FileInputStream (selectedFile);
            ZipEntry entry = new ZipEntry (selectedFile.getName ());
            outStream.setLevel (zipCompressionLevel);
            outStream.putNextEntry (entry);
            while ((bytes_read = this.inStream.read (buffer)) != - 1) {
                outStream.write (buffer, 0, bytes_read);
            }
            outStream.closeEntry ();
            this.inStream.close ();
        }
        outStream.close ();
    } catch (IOException e) {
        errEntry.setThrowable (e);
        errEntry.setAppContext ("gzip()");
        errEntry.setAppMessage ("Error zipping: " + zipDestFile);
        logger.logError (errEntry);
    }
    return;
}