primakov/ML4SE2023_Group4_Dataset.csv huggingface dataset:
Functionality: Delete Folder and Contents
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
private void cleanupStagingEnvironment (File stagingDir) throws FileUpdateException {
    if (stagingDir != null && stagingDir.exists () && stagingDir.isDirectory ()) {
        File [] files = stagingDir.listFiles ();
        for (int i = 0;
        i < files.length; i ++) {
            File f = files [i];
            if (! f.delete ()) {
                logger.error ("Could not delete: " + f.getAbsolutePath ());
                throw new SessionEnvironmentException ("Could not delete: " + f.getAbsolutePath ());
            }
        }
        if (stagingDir.exists ()) {
            if (stagingDir.delete ()) {
                logger.debug (stagingDir + " was successfully deleted");
            } else {
                logger.error ("Could not clean up staging directory: " + stagingDir.getAbsolutePath ());
                throw new SessionEnvironmentException ("Could not remove directory: " + stagingDir.getAbsolutePath ());
            }
        }
    } else {
        throw new SessionEnvironmentException ("Staging directory undefined, does not exist, or is not a directory");
    }
}

Function 2:
public static boolean deleteDir (File dir) {
    if (dir.exists ()) {
        File [] files = dir.listFiles ();
        for (int i = 0;
        i < files.length; i ++) {
            if (files [i].isDirectory ()) {
                deleteDir (files [i]);
            } else {
                files [i].delete ();
            }
        }
    }
    return (dir.delete ());
}
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:
private void addToZip (String path, String srcFile, ZipOutputStream zip) {
    File folder = new File (srcFile);
    if (folder.isDirectory ()) {
        this.addFolderToZip (path, srcFile, zip);
    } else {
        try {
            boolean includeFile = false;
            if (this.excludePattern == null) {
                includeFile = true;
            } else {
                if (srcFile.contains (this.excludePattern)) {
                    includeFile = false;
                } else {
                    includeFile = true;
                }
            }
            if (includeFile == true) {
                this.zipMonitor.setNumberNextFile ();
                this.zipMonitor.setCurrentJobFile (srcFile);
                if (zipMonitor.isCanceled ()) {
                    return;
                }
                FileInputStream in = new FileInputStream (srcFile);
                zip.putNextEntry (new ZipEntry (path + File.separator + folder.getName ()));
                byte [] buf = new byte [1024];
                int len;
                while ((len = in.read (buf)) > 0) {
                    zip.write (buf, 0, len);
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace ();
        }
    }
}
Functionality: Instantiate Using Reflection
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
private Service getServiceInstance (String className) {
    try {
        Class clazz = Class.forName (className);
        return (Service) clazz.getConstructor (new Class [] {}).newInstance (new Object [] {});
    } catch (ClassNotFoundException e) {
        this.logger.error (className, e);
        return null;
    } catch (SecurityException e) {
        this.logger.error (className, e);
        return null;
    } catch (NoSuchMethodException e) {
        this.logger.error (className, e);
        return null;
    } catch (IllegalArgumentException e) {
        this.logger.error (className, e);
        return null;
    } catch (InstantiationException e) {
        this.logger.error (className, e);
        return null;
    } catch (IllegalAccessException e) {
        this.logger.error (className, e);
        return null;
    } catch (InvocationTargetException e) {
        this.logger.error (className, e);
        return null;
    }
}

Function 2:
private void setCommandInput () {
    mCommandInput = null;
    try {
        Class < ? > consoleReaderClass = Class.forName ("jline.ConsoleReader");
        if (consoleReaderClass != null) {
            Class < ? > consoleInputClass = Class.forName ("jline.ConsoleReaderInputStream");
            if (consoleInputClass != null) {
                Object jline = consoleReaderClass.newInstance ();
                Constructor < ? > constructor = consoleInputClass.getConstructor (consoleReaderClass);
                if (constructor != null) {
                    mCommandInput = (InputStream) constructor.newInstance (jline);
                }
            }
        }
    } catch (Exception e1) {
        mLogger.info ("Exception loading jline");
    }
    if (mCommandInput == null) mCommandInput = System.in;

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

Function 1:
public static String CreateZip (String [] filesToZip, String zipFileName) {
    byte [] buffer = new byte [18024];
    try {
        ZipOutputStream out = new ZipOutputStream (new FileOutputStream (zipFileName));
        out.setLevel (Deflater.BEST_COMPRESSION);
        for (int i = 0;
        i < filesToZip.length; i ++) {
            FileInputStream in = new FileInputStream (filesToZip [i]);
            String fileName = null;
            for (int X = filesToZip [i].length () - 1;
            X >= 0; X --) {
                if (filesToZip [i].charAt (X) == '\\' || filesToZip [i].charAt (X) == '/') {
                    fileName = filesToZip [i].substring (X + 1);
                    break;
                } else if (X == 0) fileName = filesToZip [i];

            }
            out.putNextEntry (new ZipEntry (fileName));
            int len;
            while ((len = in.read (buffer)) > 0) out.write (buffer, 0, len);

            out.closeEntry ();
            in.close ();
        }
        out.close ();
    } catch (IllegalArgumentException e) {
        return "Failed to create zip: " + e.toString ();
    } catch (FileNotFoundException e) {
        return "Failed to create zip: " + e.toString ();
    } catch (IOException e) {
        return "Failed to create zip: " + e.toString ();
    }
    return "Success";
}

Function 2:
private void createButtonCopyToClipboard () {
    buttonCopyToClipboard = new Button (shell, SWT.PUSH);
    buttonCopyToClipboard.setText ("Co&py to Clipboard");
    buttonCopyToClipboard.setLayoutData (SharedStyle.relativeToBottomRight (buttonClose));
    buttonCopyToClipboard.addSelectionListener (new SelectionAdapter () {
        @Override
        public void widgetSelected (final SelectionEvent event) {
            IOUtils.copyToClipboard (Version.getEnvironmentReport ());
        }}

    );
}
Functionality: Copy File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public void transform (File inputMatrixFile, MatrixIO.Format inputFormat, File outputMatrixFile) throws IOException {
    FileChannel original = new FileInputStream (inputMatrixFile).getChannel ();
    FileChannel copy = new FileOutputStream (outputMatrixFile).getChannel ();
    copy.transferFrom (original, 0, original.size ());
    original.close ();
    copy.close ();
}

Function 2:
public static void main (String [] args) throws IOException {
    if (args.length == 0) {
        System.out.println ("Usage: \nGZIPcompress file\n" + "\tUses GZIP compression to compress " + "the file to test.gz");
        System.exit (1);
    }
    BufferedReader in = new BufferedReader (new FileReader (args [0]));
    BufferedOutputStream out = new BufferedOutputStream (new GZIPOutputStream (new FileOutputStream ("test.gz")));
    System.out.println ("Writing file");
    int c;
    while ((c = in.read ()) != - 1) out.write (c);

    in.close ();
    out.close ();
    System.out.println ("Reading file");
    BufferedReader in2 = new BufferedReader (new InputStreamReader (new GZIPInputStream (new FileInputStream ("test.gz"))));
    String s;
    while ((s = in2.readLine ()) != null) System.out.println (s);

}
Functionality: Execute update and rollback.
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public static void insert (Connection c, MLPApprox net, int azioneId, String descrizione, int [] indiciID, int output, Date from, Date to) throws SQLException {
    try {
        PreparedStatement ps = c.prepareStatement (insertNet, PreparedStatement.RETURN_GENERATED_KEYS);
        ArrayList < Integer > indexes = new ArrayList < Integer > (indiciID.length);
        for (int i = 0;
        i < indiciID.length; i ++) indexes.add (indiciID [i]);

        ps.setObject (1, net);
        ps.setInt (2, azioneId);
        ps.setObject (3, indexes);
        ps.setInt (4, output);
        ps.setDate (5, from);
        ps.setDate (6, to);
        ps.setString (7, descrizione);
        ps.executeUpdate ();
        ResultSet key = ps.getGeneratedKeys ();
        if (key.next ()) {
            int id = key.getInt (1);
            for (int i = 0;
            i < indiciID.length; i ++) {
                PreparedStatement psIndex = c.prepareStatement (insertNetIndex);
                psIndex.setInt (1, indiciID [i]);
                psIndex.setInt (2, id);
                psIndex.executeUpdate ();
            }
        }
    } catch (SQLException e) {
        e.printStackTrace ();
        try {
            c.rollback ();
        } catch (SQLException e1) {
            e1.printStackTrace ();
            throw e1;
        }
        throw e;
    }
}

Function 2:
public boolean ponerRivalxRonda (int idJugadorDiv, int idRonda, int dato) {
    int intResult = 0;
    String sql = "UPDATE jugadorxdivxronda " + " SET idPareoRival = " + dato + " WHERE jugadorxDivision_idJugadorxDivision = " + idJugadorDiv + " AND ronda_numeroRonda = " + idRonda;
    try {
        connection = conexionBD.getConnection ();
        connection.setAutoCommit (false);
        ps = connection.prepareStatement (sql);
        intResult = ps.executeUpdate ();
        connection.commit ();
    } catch (SQLException ex) {
        ex.printStackTrace ();
        try {
            connection.rollback ();
        } catch (SQLException exe) {
            exe.printStackTrace ();
        }
    } finally {
        conexionBD.close (ps);
        conexionBD.close (connection);
    }
    return (intResult > 0);
}
Functionality: Zip Files
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
public void streamDataToZip (VolumeTimeSeries vol, ZipOutputStream zout) throws Exception {
    ZipEntry entry = new ZipEntry (vol.getId () + ".dat");
    zout.putNextEntry (entry);
    if (vol instanceof FloatVolumeTimeSeries) {
        streamData (((FloatVolumeTimeSeries) vol).getData (), zout);
    } else if (vol instanceof RGBVolumeTimeSeries) {
        streamData (((RGBVolumeTimeSeries) vol).getARGBData (), zout);
    } else if (vol instanceof BinaryVolumeTimeSeries) {
        streamData (((BinaryVolumeTimeSeries) vol).getBinaryData (), zout);
    }

}

Function 2:
private void zipDir (String baseDir, String dir2zip, ZipOutputStream zos) throws IOException {
    File zipDir = new File (dir2zip);
    String [] dirList = zipDir.list ();
    for (int i = 0;
    i < dirList.length; i ++) {
        File f = new File (zipDir, dirList [i]);
        if (f.isDirectory ()) {
            String filePath = f.getPath ();
            zipDir (baseDir, filePath, zos);
        } else {
            FileInputStream fis = new FileInputStream (f);
            String basePath = new File (baseDir).getCanonicalPath ();
            String entryName = f.getCanonicalPath ();
            if (entryName.length () > basePath.length ()) entryName = entryName.substring (basePath.length () + 1);

            ZipEntry anEntry = new ZipEntry (entryName);
            zos.putNextEntry (anEntry);
            byte [] readBuffer = new byte [512];
            int bytesIn = 0;
            while ((bytesIn = fis.read (readBuffer)) != - 1) {
                zos.write (readBuffer, 0, bytesIn);
            }
            fis.close ();
        }
    }
}
Functionality: Instantiate Using Reflection
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public void updateVal (Configuration config) {
    updateValSuper (config);
    String value = field.getText ();
    Class [] params = new Class [1];
    Object [] args = new Object [1];
    params [0] = String.class;
    args [0] = value;
    Object o = null;
    try {
        Constructor c = mObj.getClass ().getConstructor (params);
        o = c.newInstance (args);
    } catch (Exception ex) {
        throw new IllegalStateException ("Problem writing unknown class to configuration");
    }
    config.put (key, o);
}

Function 2:
public < T extends Unit > T buildNewUnit (String propertiesFile, Class < T > unitType) throws Exception {
    Constructor < T > constructor = unitType.getConstructor (String.class);
    T newUnit = constructor.newInstance (propertiesFile);
    units.add (newUnit);
    return newUnit;
}
Functionality: CRC32 File Checksum
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
public static long compute (String str) {
    CRC32 crc = new CRC32 ();
    Adler32 adler = new Adler32 ();
    crc.update (str.getBytes ());
    adler.update (str.getBytes ());
    long dg1 = crc.getValue ();
    long dg2 = adler.getValue ();
    crc.update (String.valueOf (dg2).getBytes ());
    adler.update (String.valueOf (dg1).getBytes ());
    long d3 = crc.getValue ();
    long d4 = adler.getValue ();
    dg1 ^= d4;
    dg2 ^= d3;
    return (dg2 ^ ((dg1>>> 32) | (dg1 << 32)));
}

Function 2:
private static long crc32 (byte [] stream) {
    CRC32 crc32 = new CRC32 ();
    crc32.reset ();
    crc32.update (stream);
    long res = crc32.getValue ();
    return res;
}
Functionality: Copy File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public static void copy (File source, File dest) throws BuildException {
    dest = new File (dest, source.getName ());
    if (source.isFile ()) {
        byte [] buffer = new byte [4096];
        FileInputStream fin = null;
        FileOutputStream fout = null;
        try {
            fin = new FileInputStream (source);
            fout = new FileOutputStream (dest);
            int count = 0;
            while ((count = fin.read (buffer)) > 0) fout.write (buffer, 0, count);

            fin.close ();
            fout.close ();
        } catch (IOException ex) {
            throw new BuildException (ex);
        } finally {
            try {
                if (fin != null) fin.close ();

            } catch (IOException ex) {
            }
            try {
                if (fout != null) fout.close ();

            } catch (IOException ex) {
            }
        }
    } else {
        dest.mkdirs ();
        File [] children = source.listFiles ();
        for (File child : children) copy (child, dest);

    }
}

Function 2:
public static void saveZipComponents (ZipComponents zipComponents, File zipFile) throws FileNotFoundException, IOException, Exception {
    ZipOutputStream zipOutStream = new ZipOutputStream (new FileOutputStream (zipFile));
    for (ZipComponent comp : zipComponents.getComponents ()) {
        ZipEntry newEntry = new ZipEntry (comp.getName ());
        zipOutStream.putNextEntry (newEntry);
        if (comp.isDirectory ()) {
        } else {
            if (comp.getName ().endsWith ("document.xml") || comp.getName ().endsWith ("document.xml.rels")) {
            }
            InputStream inputStream = comp.getInputStream ();
            IOUtils.copy (inputStream, zipOutStream);
            inputStream.close ();
        }
    }
    zipOutStream.close ();
}
Functionality: Copy File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
private boolean enregistreToi () {
    PrintWriter lEcrivain;
    String laDest = "./img_types/" + sonImage;
    if (! new File ("./img_types").exists ()) {
        new File ("./img_types").mkdirs ();
    }
    try {
        FileChannel leFicSource = new FileInputStream (sonFichier).getChannel ();
        FileChannel leFicDest = new FileOutputStream (laDest).getChannel ();
        leFicSource.transferTo (0, leFicSource.size (), leFicDest);
        leFicSource.close ();
        leFicDest.close ();
        lEcrivain = new PrintWriter (new FileWriter (new File ("bundll/types.jay"), true));
        lEcrivain.println (sonNom);
        lEcrivain.println (sonImage);
        if (sonOptionRadio1.isSelected ()) {
            lEcrivain.println ("0:?");
        }
        if (sonOptionRadio2.isSelected ()) {
            lEcrivain.println ("1:" + JOptionPane.showInputDialog (null, "Vous avez choisis de rendre ce terrain difficile � franchir.\nVeuillez en indiquer la raison.", "Demande de pr�cision", JOptionPane.INFORMATION_MESSAGE));
        }
        if (sonOptionRadio3.isSelected ()) {
            lEcrivain.println ("2:?");
        }
        lEcrivain.close ();
        return true;
    } catch (Exception lException) {
        return false;
    }
}

Function 2:
public static boolean dumpFile (String from, File to, String lineBreak) {
    try {
        BufferedReader in = new BufferedReader (new InputStreamReader (new FileInputStream (from)));
        BufferedWriter out = new BufferedWriter (new OutputStreamWriter (new FileOutputStream (to)));
        String line = null;
        while ((line = in.readLine ()) != null) out.write (Main.getInstance ().resolve (line) + lineBreak);

        in.close ();
        out.close ();
    } catch (Exception e) {
        Installer.getInstance ().getLogger ().log (StringUtils.getStackTrace (e));
        return false;
    }
    return true;
}
Functionality: Copy File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public static File copyFile (File from, File to) throws IOException {
    FileOutputStream fos = new FileOutputStream (to);
    FileInputStream fis = new FileInputStream (from);
    FileChannel foc = fos.getChannel ();
    FileChannel fic = fis.getChannel ();
    foc.transferFrom (fic, 0, fic.size ());
    foc.close ();
    fic.close ();
    return to;
}

Function 2:
public void bindDownload (Download download) throws BindingException {
    List < ChunkDownload > chunks = download.getChunks ();
    File destination = download.getFile ();
    FileOutputStream fos = null;
    try {
        fos = FileUtils.openOutputStream (destination);
        for (ChunkDownload chunk : chunks) {
            String filePath = chunk.getChunkFilePath ();
            InputStream ins = null;
            try {
                File chunkFile = new File (filePath);
                ins = FileUtils.openInputStream (chunkFile);
                IOUtils.copy (ins, fos);
                chunkFile.delete ();
            } catch (IOException e) {
                e.printStackTrace ();
            } finally {
                ins.close ();
            }
        }
        download.getWorkDir ().delete ();
        download.complete ();
    } catch (IOException e) {
        logger.error ("IO Exception while copying the chunk " + e.getMessage (), e);
        e.printStackTrace ();
        throw new BindingException ("IO Exception while copying the chunk " + e.getMessage (), e);
    } finally {
        try {
            fos.close ();
        } catch (IOException e) {
            logger.error ("IO Exception while copying closing stream of the target file " + e.getMessage (), e);
            e.printStackTrace ();
            throw new BindingException ("IO Exception while copying closing stream of the target file " + e.getMessage (), e);
        }
    }
}
Functionality: Zip Files
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
File createJar (File jar, String...entries) throws IOException {
    OutputStream out = new FileOutputStream (jar);
    try {
        JarOutputStream jos = new JarOutputStream (out);
        for (String e : entries) {
            jos.putNextEntry (new JarEntry (getPathForZipEntry (e)));
            jos.write (getBodyForEntry (e).getBytes ());
        }
        jos.close ();
    } finally {
        out.close ();
    }
    return jar;
}

Function 2:
public void writeBookOutput (ZipOutputStream outputStream, String cleanSGML) {
    boolean isCompressedOutput = false;
    if (outputStream != null) {
        isCompressedOutput = true;
    }
    try {
        FileWriter fw = new FileWriter (bookPath);
        if (isCompressedOutput) {
            if (witsInstance.getOutputType ().equals ("solbook")) {
                SolBookWriter cWriter = new SolBookWriter (witsInstance, cleanSGML, props);
                ZipEntry entry = new ZipEntry (bookPath.getName ());
                try {
                    outputStream.putNextEntry (entry);
                    outputStream.write (cWriter.getPartialBookBody ().getBytes ());
                    outputStream.closeEntry ();
                } catch (IOException ex) {
                    ex.printStackTrace ();
                }
            }
            if (witsInstance.getOutputType ().equals ("docbook")) {
                DocBookWriter cWriter = new DocBookWriter (cleanSGML, props);
                ZipEntry entry = new ZipEntry (bookPath.getName ());
                try {
                    outputStream.putNextEntry (entry);
                    outputStream.write (cWriter.getPartialBookBody ().getBytes ());
                    outputStream.closeEntry ();
                } catch (IOException ex) {
                    ex.printStackTrace ();
                }
            }
        } else {
            if (witsInstance.getOutputType ().equals ("solbook")) {
                SolBookWriter bWriter = new SolBookWriter (witsInstance, cleanSGML, props);
                fw.write (bWriter.getPartialBookBody ());
                fw.flush ();
                fw.close ();
            }
            if (witsInstance.getOutputType ().equals ("docbook")) {
                DocBookWriter bWriter = new DocBookWriter (cleanSGML, props);
                fw.write (bWriter.getPartialBookBody ());
                fw.flush ();
                fw.close ();
            }
        }
    } catch (IOException e) {
        System.out.println ("Error while writing to: " + bookPath + ". PLease check the path/permission.");
    }
}
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:
private void checkRoundtrip (byte [] content) throws Exception {
    InputStream in = new ByteArrayInputStream (content);
    ByteArrayOutputStream out = new ByteArrayOutputStream ();
    CodecUtil.encodeQuotedPrintable (in, out);
    in = new QuotedPrintableInputStream (new ByteArrayInputStream (out.toByteArray ()));
    out = new ByteArrayOutputStream ();
    IOUtils.copy (in, out);
    assertEquals (content, out.toByteArray ());
}