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

Function 1:
public void truncateLog (long finalZxid) throws IOException {
    long highestZxid = 0;
    for (File f : dataDir.listFiles ()) {
        long zxid = isValidSnapshot (f);
        if (zxid == - 1) {
            LOG.warn ("Skipping " + f);
            continue;
        }
        if (zxid > highestZxid) {
            highestZxid = zxid;
        }
    }
    File [] files = getLogFiles (dataLogDir.listFiles (), highestZxid);
    boolean truncated = false;
    for (File f : files) {
        FileInputStream fin = new FileInputStream (f);
        InputArchive ia = BinaryInputArchive.getArchive (fin);
        FileChannel fchan = fin.getChannel ();
        try {
            while (true) {
                byte [] bytes = ia.readBuffer ("txtEntry");
                if (bytes.length == 0) {
                    throw new EOFException ();
                }
                InputArchive iab = BinaryInputArchive.getArchive (new ByteArrayInputStream (bytes));
                TxnHeader hdr = new TxnHeader ();
                deserializeTxn (iab, hdr);
                if (ia.readByte ("EOF") != 'B') {
                    throw new EOFException ();
                }
                if (hdr.getZxid () == finalZxid) {
                    long pos = fchan.position ();
                    fin.close ();
                    FileOutputStream fout = new FileOutputStream (f);
                    FileChannel fchanOut = fout.getChannel ();
                    fchanOut.truncate (pos);
                    truncated = true;
                    break;
                }
            }
        } catch (EOFException eof) {
        }
        if (truncated == true) {
            break;
        }
    }
    if (truncated == false) {
        LOG.error ("Not able to truncate the log " + Long.toHexString (finalZxid));
        System.exit (13);
    }
}

Function 2:
public static String stringOfUrl (String addr) throws IOException {
    ByteArrayOutputStream output = new ByteArrayOutputStream ();
    URL url = new URL (addr);
    IOUtils.copy (url.openStream (), output);
    return output.toString ();
}
Functionality: Copy File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public static void kopirujSoubor (File vstup, File vystup) throws IOException {
    FileChannel sourceChannel = new FileInputStream (vstup).getChannel ();
    FileChannel destinationChannel = new FileOutputStream (vystup).getChannel ();
    sourceChannel.transferTo (0, sourceChannel.size (), destinationChannel);
    sourceChannel.close ();
    destinationChannel.close ();
}

Function 2:
public void copyFile (File sourceFile, String toDir, boolean create, boolean overwrite) throws FileNotFoundException, IOException {
    FileInputStream source = null;
    FileOutputStream destination = null;
    byte [] buffer;
    int bytes_read;
    File toFile = new File (toDir);
    if (create && ! toFile.exists ()) toFile.mkdirs ();

    if (toFile.exists ()) {
        File destFile = new File (toDir + "/" + sourceFile.getName ());
        try {
            if (! destFile.exists () || overwrite) {
                source = new FileInputStream (sourceFile);
                destination = new FileOutputStream (destFile);
                buffer = new byte [1024];
                while (true) {
                    bytes_read = source.read (buffer);
                    if (bytes_read == - 1) break;

                    destination.write (buffer, 0, bytes_read);
                }
            }
        } catch (Exception exx) {
            exx.printStackTrace ();
        } finally {
            if (source != null) try {
                source.close ();
            } catch (IOException e) {
            }

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

        }
    }
}
Functionality: Take Screenshot to File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public void takeScreenshot (String title) throws Exception {
    Calendar cal = Calendar.getInstance ();
    SimpleDateFormat sdf = new SimpleDateFormat ("yyyy_MM_dd_HH_mm_ss");
    String time = sdf.format (cal.getTime ());
    Dimension screenSize = Toolkit.getDefaultToolkit ().getScreenSize ();
    Rectangle screenRectangle = new Rectangle (screenSize);
    Robot robot = new Robot ();
    BufferedImage image = robot.createScreenCapture (screenRectangle);
    File f = new File (report.getCurrentTestFolder (), "screenshot_" + time + ".png");
    f.createNewFile ();
    ImageIO.write (image, "png", f);
    report.addLink (getTitle ("Screenshot"), "file:///" + f.getAbsolutePath ());
}

Function 2:
public void screenCapture () throws Exception {
    BufferedImage screencapture = new Robot ().createScreenCapture (new Rectangle (Toolkit.getDefaultToolkit ().getScreenSize ()));
    File file = new File (report.getCurrentTestFolder (), "screencapture.jpg");
    ImageIO.write (screencapture, "jpg", file);
    report.addLink ("screen capture", "screencapture.jpg");
}
Functionality: CRC32 File Checksum
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
public String setCrc32 () {
    CRC32 crc = new CRC32 ();
    crc.update (file);
    crc32 = "" + crc.getValue ();
    return crc32;
}

Function 2:
private static void processFiles (final File packDir, final File file, final ZipOutputStream out) throws IOException {
    if (file.isDirectory ()) {
        final ZipEntry e = new ZipEntry (ZipUtils.convertFileName (packDir, file) + "/");
        out.putNextEntry (e);
        out.closeEntry ();
        final File [] files = file.listFiles ();
        for (final File f : files) ZipUtils.processFiles (packDir, f, out);

    } else {
        final BufferedInputStream bis = new BufferedInputStream (new FileInputStream (file));
        final ZipEntry e = new ZipEntry (ZipUtils.convertFileName (packDir, file));
        final CRC32 crc = new CRC32 ();
        out.putNextEntry (e);
        final byte [] buf = new byte [4096];
        int len = 0;
        while ((len = bis.read (buf)) > 0) {
            out.write (buf, 0, len);
            crc.update (buf, 0, len);
        }
        e.setCrc (crc.getValue ());
        out.closeEntry ();
        bis.close ();
    }
}
Functionality: Zip Files
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
public static void buildKMZ (File kmzFile, Layer layer) throws Exception {
    if (! (layer instanceof TimeLoopGroundOverlay) && ! (layer instanceof GroundOverlayLayer)) throw new IOException ("Invalid layer type:" + layer.getClass ().getName ());

    ZipOutputStream out = new ZipOutputStream (new FileOutputStream (kmzFile));
    String kmlDoc;
    if (layer instanceof TimeLoopGroundOverlay) {
        final TimeLoopGroundOverlay loop = (TimeLoopGroundOverlay) layer;
        kmlDoc = loop.toKML (false, true);
        for (GroundOverlayLayer ov : loop.getOverlays ()) {
            File f = ov.getFileFromCache ();
            String fName = f.getName ();
            logger.debug ("Adding Time Loop Ov to KMZ:" + fName);
            out.putNextEntry (new ZipEntry (fName));
            out.write (Messages.readFile (f));
        }
        if (loop.getLegend () != null) {
            try {
                File f = loop.getLegend ().getFile ();
                logger.debug ("Adding Time Loop LEGEND to KMZ:" + f.getName ());
                out.putNextEntry (new ZipEntry (f.getName ()));
                out.write (Messages.readFile (f));
            } catch (Exception e) {
                logger.error ("Error adding legend " + loop.getLegend () + " to kmz." + e);
            }
        }
    } else {
        final GroundOverlayLayer gov = (GroundOverlayLayer) layer;
        kmlDoc = gov.toKML (false, false);
        File f = new File (gov.getTextureURL ().toURI ());
        String fName = f.getName ();
        logger.debug ("Adding Ground Overlay to KMZ:" + fName);
        out.putNextEntry (new ZipEntry (fName));
        out.write (Messages.readFile (f));
    }
    out.putNextEntry (new ZipEntry ("doc.kml"));
    out.write (kmlDoc.getBytes ());
    out.close ();
}

Function 2:
public void addStringEntry (String filename, String data) throws Exception {
    zOut.putNextEntry (new ZipEntry (filename));
    zOut.write (data.getBytes ());
    zOut.closeEntry ();
    fileCount ++;
}
Functionality: Zip Files
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
private void addFileToZip (String filename, ZipOutputStream out) throws IOException {
    out.putNextEntry (new ZipEntry (filename));
    out.closeEntry ();
}

Function 2:
public static void zi (String s, String z, int i) throws Exception {
    byte [] buffer = s.getBytes ("UTF-8");
    ZipOutputStream out = new ZipOutputStream (new FileOutputStream (z + ".zip"));
    out.putNextEntry (new ZipEntry (i + ".txt"));
    out.write (buffer);
    out.closeEntry ();
    out.close ();
    System.out.println (i + ".txt -> " + z + ".zip");
}
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:
public void addNonKMLFile (final byte [] file, final String inZipFilename) throws IOException {
    ZipEntry entry = new ZipEntry (inZipFilename);
    this.zipOut.putNextEntry (entry);
    this.zipOut.write (file);
    log.info (entry.getName () + " added to kmz.");
}
Functionality: Secure Hash
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public static String md5 (String string) throws NoSuchAlgorithmException {
    MessageDigest md5 = MessageDigest.getInstance ("MD5");
    md5.reset ();
    md5.update (string.getBytes ());
    byte [] result = md5.digest ();
    StringBuffer hexString = new StringBuffer ();
    for (int i = 0;
    i < result.length; i ++) {
        hexString.append (Integer.toHexString ((result [i] & 0xFF) | 0x100).toLowerCase ().substring (1, 3));
    }
    return hexString.toString ();
}

Function 2:
public static byte [] ComputeForBinary (String ThisString) throws Exception {
    byte [] Result;
    MessageDigest MD5Hasher;
    MD5Hasher = MessageDigest.getInstance ("MD5");
    MD5Hasher.update (ThisString.getBytes ("iso-8859-1"));
    Result = MD5Hasher.digest ();
    return Result;
}
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 boolean renameTo (File dest) throws IOException {
    if (dest == null) {
        throw new NullPointerException ("dest");
    }
    if (! file.renameTo (dest)) {
        FileInputStream inputStream = new FileInputStream (file);
        FileOutputStream outputStream = new FileOutputStream (dest);
        FileChannel in = inputStream.getChannel ();
        FileChannel out = outputStream.getChannel ();
        long destsize = in.transferTo (0, size, out);
        in.close ();
        out.close ();
        if (destsize == size) {
            file.delete ();
            file = dest;
            isRenamed = true;
            return true;
        } else {
            dest.delete ();
            return false;
        }
    }
    file = dest;
    isRenamed = true;
    return true;
}
Functionality: Connect to FTP Server
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public static void main (String [] args) {
    FTPClient client = new FTPClient ();
    String sFTP = "ftp.miservidor.com";
    String sUser = "usuario";
    String sPassword = "password";
    try {
        System.out.println ("Conectandose a " + sFTP);
        client.connect (sFTP);
        boolean login = client.login (sUser, sPassword);
        if (login) {
            System.out.println ("Login correcto");
            boolean logout = client.logout ();
            if (logout) {
                System.out.println ("Logout del servidor FTP");
            }
        } else {
            System.out.println ("Error en el login.");
        }
        System.out.println ("Desconectando.");
        client.disconnect ();
    } catch (IOException ioe) {
        ioe.printStackTrace ();
    }
}

Function 2:
private static void getFileFtp (String user, String password, String host, int port, String fileName, String location) throws Exception {
    Log.info ("\nretrieve " + fileName + NEW_LINE);
    FTPClient client = new FTPClient ();
    client.connect (host, port);
    int reply = client.getReplyCode ();
    if (! FTPReply.isPositiveCompletion (reply)) {
        throw new Exception ("FTP fail to connect");
    }
    if (! client.login (user, password)) {
        throw new Exception ("FTP fail to login");
    }
    try {
        File locationFile = new File (location);
        File dest = new File (locationFile, fileName);
        if (dest.exists ()) {
            dest.delete ();
        } else {
            locationFile.mkdirs ();
        }
        boolean status = client.changeWorkingDirectory ("/");
        Log.info ("chdir-status:" + status + NEW_LINE);
        client.setFileTransferMode (FTPClient.BINARY_FILE_TYPE);
        client.setFileType (FTPClient.BINARY_FILE_TYPE);
        client.enterLocalActiveMode ();
        InputStream in = client.retrieveFileStream (fileName);
        if (in == null) {
            Log.error ("Input stream is null\n");
            throw new Exception ("Fail to retrieve file " + fileName);
        }
        Thread.sleep (3000);
        saveInputStreamToFile (in, new File (location, fileName));
    } finally {
        client.disconnect ();
    }
}
Functionality: Copy File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public void update () {
    if (! updatable) {
        Main.fenetre ().erreur (Fenetre.OLD_VERSION);
        return;
    }
    try {
        Main.fenetre ().update ();
        Element remoteRoot = new SAXBuilder ().build (xml).getRootElement ();
        addPackages = new HashMap < Integer, PackageVersion > ();
        Iterator < ? > iterElem = remoteRoot.getChildren ().iterator ();
        while (iterElem.hasNext ()) {
            PackageVersion pack = new PackageVersion ((Element) iterElem.next ());
            addPackages.put (pack.id (), pack);
        }
        removePackages = new HashMap < Integer, PackageVersion > ();
        iterElem = root.getChildren ("package").iterator ();
        while (iterElem.hasNext ()) {
            PackageVersion pack = new PackageVersion ((Element) iterElem.next ());
            int id = pack.id ();
            if (! addPackages.containsKey (id)) {
                removePackages.put (id, pack);
            } else if (addPackages.get (id).version ().equals (pack.version ())) {
                addPackages.remove (id);
            } else {
                addPackages.get (id).ecrase ();
            }

        }
        Iterator < PackageVersion > iterPack = addPackages.values ().iterator ();
        while (iterPack.hasNext ()) {
            install (iterPack.next ());
        }
        iterPack = removePackages.values ().iterator ();
        while (iterPack.hasNext ()) {
            remove (iterPack.next ());
        }
        if (offline) {
            Runtime.getRuntime ().addShutdownHook (new AddPackage (xml, "versions.xml"));
            Main.fenetre ().erreur (Fenetre.UPDATE_TERMINE_RESTART);
        } else {
            File oldXML = new File ("versions.xml");
            oldXML.delete ();
            oldXML.createNewFile ();
            FileChannel out = new FileOutputStream (oldXML).getChannel ();
            FileChannel in = new FileInputStream (xml).getChannel ();
            in.transferTo (0, in.size (), out);
            in.close ();
            out.close ();
            xml.delete ();
            if (restart) {
                Main.fenetre ().erreur (Fenetre.UPDATE_TERMINE_RESTART);
            } else {
                Main.updateVersion ();
            }
        }
    } catch (Exception e) {
        Main.fenetre ().erreur (Fenetre.ERREUR_UPDATE, e);
    }
}

Function 2:
private void printToStdout (InputStream in) throws IOException {
    try {
        IOUtils.copyBytes (in, System.out, getConf (), false);
    } finally {
        in.close ();
    }
}
Functionality: Zip Files
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
public void setUp () throws IOException {
    tmp = TestingUtil.tmpFile (new File ("."));
    ZipOutputStream os = new ZipOutputStream (new FileOutputStream (tmp));
    os.putNextEntry (new ZipEntry ("key0"));
    os.write (0x01);
    os.write (0x05);
    os.closeEntry ();
    os.putNextEntry (new ZipEntry ("key1"));
    os.write (0x02);
    os.closeEntry ();
    os.putNextEntry (new ZipEntry ("properties"));
    os.write ("foo=bar\n".getBytes ());
    os.closeEntry ();
    os.close ();
    storer = new ZipStorer (new ZipFile (tmp));
}

Function 2:
public Boolean execute (String sDestinationFilename) {
    ResourcesManager manager = new ResourcesManager ();
    BufferedInputStream oOrigin = null;
    FileOutputStream oDestination;
    ZipOutputStream oOutput;
    byte [] aData;
    try {
        System.out.println ("Compressing the model");
        oDestination = new FileOutputStream (sDestinationFilename);
        oOutput = new ZipOutputStream (new BufferedOutputStream (oDestination));
        Collection < File > files = manager.getFiles (tempFilePath);
        aData = new byte [BUFFER_SIZE];
        Iterator < File > fileIterator = files.iterator ();
        while (fileIterator.hasNext ()) {
            File currentFile = fileIterator.next ();
            String sFilename = currentFile.getAbsolutePath ();
            sFilename = LibraryString.replaceAll (sFilename, Strings.BAR135, Strings.BAR45);
            FileInputStream fisInput = new FileInputStream (sFilename);
            oOrigin = new BufferedInputStream (fisInput, BUFFER_SIZE);
            sFilename = sFilename.substring (sFilename.indexOf (tempFilePath) + tempFilePath.length () + 1);
            ZipEntry oEntry = new ZipEntry (sFilename.replace ('\\', '/'));
            oOutput.putNextEntry (oEntry);
            int iCount;
            while ((iCount = oOrigin.read (aData, 0, BUFFER_SIZE)) != - 1) {
                oOutput.write (aData, 0, iCount);
            }
            oOrigin.close ();
            fisInput.close ();
        }
        oOutput.close ();
        System.out.println ("Model compressed");
        AgentFilesystem.removeDir (tempFilePath);
    } catch (Exception oException) {
        oException.printStackTrace ();
        return false;
    }
    return true;
}
Functionality: Zip Files
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
public static void zipDirectory (String dir, String zipfile) throws IOException, IllegalArgumentException {
    File d = new File (dir);
    if (! d.isDirectory ()) throw new IllegalArgumentException ("Not a directory:  " + dir);

    String [] entries = d.list ();
    byte [] buffer = new byte [4096];
    int bytesRead;
    ZipOutputStream out = new ZipOutputStream (new FileOutputStream (zipfile));
    for (int i = 0;
    i < entries.length; i ++) {
        File f = new File (d, entries [i]);
        if (f.isDirectory ()) continue;

        FileInputStream in = new FileInputStream (f);
        ZipEntry entry = new ZipEntry (f.getPath ());
        out.putNextEntry (entry);
        while ((bytesRead = in.read (buffer)) != - 1) out.write (buffer, 0, bytesRead);

        in.close ();
    }
    out.close ();
}

Function 2:
protected static void scaleImage (InputStream in, String name, ZipOutputStream out, double scaleX, double scaleY) throws Exception {
    BufferedImage img = ImageIO.read (in);
    Image scaled = img.getScaledInstance ((int) (img.getWidth () * scaleX), (int) (img.getHeight () * scaleY), Image.SCALE_SMOOTH);
    BufferedImage bScaled = new BufferedImage (img.getWidth (), img.getHeight (), BufferedImage.TYPE_INT_ARGB);
    bScaled.getGraphics ().drawImage (scaled, 0, 0, null);
    out.putNextEntry (new ZipEntry (name));
    ImageIO.write (bScaled, "PNG", out);
}
Functionality: Copy File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public static void main (String [] args) {
    if (args.length != 1) {
        System.out.println ("Usage: GUnzip source");
        return;
    }
    String zipname, source;
    if (args [0].endsWith (".gz")) {
        zipname = args [0];
        source = args [0].substring (0, args [0].length () - 3);
    } else {
        zipname = args [0] + ".gz";
        source = args [0];
    }
    GZIPInputStream zipin;
    try {
        FileInputStream in = new FileInputStream (zipname);
        zipin = new GZIPInputStream (in);
    } catch (IOException e) {
        System.out.println ("Couldn't open " + zipname + ".");
        return;
    }
    byte [] buffer = new byte [sChunk];
    try {
        FileOutputStream out = new FileOutputStream (source);
        int length;
        while ((length = zipin.read (buffer, 0, sChunk)) != - 1) out.write (buffer, 0, length);

        out.close ();
    } catch (IOException e) {
        System.out.println ("Couldn't decompress " + args [0] + ".");
    }
    try {
        zipin.close ();
    } catch (IOException e) {
    }
}

Function 2:
private String fetchCompareContent () throws IOException {
    URL url = new URL (compareTo);
    StringWriter sw = new StringWriter ();
    IOUtils.copy (url.openStream (), sw);
    return sw.getBuffer ().toString ();
}
Functionality: CRC32 File Checksum
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
protected AbstractUnicodeExtraField (String text, byte [] bytes, int off, int len) {
    CRC32 crc32 = new CRC32 ();
    crc32.update (bytes, off, len);
    nameCRC32 = crc32.getValue ();
    try {
        unicodeName = text.getBytes ("UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException ("FATAL: UTF-8 encoding not supported.", e);
    }
}

Function 2:
static long computeFileCrc (File f) {
    FileInputStream fis = null;
    try {
        fis = new FileInputStream (f);
        CRC32 crc = new CRC32 ();
        byte [] data = new byte [BUFFER_SIZE];
        int len = - 1;
        while ((len = fis.read (data)) > - 1) {
            crc.update (data, 0, len);
        }
        return crc.getValue ();
    } catch (IOException e) {
        logger.error ("Unexpected exception while computing CRC on file: " + f.getAbsolutePath (), e);
        return - 1;
    } finally {
        try {
            fis.close ();
        } catch (IOException e) {
        }
    }
}