primakov/ML4SE2023_Group4_Dataset.csv huggingface dataset:
Functionality: Copy File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
private File extractResource (String resourceName, File destDir) {
    File file = new File (destDir, resourceName);
    InputStream in = getClass ().getResourceAsStream (resourceName);
    try {
        FileOutputStream out = FileUtils.openOutputStream (file);
        try {
            IOUtils.copy (in, out);
        } finally {
            if (out != null) {
                out.close ();
            }
        }
    } finally {
        if (in != null) {
            in.close ();
        }
    }
    return file;
}

Function 2:
private void outputSignedOpenDocument (byte [] signatureData) throws IOException {
    LOG.debug ("output signed open document");
    OutputStream signedOdfOutputStream = getSignedOpenDocumentOutputStream ();
    if (null == signedOdfOutputStream) {
        throw new NullPointerException ("signedOpenDocumentOutputStream is null");
    }
    ZipOutputStream zipOutputStream = new ZipOutputStream (signedOdfOutputStream);
    ZipInputStream zipInputStream = new ZipInputStream (this.getOpenDocumentURL ().openStream ());
    ZipEntry zipEntry;
    while (null != (zipEntry = zipInputStream.getNextEntry ())) {
        if (! zipEntry.getName ().equals (ODFUtil.SIGNATURE_FILE)) {
            zipOutputStream.putNextEntry (zipEntry);
            IOUtils.copy (zipInputStream, zipOutputStream);
        }
    }
    zipInputStream.close ();
    zipEntry = new ZipEntry (ODFUtil.SIGNATURE_FILE);
    zipOutputStream.putNextEntry (zipEntry);
    IOUtils.write (signatureData, zipOutputStream);
    zipOutputStream.close ();
}
Functionality: Zip Files
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
private void nextZipEntry (String url, int level) throws IOException {
    if (! url.startsWith ("META-INF/") && ! url.startsWith ("OEBPS/")) url = "OEBPS/" + url;

    ZipEntry ze = new ZipEntry (url);
    ze.setMethod (ZipEntry.DEFLATED);
    tmpzos.putNextEntry (ze);
}

Function 2:
public void zipFile (FileEntry fileEntry) {
    String zipfilename = fileEntry.getPath ();
    if (fileEntry.isDir ()) {
        zipfilename += ".zip";
    } else {
        zipfilename = zipfilename.substring (0, zipfilename.length () - 4) + ".zip";
    }
    try {
        ZipOutputStream out = new ZipOutputStream (new BufferedOutputStream (new FileOutputStream (zipfilename)));
        out.setLevel (Deflater.DEFAULT_COMPRESSION);
        byte [] data = new byte [1000];
        BufferedInputStream in = new BufferedInputStream (new FileInputStream (fileEntry.getPath ()));
        int count;
        out.putNextEntry (new ZipEntry (fileEntry.getName ()));
        while ((count = in.read (data, 0, 1000)) != - 1) {
            out.write (data, 0, count);
        }
        in.close ();
        out.flush ();
        out.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 void archive (String [] fileNames, String archiveName) {
    byte [] buffer = new byte [1024];
    try {
        ZipOutputStream zipOut = new ZipOutputStream (new FileOutputStream (archiveName));
        for (int i = 0;
        i < fileNames.length; i ++) {
            FileInputStream fileIn = new FileInputStream (fileNames [i]);
            zipOut.putNextEntry (new ZipEntry (fileNames [i].replace ('\\', '/')));
            int length;
            while ((length = fileIn.read (buffer)) > 0) {
                zipOut.write (buffer, 0, length);
            }
            zipOut.closeEntry ();
            fileIn.close ();
        }
        zipOut.close ();
    } catch (IOException e) {
    }
}
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:
void copyResourceToZip (String entryName, InputStream is, ZipOutputStream zos) throws Exception {
    ZipEntry entry = new ZipEntry (entryName);
    zos.putNextEntry (entry);
    BufferedInputStream bis = new BufferedInputStream (is);
    int avail = bis.available ();
    byte [] buffer = new byte [avail];
    bis.read (buffer, 0, avail);
    zos.write (buffer, 0, avail);
    zos.closeEntry ();
}
Functionality: Zip Files
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
private void saveZipEntries (Object [] entries, ZipOutputStream zos) throws IOException {
    for (int i = 0;
    i < entries.length;) {
        String entryName = (String) entries [i ++];
        Object entry = entries [i ++];
        zos.putNextEntry (new ZipEntry (entryName));
        if (entry instanceof String) {
            this.saveContents ((String) entry, zos);
        } else {
            this.saveZipEntries ((Object []) entry, zos);
        }
    }
}

Function 2:
private List < ? extends Attachment > createZipAttachment (List < FileSystemItem > nodes, boolean withFolders) throws IOException {
    File tmp = File.createTempFile ("securus", null);
    ZipOutputStream zip = new ZipOutputStream (new FileOutputStream (tmp));
    try {
        for (FileSystemItem node : nodes) {
            String path;
            if (withFolders) {
                path = node.getFile ();
            } else {
                path = node.getFile ();
            }
            zip.putNextEntry (new ZipEntry (path));
            InputStream in = new BufferedInputStream (node.getContent ());
            int b;
            while ((b = in.read ()) != - 1) {
                zip.write (b);
            }
            zip.closeEntry ();
        }
    } finally {
        zip.close ();
    }
    return Arrays.asList (new ZipAttachment (tmp));
}
Functionality: Resize Array
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public static Object [] addObjectToArray (Object [] array, Object obj) {
    Class compType = Object.class;
    if (array != null) {
        compType = array.getClass ().getComponentType ();
    } else if (obj != null) {
        compType = obj.getClass ();
    }

    int newArrLength = (array != null ? array.length + 1 : 1);
    Object [] newArr = (Object []) Array.newInstance (compType, newArrLength);
    if (array != null) {
        System.arraycopy (array, 0, newArr, 0, array.length);
    }
    newArr [newArr.length - 1] = obj;
    return newArr;
}

Function 2:
public static Object resizeArrayIfDifferent (Object source, int newsize) {
    int oldsize = Array.getLength (source);
    if (oldsize == newsize) {
        return source;
    }
    Object newarray = Array.newInstance (source.getClass ().getComponentType (), newsize);
    if (oldsize < newsize) {
        newsize = oldsize;
    }
    System.arraycopy (source, 0, newarray, 0, newsize);
    return newarray;
}
Functionality: Secure Hash
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public static byte [] encode (String origin, String algorithm) throws NoSuchAlgorithmException {
    String resultStr = null;
    resultStr = new String (origin);
    MessageDigest md = MessageDigest.getInstance (algorithm);
    md.update (resultStr.getBytes ());
    return md.digest ();
}

Function 2:
private String md5 (String uri) throws ConnoteaRuntimeException {
    try {
        MessageDigest messageDigest = MessageDigest.getInstance ("MD5");
        messageDigest.update (uri.getBytes ());
        byte [] bytes = messageDigest.digest ();
        StringBuffer stringBuffer = new StringBuffer ();
        for (byte b : bytes) {
            String hex = Integer.toHexString (0xff & b);
            if (hex.length () == 1) {
                stringBuffer.append ('0');
            }
            stringBuffer.append (hex);
        }
        return stringBuffer.toString ();
    } catch (NoSuchAlgorithmException e) {
        throw new ConnoteaRuntimeException (e);
    }
}
Functionality: Zip Files
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
private void zipStream (InputStream inStream, String streamName, File zipFile) throws IOException {
    if (inStream == null) {
        log.warn ("No stream to zip.");
    } else {
        try {
            FileOutputStream dest = new FileOutputStream (zipFile);
            ZipOutputStream out = new ZipOutputStream (new BufferedOutputStream (dest));
            ZipEntry entry = new ZipEntry (streamName);
            out.putNextEntry (entry);
            copyInputStream (inStream, out);
            out.close ();
            dest.close ();
            inStream.close ();
        } catch (IOException e) {
            log.error ("IOException while zipping stream");
            throw e;
        }
    }
}

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 ();
    }
}