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

Function 1:
public File convert (URI uri) throws DjatokaException {
    processing.add (uri.toString ());
    File urlLocal = null;
    try {
        logger.info ("processingRemoteURI: " + uri.toURL ());
        boolean isJp2 = false;
        InputStream src = IOUtils.getInputStream (uri.toURL ());
        String ext = uri.toURL ().toString ().substring (uri.toURL ().toString ().lastIndexOf (".") + 1).toLowerCase ();
        if (ext.equals (FORMAT_ID_TIF) || ext.equals (FORMAT_ID_TIFF)) {
            urlLocal = File.createTempFile ("convert" + uri.hashCode (), "." + FORMAT_ID_TIF);
        } else if (formatMap.containsKey (ext) && (formatMap.get (ext).equals (FORMAT_MIMEYPE_JP2) || formatMap.get (ext).equals (FORMAT_MIMEYPE_JPX))) {
            urlLocal = File.createTempFile ("cache" + uri.hashCode (), "." + ext);
            isJp2 = true;
        } else {
            if (src.markSupported ()) src.mark (15);

            if (ImageProcessingUtils.checkIfJp2 (src)) urlLocal = File.createTempFile ("cache" + uri.hashCode (), "." + FORMAT_ID_JP2);

            if (src.markSupported ()) src.reset ();
            else {
                src.close ();
                src = IOUtils.getInputStream (uri.toURL ());
            }
        }

        if (urlLocal == null) {
            urlLocal = File.createTempFile ("convert" + uri.hashCode (), ".img");
        }
        urlLocal.deleteOnExit ();
        FileOutputStream dest = new FileOutputStream (urlLocal);
        IOUtils.copyStream (src, dest);
        if (! isJp2) urlLocal = processImage (urlLocal, uri);

        src.close ();
        dest.close ();
        return urlLocal;
    } catch (Exception e) {
        urlLocal.delete ();
        throw new DjatokaException (e);
    } finally {
        if (processing.contains (uri.toString ())) processing.remove (uri.toString ());

    }
}

Function 2:
private void publishMap (LWMap map) throws IOException {
    File savedMap = PublishUtil.saveMap (map);
    InputStream istream = new BufferedInputStream (new FileInputStream (savedMap));
    OutputStream ostream = new BufferedOutputStream (new FileOutputStream (ActionUtil.selectFile ("ConceptMap", "vue")));
    int fileLength = (int) savedMap.length ();
    byte bytes [] = new byte [fileLength];
    while (istream.read (bytes, 0, fileLength) != - 1) ostream.write (bytes, 0, fileLength);

    istream.close ();
    ostream.close ();
}
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:
public void zipDir (File zipDir, ZipOutputStream zos, File root) {
    try {
        String [] dirList = zipDir.list ();
        byte [] readBuffer = new byte [1024];
        int bytesIn = 0;
        for (int i = 0;
        i < dirList.length; i ++) {
            File f = new File (zipDir, dirList [i]);
            if (f.isDirectory ()) {
                zipDir (f, zos, root);
                continue;
            }
            FileInputStream fis = new FileInputStream (f);
            ZipEntry anEntry = new ZipEntry (f.getPath ().replace (root + File.separator, ""));
            zos.putNextEntry (anEntry);
            while ((bytesIn = fis.read (readBuffer)) != - 1) {
                zos.write (readBuffer, 0, bytesIn);
            }
            fis.close ();
        }
    } catch (Exception e) {
        e.printStackTrace ();
    }
}
Functionality: CRC32 File Checksum
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
protected int writeEntry (ZipOutputStream jar, Filelike entry, ULog log) throws IOException, ValidationException {
    String archiveName = getNameStrategy ().getArchiveName (log, entry);
    if (archiveName != null && archiveName.length () > 0) {
        ZipEntry ze = new ZipEntry (archiveName);
        log.fine ("writing entry {0} ({1} bytes)", new Quote (ze.getName ()), SIZE_FORMAT.format (entry.getSize ()));
        byte [] bytes = entry.readWhole ();
        if (! compressed) {
            ze.setMethod (ZipEntry.STORED);
            ze.setSize (entry.getSize ());
            ze.setCompressedSize (entry.getSize ());
            CRC32 crc = new CRC32 ();
            crc.update (bytes);
            ze.setCrc (crc.getValue ());
        }
        jar.putNextEntry (ze);
        jar.write (bytes);
        jar.closeEntry ();
        return bytes.length;
    } else {
        return 0;
    }
}

Function 2:
private byte [] getgAMABytes () {
    byte [] array = new byte [16];
    ByteBuffer buffer = ByteBuffer.wrap (array);
    buffer.putInt (4);
    buffer.put (getISO8859_1Bytes (CHUNK_TYPE_gAMA));
    buffer.putInt (gamma);
    CRC32 crc = new CRC32 ();
    crc.update (array, 4, 8);
    buffer.putInt ((int) crc.getValue ());
    return array;
}
Functionality: Download From Web
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public PhoneSetImpl (URL url) throws IOException {
    BufferedReader reader;
    String line;
    phonesetMap = new HashMap ();
    reader = new BufferedReader (new InputStreamReader (url.openStream ()));
    line = reader.readLine ();
    lineCount ++;
    while (line != null) {
        if (! line.startsWith ("***")) {
            parseAndAdd (line);
        }
        line = reader.readLine ();
    }
    reader.close ();
}

Function 2:
public static List importDate (Report report, TradingDate date) throws ImportExportException {
    List quotes = new ArrayList ();
    String urlString = constructURL (date);
    EODQuoteFilter filter = new MetaStockQuoteFilter ();
    PreferencesManager.ProxyPreferences proxyPreferences = PreferencesManager.getProxySettings ();
    try {
        URL url = new URL (urlString);
        InputStreamReader input = new InputStreamReader (url.openStream ());
        BufferedReader bufferedInput = new BufferedReader (input);
        String line = null;
        do {
            line = bufferedInput.readLine ();
            if (line != null) {
                try {
                    EODQuote quote = filter.toEODQuote (line);
                    quotes.add (quote);
                    verify (report, quote);
                } catch (QuoteFormatException e) {
                    report.addError (Locale.getString ("DFLOAT_DISPLAY_URL") + ":" + date + ":" + Locale.getString ("ERROR") + ": " + e.getMessage ());
                }
            }
        } while (line != null);
        bufferedInput.close ();
    } catch (BindException e) {
        throw new ImportExportException (Locale.getString ("UNABLE_TO_CONNECT_ERROR", e.getMessage ()));
    } catch (ConnectException e) {
        throw new ImportExportException (Locale.getString ("UNABLE_TO_CONNECT_ERROR", e.getMessage ()));
    } catch (UnknownHostException e) {
        throw new ImportExportException (Locale.getString ("UNKNOWN_HOST_ERROR", e.getMessage ()));
    } catch (NoRouteToHostException e) {
        throw new ImportExportException (Locale.getString ("DESTINATION_UNREACHABLE_ERROR", e.getMessage ()));
    } catch (MalformedURLException e) {
        throw new ImportExportException (Locale.getString ("INVALID_PROXY_ERROR", proxyPreferences.host, proxyPreferences.port));
    } catch (FileNotFoundException e) {
        report.addError (Locale.getString ("FLOAT_DISPLAY_URL") + ":" + date + ":" + Locale.getString ("ERROR") + ": " + Locale.getString ("NO_QUOTES_FOUND"));
    } catch (IOException e) {
        throw new ImportExportException (Locale.getString ("ERROR_DOWNLOADING_QUOTES"));
    }
    return quotes;
}
Functionality: Zip Files
Clone type: Type-3 (WT3/4)
Is clone: TRUE

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 addAllUploadedFiles (Environment en, ZipOutputStream zipout, int progressStart, int progressLength) throws IOException, FileNotFoundException {
    File uploadPath = en.uploadPath (virtualWiki, "");
    String [] files = uploadPath.list ();
    int bytesRead = 0;
    byte byteArray [] = new byte [4096];
    for (int i = 0;
    i < files.length; i ++) {
        progress = Math.min (progressStart + (int) ((double) i * (double) progressLength / (double) files.length), 99);
        logger.debug ("Adding uploaded file " + files [i]);
        ZipEntry entry = new ZipEntry (safename (files [i]));
        try {
            FileInputStream in = new FileInputStream (en.uploadPath (virtualWiki, files [i]));
            zipout.putNextEntry (entry);
            while (in.available () > 0) {
                bytesRead = in.read (byteArray, 0, Math.min (4096, in.available ()));
                zipout.write (byteArray, 0, bytesRead);
            }
            zipout.closeEntry ();
            zipout.flush ();
        } catch (FileNotFoundException e) {
            logger.warn ("Could not open file!", e);
        } catch (IOException e) {
            logger.warn ("IOException!", e);
            try {
                zipout.closeEntry ();
                zipout.flush ();
            } catch (IOException e1) {
            }
        }
    }
}
Functionality: Zip Files
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
public void addMetadata (Request request, Entry entry, ZipOutputStream zos, Metadata metadata, Element node) throws Exception {
    MetadataType type = getType (metadata.getType ());
    if (type == null) {
        throw new IllegalStateException ("Unknown metadata type:" + metadata.getType ());
    }
    Document doc = node.getOwnerDocument ();
    Element metadataNode = XmlUtil.create (doc, TAG_METADATA, node, new String [] {ATTR_TYPE, metadata.getType ()});
    for (MetadataElement element : type.getChildren ()) {
        int index = element.getIndex ();
        String value = metadata.getAttr (index);
        if (value == null) {
            continue;
        }
        Element attrNode = XmlUtil.create (doc, Metadata.TAG_ATTR, metadataNode, new String [] {Metadata.ATTR_INDEX, "" + index});
        attrNode.appendChild (XmlUtil.makeCDataNode (doc, value, true));
        if (zos != null && element.getDataType ().equals (element.DATATYPE_FILE)) {
            File f = type.getFile (entry, metadata, element);
            if (f == null || ! f.exists ()) continue;

            String fileName = repository.getGUID ();
            attrNode.setAttribute ("fileid", fileName);
            zos.putNextEntry (new ZipEntry (fileName));
            InputStream fis = getStorageManager ().getFileInputStream (f.toString ());
            try {
                IOUtil.writeTo (fis, zos);
            } finally {
                IOUtil.close (fis);
                zos.closeEntry ();
            }
        }
    }
}

Function 2:
private void createTextFile (ZipOutputStream zipOut, String str, String basename, boolean utf8, boolean utf16) throws IOException {
    byte [] bytes = null;
    if (utf8) {
        bytes = str.getBytes ("utf-8");
        zipOut.putNextEntry (new ZipEntry (basename + ".txt"));
        zipOut.write (bytes, 0, bytes.length);
    }
    if (utf16) {
        bytes = str.getBytes ("utf-16");
        zipOut.putNextEntry (new ZipEntry (basename + ".utf-16.txt"));
        zipOut.write (bytes, 0, bytes.length);
    }
}
Functionality: Copy File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public static void copy (String from_name, String to_name, boolean overwriteOk) throws IOException {
    File from_file = new File (from_name);
    File to_file = new File (to_name);
    if (! from_file.exists ()) abort ("FileCopy: no such source file: " + from_name);

    if (! from_file.isFile ()) abort ("FileCopy: can't copy directory: " + from_name);

    if (! from_file.canRead ()) abort ("FileCopy: source file is unreadable: " + from_name);

    if (to_file.isDirectory ()) to_file = new File (to_file, from_file.getName ());

    if (to_file.exists ()) {
        if (! to_file.canWrite ()) abort ("FileCopy: destination file is unwriteable: " + to_name);

        if (! overwriteOk) {
            System.out.print ("Overwrite existing file " + to_name + "? (Y/N): ");
            System.out.flush ();
            BufferedReader in = new BufferedReader (new InputStreamReader (System.in));
            String response = in.readLine ();
            if (! response.equals ("Y") && ! response.equals ("y")) abort ("FileCopy: existing file was not overwritten.");

        }
    } else {
        String parent = to_file.getParent ();
        if (parent == null) parent = System.getProperty ("user.dir");

        File dir = new File (parent);
        if (! dir.exists ()) abort ("FileCopy: destination directory doesn't exist: " + parent);

        if (dir.isFile ()) abort ("FileCopy: destination is not a directory: " + parent);

        if (! dir.canWrite ()) abort ("FileCopy: destination directory is unwriteable: " + parent);

    }
    FileInputStream from = null;
    FileOutputStream to = null;
    try {
        from = new FileInputStream (from_file);
        to = new FileOutputStream (to_file);
        byte [] buffer = new byte [4096];
        int bytes_read;
        while ((bytes_read = from.read (buffer)) != - 1) to.write (buffer, 0, bytes_read);

    } finally {
        if (from != null) try {
            from.close ();
        } catch (IOException e) {
        }

        if (to != null) try {
            to.close ();
        } catch (IOException e) {
        }

    }
}

Function 2:
private static void unzipEntry (ZipFile zipfile, ZipEntry entry, File outputDir) throws IOException {
    if (entry.isDirectory ()) {
        createDir (new File (outputDir, entry.getName ()));
        return;
    }
    File outputFile = new File (outputDir, entry.getName ());
    if (! outputFile.getParentFile ().exists ()) {
        createDir (outputFile.getParentFile ());
    }
    BufferedInputStream inputStream = new BufferedInputStream (zipfile.getInputStream (entry));
    BufferedOutputStream outputStream = new BufferedOutputStream (new FileOutputStream (outputFile));
    try {
        IOUtils.copy (inputStream, outputStream);
    } finally {
        outputStream.close ();
        inputStream.close ();
    }
}
Functionality: Zip Files
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
private static void addToZip (ZipOutputStream zout, String file, String code, String currentDirectory) {
    try {
        ZipEntry entry = new ZipEntry (currentDirectory + file);
        zout.putNextEntry (entry);
        zout.write (code.getBytes (), 0, code.length ());
        zout.closeEntry ();
    } catch (IOException e) {
        e.printStackTrace ();
    }
}

Function 2:
public static void makeArchiveFromFolder (@NotNull
File folder, File toZipFile, int method) throws IOException, IllegalArgumentException {
    if (folder == null) {
        throw new IllegalArgumentException ("the folder can't be null!");
    }
    if (! folder.exists ()) {
        throw new IllegalArgumentException ("the folder = " + folder.getAbsolutePath () + " don't exist!");
    }
    if (! folder.isDirectory ()) {
        throw new IllegalArgumentException ("the folder = " + folder.getAbsolutePath () + " is a file and not a folder!");
    }
    BufferedInputStream origin = null;
    FileOutputStream dest = new FileOutputStream (toZipFile);
    ZipOutputStream out = new ZipOutputStream (new BufferedOutputStream (dest));
    out.setMethod (method);
    byte data [] = new byte [BUFFER];
    File files [] = folder.listFiles ();
    for (int i = 0;
    i < files.length; i ++) {
        FileInputStream fi = new FileInputStream (files [i]);
        origin = new BufferedInputStream (fi, BUFFER);
        ZipEntry entry = new ZipEntry (files [i].getName ());
        out.putNextEntry (entry);
        int count;
        while ((count = origin.read (data, 0, BUFFER)) != - 1) {
            out.write (data, 0, count);
        }
        origin.close ();
    }
    out.close ();
}
Functionality: Copy File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
@Override
protected void copy (Reader reader, OutputStream outputs) throws IOException {
    if (outputs == null) {
        throw new NullPointerException ();
    }
    if (reader == null) {
        throw new NullPointerException ();
    }
    ZipOutputStream zipoutputs = null;
    try {
        zipoutputs = new ZipOutputStream (outputs);
        zipoutputs.putNextEntry (new ZipEntry ("default"));
        IOUtils.copy (reader, zipoutputs);
    } catch (IOException e) {
        e.printStackTrace ();
        throw e;
    } finally {
        if (zipoutputs != null) {
            zipoutputs.close ();
        }
        if (reader != null) {
            reader.close ();
        }
    }
}

Function 2:
private void deleteProject (String uid, String home, HttpServletRequest request, HttpServletResponse response) throws Exception {
    String project = request.getParameter ("project");
    String line;
    response.setContentType ("text/html");
    PrintWriter out = response.getWriter ();
    htmlHeader (out, "Project Status", "");
    try {
        synchronized (Class.forName ("com.sun.gep.SunTCP")) {
            Vector list = new Vector ();
            String directory = home;
            Runtime.getRuntime ().exec ("/usr/bin/rm -rf " + directory + project);
            FilePermission perm = new FilePermission (directory + SUNTCP_LIST, "read,write,execute");
            File listfile = new File (directory + SUNTCP_LIST);
            BufferedReader read = new BufferedReader (new FileReader (listfile));
            while ((line = read.readLine ()) != null) {
                if (! ((new StringTokenizer (line, "\t")).nextToken ().equals (project))) {
                    list.addElement (line);
                }
            }
            read.close ();
            if (list.size () > 0) {
                PrintWriter write = new PrintWriter (new BufferedWriter (new FileWriter (listfile)));
                for (int i = 0;
                i < list.size (); i ++) {
                    write.println ((String) list.get (i));
                }
                write.close ();
            } else {
                listfile.delete ();
            }
            out.println ("The project was successfully deleted.");
        }
    } catch (Exception e) {
        out.println ("Error accessing this project.");
    }
    out.println ("<center><form><input type=button value=Continue onClick=\"opener.location.reload(); window.close()\"></form></center>");
    htmlFooter (out);
}
Functionality: CRC32 File Checksum
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
public static final long crc32 (byte [] data) {
    CRC32 crc32 = new CRC32 ();
    crc32.update (data);
    return crc32.getValue ();
}

Function 2:
protected int writeEntry (ZipOutputStream jar, Filelike entry, ULog log) throws IOException, ValidationException {
    String archiveName = getNameStrategy ().getArchiveName (log, entry);
    if (archiveName != null && archiveName.length () > 0) {
        ZipEntry ze = new ZipEntry (archiveName);
        log.fine ("writing entry {0} ({1} bytes)", new Quote (ze.getName ()), SIZE_FORMAT.format (entry.getSize ()));
        byte [] bytes = entry.readWhole ();
        if (! compressed) {
            ze.setMethod (ZipEntry.STORED);
            ze.setSize (entry.getSize ());
            ze.setCompressedSize (entry.getSize ());
            CRC32 crc = new CRC32 ();
            crc.update (bytes);
            ze.setCrc (crc.getValue ());
        }
        jar.putNextEntry (ze);
        jar.write (bytes);
        jar.closeEntry ();
        return bytes.length;
    } else {
        return 0;
    }
}
Functionality: CRC32 File Checksum
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
public static final long crc32 (byte [] data) {
    CRC32 crc32 = new CRC32 ();
    crc32.update (data);
    return crc32.getValue ();
}

Function 2:
public long computeCRC32 () throws IOException {
    CRC32 compCRC32 = new CRC32 ();
    for (int i = 0;
    i < numDataRecords; i ++) {
        try {
            compCRC32.update (readRecord (i + 1));
        } catch (ArrayIndexOutOfBoundsException e) {
            throw new IOException ("computeCRC32: Index out of bounds reading record " + (i + 1));
        } catch (IOException e) {
            throw new IOException ("computeCRC32: error reading record " + (i + 1));
        }
    }
    return compCRC32.getValue ();
}
Functionality: Resize Array
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public static Object deleteElements (Object array, int firstElement, int nElements) {
    if (nElements == 0 || array == null) return array;

    int oldLength = Array.getLength (array);
    if (firstElement >= oldLength) return array;

    int n = oldLength - (firstElement + nElements);
    if (n < 0) n = 0;

    Object t = Array.newInstance (array.getClass ().getComponentType (), firstElement + n);
    if (firstElement > 0) System.arraycopy (array, 0, t, 0, firstElement);

    if (n > 0) System.arraycopy (array, firstElement + nElements, t, firstElement, n);

    return t;
}

Function 2:
private static Object extendArray (Object a1) {
    int n = Array.getLength (a1);
    Object a2 = Array.newInstance (a1.getClass ().getComponentType (), n + ARRAY_SIZE_INCREMENT);
    System.arraycopy (a1, 0, a2, 0, n);
    return a2;
}