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

Function 1:
void initOut () throws IOException {
    if (zipped) {
        zout = new ZipOutputStream (sink);
        zout.putNextEntry (new ZipEntry ("file.xml"));
        this.xout = new OutputStreamWriter (zout, "UTF8");
    } else {
        this.xout = new OutputStreamWriter (sink, "UTF8");
    }
}

Function 2:
private void addToJar (JarOutputStream out, InputStream in, String entryName, long length) throws IOException {
    byte [] buf = new byte [2048];
    ZipEntry entry = new ZipEntry (entryName);
    CRC32 crc = new CRC32 ();
    entry.setSize (length);
    entry.setCrc (crc.getValue ());
    out.putNextEntry (entry);
    int read = in.read (buf);
    while (read > 0) {
        crc.update (buf, 0, read);
        out.write (buf, 0, read);
        read = in.read (buf);
    }
    entry.setCrc (crc.getValue ());
    in.close ();
    out.closeEntry ();
}
Functionality: Zip Files
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
private static void createZip (final File destinationFile, final List < File > files, final int cutFileNameIndex) throws IOException {
    final ZipOutputStream oStream = new ZipOutputStream (new FileOutputStream (destinationFile));
    for (final File file : files) {
        final String fullFileName = file.getAbsolutePath ();
        final String cuttedFileName = fullFileName.substring (cutFileNameIndex);
        final String osIndependendFileName = cuttedFileName.replace (File.separatorChar, '/');
        oStream.putNextEntry (new ZipEntry (osIndependendFileName));
        final FileInputStream iStream = new FileInputStream (file);
        FileOperations.copy (iStream, oStream);
        oStream.closeEntry ();
        iStream.close ();
    }
    oStream.close ();
}

Function 2:
private void addFile (ZipOutputStream zos, String path, Element details, String name) throws Exception {
    ZipEntry entry = new ZipEntry (name);
    zos.putNextEntry (entry);
    BinaryFile.write (details, zos);
    zos.closeEntry ();
}
Functionality: Load File into Byte Array
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
private byte [] getFileContents (String fileName) throws Exception {
    ByteArrayOutputStream ba = new ByteArrayOutputStream ();
    FileInputStream fis = new FileInputStream (fileName);
    byte [] data = new byte [1024];
    int read = fis.read (data, 0, 1024);
    while (read > - 1) {
        ba.write (data, 0, read);
        read = fis.read (data, 0, 1024);
    }
    fis.close ();
    return ba.toByteArray ();
}

Function 2:
public static boolean unZip (String zipname, String extractTo) {
    InputStream is;
    ZipInputStream zis;
    try {
        is = new FileInputStream (extractTo + zipname);
        zis = new ZipInputStream (new BufferedInputStream (is));
        ZipEntry ze;
        while ((ze = zis.getNextEntry ()) != null) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream ();
            byte [] buffer = new byte [1024];
            int count;
            String filename = ze.getName ();
            FileOutputStream fout = new FileOutputStream (extractTo + filename);
            while ((count = zis.read (buffer)) != - 1) {
                baos.write (buffer, 0, count);
                byte [] bytes = baos.toByteArray ();
                fout.write (bytes);
                baos.reset ();
            }
            fout.flush ();
            fout.close ();
            zis.closeEntry ();
        }
        zis.close ();
    } catch (IOException e) {
        e.printStackTrace ();
        return false;
    }
    return true;
}
Functionality: Zip Files
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
public synchronized void writeFile (String filename) throws IOException {
    int amount;
    byte buffer [] = new byte [4096];
    File f = new File (filename);
    FileInputStream in = new FileInputStream (f);
    putNextEntry (new ZipEntry (f.getName ()));
    while ((amount = in.read (buffer)) != - 1) write (buffer, 0, amount);

    closeEntry ();
    in.close ();
}

Function 2:
private void zipTempDir (String dir2zip, ZipOutputStream zos) {
    try {
        File zipDir = new File (dir2zip);
        String [] dirList = zipDir.list ();
        byte [] readBuffer = new byte [2156];
        int bytesIn = 0;
        for (int i = 0;
        i < dirList.length; i ++) {
            File f = new File (zipDir, dirList [i]);
            if (f.isDirectory ()) {
                String filePath = f.getPath ();
                zipTempDir (filePath, zos);
                continue;
            }
            FileInputStream fis = new FileInputStream (f);
            String filePath = f.getPath ();
            filePath = getZipPath (filePath);
            ZipEntry anEntry = new ZipEntry (filePath);
            zos.putNextEntry (anEntry);
            while ((bytesIn = fis.read (readBuffer)) != - 1) {
                zos.write (readBuffer, 0, bytesIn);
            }
            fis.close ();
        }
    } catch (Exception e) {
        System.out.println ("Could not do the zipDir process. debug zipDir()");
        System.out.println ("This would be an internal variable configuration error. I guess you'll have to debug it");
        e.printStackTrace ();
        System.exit (1);
    }
}
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:
public static void saveToZipFile (File f, ByteBuffer buf) {
    try {
        FileOutputStream fOut = new FileOutputStream (f);
        ZipOutputStream zipOut = new ZipOutputStream (fOut);
        zipOut.putNextEntry (new ZipEntry ("contents"));
        zipOut.write (buf.getBytes ());
        zipOut.closeEntry ();
        zipOut.close ();
        fOut.close ();
    } catch (Exception e) {
        e.printStackTrace ();
    }
}
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:
public static File fileToZipFile (File file) throws Exception {
    ZipOutputStream out = null;
    FileInputStream in = null;
    File retFile = changeFileNameSuffix (file, "zip");
    try {
        byte [] buf = new byte [1024];
        out = new ZipOutputStream (new FileOutputStream (retFile));
        in = new FileInputStream (file);
        out.putNextEntry (new ZipEntry (file.getName ()));
        int len;
        while ((len = in.read (buf)) > 0) {
            out.write (buf, 0, len);
        }
        out.closeEntry ();
    } finally {
        if (in != null) {
            in.close ();
        }
        if (out != null) {
            out.close ();
        }
    }
    file.delete ();
    return retFile;
}
Functionality: Copy File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public void includeCss (Group group, Writer out, PageContext pageContext) throws IOException {
    ByteArrayOutputStream outtmp = new ByteArrayOutputStream ();
    if (AbstractGroupBuilder.getInstance ().buildGroupJsIfNeeded (group, outtmp, pageContext.getServletContext ())) {
        FileOutputStream fileStream = null;
        try {
            fileStream = new FileOutputStream (new File (RetentionHelper.buildFullRetentionFilePath (group, ".css")));
            IOUtils.copy (new ByteArrayInputStream (outtmp.toByteArray ()), fileStream);
        } finally {
            if (fileStream != null) fileStream.close ();

        }
    }
}

Function 2:
private void copyArtifact (String name) throws IOException {
    IOUtils.copyFromClassPath (name, model.getOutputFolder () + name);
}
Functionality: Copy File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public void writeTo (OutputStream out) throws IOException {
    IOUtils.copy (tempFile.getInputStream (), out);
}

Function 2:
protected void copy (File src, File dest) throws IOException {
    if (src.isDirectory () && dest.isFile ()) throw new IOException ("Cannot copy a directory to a file");

    if (src.isDirectory ()) {
        File newDir = new File (dest, src.getName ());
        if (! newDir.mkdirs ()) throw new IOException ("Cannot create a new Directory");

        File [] entries = src.listFiles ();
        for (int i = 0;
        i < entries.length; ++ i) copy (entries [i], newDir);

        return;
    }
    if (dest.isDirectory ()) {
        File newFile = new File (dest, src.getName ());
        newFile.createNewFile ();
        copy (src, newFile);
        return;
    }
    try {
        if (src.length () == 0) {
            dest.createNewFile ();
            return;
        }
        FileChannel fc = new FileInputStream (src).getChannel ();
        FileChannel dstChannel = new FileOutputStream (dest).getChannel ();
        long transfered = 0;
        long totalLength = src.length ();
        while (transfered < totalLength) {
            long num = fc.transferTo (transfered, totalLength - transfered, dstChannel);
            if (num == 0) throw new IOException ("Error while copying");

            transfered += num;
        }
        dstChannel.close ();
        fc.close ();
    } catch (IOException e) {
        if (os.equals ("Unix")) {
            _logger.fine ("Trying to use cp to copy file...");
            File cp = new File ("/usr/bin/cp");
            if (! cp.exists ()) cp = new File ("/bin/cp");

            if (! cp.exists ()) cp = new File ("/usr/local/bin/cp");

            if (! cp.exists ()) cp = new File ("/sbin/cp");

            if (! cp.exists ()) cp = new File ("/usr/sbin/cp");

            if (! cp.exists ()) cp = new File ("/usr/local/sbin/cp");

            if (cp.exists ()) {
                Process cpProcess = Runtime.getRuntime ().exec (cp.getAbsolutePath () + " '" + src.getAbsolutePath () + "' '" + dest.getAbsolutePath () + "'");
                int errCode;
                try {
                    errCode = cpProcess.waitFor ();
                } catch (java.lang.InterruptedException ie) {
                    throw e;
                }
                return;
            }
        }
        throw e;
    }
}
Functionality: Copy File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public static void copyFile (final File sourceFile, final File destFile) throws IOException {
    if (destFile.getParentFile () != null && ! destFile.getParentFile ().mkdirs ()) {
        LOG.error ("GeneralHelper.copyFile(): Cannot create parent directories from " + destFile);
    }
    FileInputStream fIn = null;
    FileOutputStream fOut = null;
    FileChannel source = null;
    FileChannel destination = null;
    try {
        fIn = new FileInputStream (sourceFile);
        source = fIn.getChannel ();
        fOut = new FileOutputStream (destFile);
        destination = fOut.getChannel ();
        long transfered = 0;
        final long bytes = source.size ();
        while (transfered < bytes) {
            transfered += destination.transferFrom (source, 0, source.size ());
            destination.position (transfered);
        }
    } finally {
        if (source != null) {
            source.close ();
        } else if (fIn != null) {
            fIn.close ();
        }

        if (destination != null) {
            destination.close ();
        } else if (fOut != null) {
            fOut.close ();
        }

    }
}

Function 2:
protected void copy (URL url, File file) throws IOException {
    InputStream in = null;
    FileOutputStream out = null;
    try {
        in = url.openStream ();
        out = new FileOutputStream (file);
        IOUtils.copy (in, out);
    } finally {
        if (out != null) {
            out.close ();
        }
        if (in != null) {
            in.close ();
        }
    }
}
Functionality: CRC32 File Checksum
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
public long checksumFile (String name) throws IOException {
    byte [] buffer = new byte [4000];
    InputStream in = new FileInputStream (new File (dir, name));
    Checksum cksum = new CRC32 ();
    while (true) {
        int n = in.read (buffer);
        if (n < 0) break;

        cksum.update (buffer, 0, n);
    }
    return cksum.getValue ();
}

Function 2:
private boolean isNotCorrupted (String fileName) throws Exception {
    FileReader xmlFile;
    FileReader checksumFile;
    CRC32 check = new CRC32 ();
    int c;
    String compareCheck = "";
    check.reset ();
    try {
        xmlFile = new FileReader (fileName);
        while ((c = xmlFile.read ()) != - 1) {
            check.update ((char) c);
        }
    } catch (FileNotFoundException e) {
        System.out.println ("[ERROR] was not possible to open xml file: " + fileName);
        throw e;
    } catch (IOException e) {
        System.out.println ("[ERROR] was not possible to read xml file: " + fileName);
        throw e;
    }
    try {
        checksumFile = new FileReader (fileName.substring (0, fileName.length () - 4) + ".crc32");
        while ((c = checksumFile.read ()) != - 1) {
            compareCheck += (char) c;
        }
    } catch (FileNotFoundException e) {
        System.out.println ("[ERROR] was not possible to open checksum file: " + fileName.substring (0, fileName.length () - 4) + ".crc32");
        throw e;
    } catch (IOException e) {
        System.out.println ("[ERROR] was not possible to read checksum file: " + fileName.substring (0, fileName.length () - 4) + ".crc32");
        throw e;
    }
    return compareCheck.trim ().equalsIgnoreCase (String.valueOf (check.getValue ()));
}
Functionality: Zip Files
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
private void backupFile (ZipOutputStream out, String base, String fn) throws IOException {
    String f = FileUtils.getAbsolutePath (fn);
    base = FileUtils.getAbsolutePath (base);
    if (! f.startsWith (base)) {
        Message.throwInternalError (f + " does not start with " + base);
    }
    f = f.substring (base.length ());
    f = correctFileName (f);
    out.putNextEntry (new ZipEntry (f));
    InputStream in = FileUtils.openFileInputStream (fn);
    IOUtils.copyAndCloseInput (in, out);
    out.closeEntry ();
}

Function 2:
public static void addToZip (ZipOutputStream zos, String filename, String nameInArchive) throws Exception {
    File file = new File (filename);
    if (! file.exists ()) {
        System.err.println ("File does not exist, skipping: " + filename);
        return;
    }
    BufferedInputStream bis = new BufferedInputStream (new FileInputStream (file));
    int bytesRead;
    byte [] buffer = new byte [1024];
    CRC32 crc = new CRC32 ();
    crc.reset ();
    while ((bytesRead = bis.read (buffer)) != - 1) {
        crc.update (buffer, 0, bytesRead);
    }
    bis.close ();
    bis = new BufferedInputStream (new FileInputStream (file));
    String nameInArchiveFixed = nameInArchive.replace ("\\", "/");
    ZipEntry entry = new ZipEntry (nameInArchiveFixed);
    entry.setMethod (ZipEntry.STORED);
    entry.setCompressedSize (file.length ());
    entry.setSize (file.length ());
    entry.setCrc (crc.getValue ());
    zos.putNextEntry (entry);
    while ((bytesRead = bis.read (buffer)) != - 1) {
        zos.write (buffer, 0, bytesRead);
    }
    bis.close ();
}
Functionality: Secure Hash
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
private String hash (String clearPassword) {
    if (salt == 0) return null;

    MessageDigest md = null;
    try {
        md = MessageDigest.getInstance ("SHA1");
    } catch (NoSuchAlgorithmException e) {
        throw new AssertionError ("Can't find the SHA1 algorithm in the java.security package");
    }
    String saltString = String.valueOf (salt);
    md.update (saltString.getBytes ());
    md.update (clearPassword.getBytes ());
    byte [] digestBytes = md.digest ();
    StringBuffer digestSB = new StringBuffer ();
    for (int i = 0;
    i < digestBytes.length; i ++) {
        int lowNibble = digestBytes [i] & 0x0f;
        int highNibble = (digestBytes [i]>> 4) & 0x0f;
        digestSB.append (Integer.toHexString (highNibble));
        digestSB.append (Integer.toHexString (lowNibble));
    }
    String digestStr = digestSB.toString ();
    return digestStr;
}

Function 2:
public static String do_checksum (String data) throws NoSuchAlgorithmException {
    MessageDigest md5 = MessageDigest.getInstance ("MD5");
    StringBuffer strbuf = new StringBuffer ();
    md5.update (data.getBytes (), 0, data.length ());
    byte [] digest = md5.digest ();
    for (int i = 0;
    i < digest.length; i ++) {
        strbuf.append (toHexString (digest [i]));
    }
    return strbuf.toString ();
}
Functionality: Copy File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public static void copyFile (File in, File out) throws IOException {
    FileChannel inChannel = new FileInputStream (in).getChannel ();
    FileChannel outChannel = new FileOutputStream (out).getChannel ();
    try {
        inChannel.transferTo (0, inChannel.size (), outChannel);
    } finally {
        if (inChannel != null) inChannel.close ();

        if (outChannel != null) outChannel.close ();

    }
}

Function 2:
public FileReader (String filePath, Configuration aConfiguration) throws IOException {
    file = new File (URLDecoder.decode (filePath, "UTF-8")).getCanonicalFile ();
    readerConf = aConfiguration;
    if (file.isDirectory ()) {
        File indexFile = new File (file, "index.php");
        File indexFile_1 = new File (file, "index.html");
        if (indexFile.exists () && ! indexFile.isDirectory ()) {
            file = indexFile;
        } else if (indexFile_1.exists () && ! indexFile_1.isDirectory ()) {
            file = indexFile_1;
        } else {
            if (! readerConf.getOption ("showFolders").equals ("Yes")) {
                makeErrorPage (503, "Permision denied");
            } else {
                FileOutputStream out = new FileOutputStream (readerConf.getOption ("wwwPath") + "/temp/temp.php");
                File [] files = file.listFiles ();
                makeHeader (200, - 1, new Date (System.currentTimeMillis ()).toString (), "text/html");
                String title = "Index of " + file;
                out.write (("<html><head><title>" + title + "</title></head><body><h3>Index of " + file + "</h3><p>\n").getBytes ());
                for (int i = 0;
                i < files.length; i ++) {
                    file = files [i];
                    String filename = file.getName ();
                    String description = "";
                    if (file.isDirectory ()) {
                        description = "&lt;DIR&gt;";
                    }
                    out.write (("<a href=\"" + file.getPath ().substring (readerConf.getOption ("wwwPath").length ()) + "\">" + filename + "</a> " + description + "<br>\n").getBytes ());
                }
                out.write (("</p><hr><p>yawwwserwer</p></body><html>").getBytes ());
                file = new File (URLDecoder.decode (readerConf.getOption ("wwwPath") + "/temp/temp.php", "UTF-8")).getCanonicalFile ();
            }
        }

    } else if (! file.exists ()) {
        makeErrorPage (404, "File Not Found.");
    } else if (getExtension () == ".exe" || getExtension ().contains (".py")) {
        FileOutputStream out = new FileOutputStream (readerConf.getOption ("wwwPath") + "/temp/temp.php");
        out.write ((runCommand (filePath)).getBytes ());
        file = new File (URLDecoder.decode (readerConf.getOption ("wwwPath") + "/temp/temp.php", "UTF-8")).getCanonicalFile ();
    } else {
        System.out.println (getExtension ());
        makeHeader (200, file.length (), new Date (file.lastModified ()).toString (), TYPES.get (getExtension ()).toString ());
    }

    System.out.println (file);
}
Functionality: Zip Files
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
private static PrintWriter getOut (int first, int last, String dir, String lang) throws IOException {
    if (dir == null) return null;

    File file = new File (dir, lang + ".wikipedia.zip");
    if (! file.exists ()) file.createNewFile ();

    if (! file.canWrite ()) throw new IllegalArgumentException ("can't write " + file);

    log (true, "Writing Wikipedia events into " + file.getAbsolutePath ());
    System.setProperty ("line.separator", "\n");
    ZipOutputStream out = new ZipOutputStream (new FileOutputStream (file));
    out.putNextEntry (new ZipEntry (lang + ".wikipedia"));
    return new PrintWriter (new OutputStreamWriter (out, UTF8));
}

Function 2:
protected void addFile (String path, InputStream source, JarOutputStream jos) throws IOException {
    jos.putNextEntry (new ZipEntry (path));
    try {
        int count;
        while ((count = source.read (buffer)) > 0) {
            jos.write (buffer, 0, count);
        }
    } finally {
        jos.closeEntry ();
    }
}