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

Function 1:
@Override
public void execute () {
    File currentModelDirectory = new File (this.globalData.getData (String.class, GlobalData.MODEL_INSTALL_DIRECTORY));
    File mobileDirectory = new File (currentModelDirectory, "mobile");
    mobileDirectory.mkdir ();
    File mobileModelFile = new File (mobileDirectory, "mobile_model.zip");
    FileOutputStream outputStream = null;
    ZipOutputStream zipStream = null;
    BusinessModel businessModel = BusinessUnit.getInstance ().getBusinessModel ();
    try {
        mobileModelFile.createNewFile ();
        outputStream = new FileOutputStream (mobileModelFile);
        zipStream = new ZipOutputStream (outputStream);
        Dictionary dictionary = businessModel.getDictionary ();
        for (Definition definition : dictionary.getAllDefinitions ()) {
            ZipEntry entry = new ZipEntry (definition.getRelativeFileName ());
            zipStream.putNextEntry (entry);
            writeBinary (definition.getAbsoluteFileName (), zipStream);
        }
        final String modelFilename = "model.xml";
        ZipEntry entry = new ZipEntry (modelFilename);
        zipStream.putNextEntry (entry);
        writeBinary (businessModel.getAbsoluteFilename (modelFilename), zipStream);
        final String logoFilename = dictionary.getModel ().getImageSource (LogoType.mobile);
        entry = new ZipEntry (logoFilename);
        zipStream.putNextEntry (entry);
        writeBinary (businessModel.getAbsoluteFilename (logoFilename), zipStream);
    } catch (IOException e) {
        agentLogger.error (e);
    } finally {
        StreamHelper.close (zipStream);
        StreamHelper.close (outputStream);
    }
}

Function 2:
void copyZipToZip (ZipInputStream zis, ZipOutputStream zos) throws Exception {
    ZipEntry entry;
    byte [] buffer = new byte [1];
    while ((entry = zis.getNextEntry ()) != null) {
        zos.putNextEntry (new ZipEntry (entry.getName ()));
        while (zis.available () == 1) {
            zis.read (buffer, 0, buffer.length);
            zos.write (buffer, 0, buffer.length);
        }
        zis.closeEntry ();
        zos.closeEntry ();
    }
}
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 static void zip (File srcDir, File originSrcDir, ZipOutputStream dstStream) throws IOException {
    byte [] buffer = new byte [ZIP_BUFFER_SIZE];
    int bytes = 0;
    String [] dirList = srcDir.list ();
    for (int i = 0;
    i < dirList.length; i ++) {
        File file = new File (srcDir, dirList [i]);
        if (file.isDirectory ()) {
            zip (file, originSrcDir, dstStream);
            continue;
        }
        FileInputStream fis = new FileInputStream (file);
        ZipEntry entry = new ZipEntry (TFileHandler.removeDirectoryPath (originSrcDir.getAbsolutePath (), file.getAbsolutePath ()));
        dstStream.putNextEntry (entry);
        while ((bytes = fis.read (buffer)) != - 1) dstStream.write (buffer, 0, bytes);

        fis.close ();
    }
}
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:
public static boolean addZipEntry (String srcZipFile, String newEntryFile, String dstFile) {
    java.util.zip.ZipOutputStream zout = null;
    InputStream is = null;
    try {
        if (new File (newEntryFile).isDirectory () && ! newEntryFile.substring (newEntryFile.length () - 1).equals (File.separator)) {
            newEntryFile = newEntryFile + File.separator;
        }
        System.err.println ("============");
        File fn = new File (dstFile);
        if (! fn.exists ()) {
            fn.createNewFile ();
        }
        zout = new java.util.zip.ZipOutputStream (new FileOutputStream (dstFile));
        ZipFile zipfile = new ZipFile (srcZipFile);
        ZipEntry entry = null;
        Enumeration e = zipfile.entries ();
        byte [] buffer = new byte [1024];
        while (e.hasMoreElements ()) {
            entry = (ZipEntry) e.nextElement ();
            System.err.println (entry.getName ());
            zout.putNextEntry (entry);
            is = new BufferedInputStream (zipfile.getInputStream (entry));
            int count;
            while ((count = is.read (buffer, 0, 1024)) != - 1) {
                zout.write (buffer, 0, count);
                zout.flush ();
            }
            is.close ();
            zout.closeEntry ();
        }
        zipFile (null, newEntryFile, "*.*", zout);
        zout.close ();
        return true;
    } catch (java.io.IOException ioex) {
        LogUtil.getLogger ().error (ioex.getMessage (), ioex);
        ioex.printStackTrace ();
        return false;
    } finally {
        try {
            if (zout != null) {
                zout.close ();
            }
        } catch (Exception ex) {
        }
        try {
            if (is != null) {
                is.close ();
            }
        } catch (Exception ex) {
        }
    }
}
Functionality: Execute update and rollback.
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public void testSavepoint4 () throws Exception {
    Statement stmt = con.createStatement ();
    stmt.execute ("CREATE TABLE #savepoint4 (data int)");
    stmt.close ();
    con.setAutoCommit (false);
    for (int i = 0;
    i < 3; i ++) {
        PreparedStatement pstmt = con.prepareStatement ("INSERT INTO #savepoint4 (data) VALUES (?)");
        pstmt.setInt (1, 1);
        assertTrue (pstmt.executeUpdate () == 1);
        Savepoint savepoint = con.setSavepoint ();
        assertNotNull (savepoint);
        assertTrue (savepoint.getSavepointId () == 1);
        try {
            savepoint.getSavepointName ();
            assertTrue (false);
        } catch (SQLException e) {
        }
        pstmt.setInt (1, 2);
        assertTrue (pstmt.executeUpdate () == 1);
        pstmt.close ();
        pstmt = con.prepareStatement ("SELECT SUM(data) FROM #savepoint4");
        ResultSet rs = pstmt.executeQuery ();
        assertTrue (rs.next ());
        assertTrue (rs.getInt (1) == 3);
        assertTrue (! rs.next ());
        pstmt.close ();
        rs.close ();
        con.rollback (savepoint);
        pstmt = con.prepareStatement ("SELECT SUM(data) FROM #savepoint4");
        rs = pstmt.executeQuery ();
        assertTrue (rs.next ());
        assertTrue (rs.getInt (1) == 1);
        assertTrue (! rs.next ());
        pstmt.close ();
        rs.close ();
        con.rollback ();
    }
    con.setAutoCommit (true);
}

Function 2:
public boolean actualizarIdPartida (int idJugadorDiv, int idRonda, int idPartida) {
    int intResult = 0;
    String sql = "UPDATE jugadorxdivxronda " + " SET idPartida = " + idPartida + " 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: Secure Hash
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public static String MD5 (String s) {
    try {
        MessageDigest m = MessageDigest.getInstance ("MD5");
        m.update (s.getBytes (), 0, s.length ());
        return new BigInteger (1, m.digest ()).toString (16);
    } catch (NoSuchAlgorithmException ex) {
        return "";
    }
}

Function 2:
private byte [] szyfrujKlucz (byte [] kluczSesyjny) {
    byte [] zaszyfrowanyKlucz = null;
    byte [] klucz = null;
    try {
        MessageDigest skrot = MessageDigest.getInstance ("SHA-1");
        skrot.update (haslo.getBytes ());
        byte [] skrotHasla = skrot.digest ();
        Object kluczDoKlucza = MARS_Algorithm.makeKey (skrotHasla);
        int resztaKlucza = this.dlugoscKlucza % ROZMIAR_BLOKU;
        if (resztaKlucza == 0) {
            klucz = kluczSesyjny;
            zaszyfrowanyKlucz = new byte [this.dlugoscKlucza];
        } else {
            int liczbaBlokow = this.dlugoscKlucza / ROZMIAR_BLOKU + 1;
            int nowyRozmiar = liczbaBlokow * ROZMIAR_BLOKU;
            zaszyfrowanyKlucz = new byte [nowyRozmiar];
            klucz = new byte [nowyRozmiar];
            byte roznica = (byte) (ROZMIAR_BLOKU - resztaKlucza);
            System.arraycopy (kluczSesyjny, 0, klucz, 0, kluczSesyjny.length);
            for (int i = kluczSesyjny.length;
            i < nowyRozmiar; i ++) klucz [i] = (byte) roznica;

        }
        byte [] szyfrogram = null;
        int liczbaBlokow = klucz.length / ROZMIAR_BLOKU;
        int offset = 0;
        for (offset = 0; offset < liczbaBlokow; offset ++) {
            szyfrogram = MARS_Algorithm.blockEncrypt (klucz, offset * ROZMIAR_BLOKU, kluczDoKlucza);
            System.arraycopy (szyfrogram, 0, zaszyfrowanyKlucz, offset * ROZMIAR_BLOKU, szyfrogram.length);
        }
    } catch (InvalidKeyException ex) {
        Logger.getLogger (SzyfrowaniePliku.class.getName ()).log (Level.SEVERE, null, ex);
    } catch (NoSuchAlgorithmException ex) {
        ex.printStackTrace ();
    }
    return zaszyfrowanyKlucz;
}
Functionality: Secure Hash
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public boolean verify (final char [] password, final String encryptedPassword) {
    MessageDigest digest = null;
    int size = 0;
    String base64 = null;
    if (encryptedPassword.regionMatches (true, 0, "{SHA}", 0, 5)) {
        size = 20;
        base64 = encryptedPassword.substring (5);
        try {
            digest = MessageDigest.getInstance ("SHA-1");
        } catch (final NoSuchAlgorithmException e) {
            throw new IllegalStateException ("Invalid algorithm");
        }
    } else if (encryptedPassword.regionMatches (true, 0, "{SSHA}", 0, 6)) {
        size = 20;
        base64 = encryptedPassword.substring (6);
        try {
            digest = MessageDigest.getInstance ("SHA-1");
        } catch (final NoSuchAlgorithmException e) {
            throw new IllegalStateException ("Invalid algorithm");
        }
    } else if (encryptedPassword.regionMatches (true, 0, "{MD5}", 0, 5)) {
        size = 16;
        base64 = encryptedPassword.substring (5);
        try {
            digest = MessageDigest.getInstance ("MD5");
        } catch (final NoSuchAlgorithmException e) {
            throw new IllegalStateException ("Invalid algorithm");
        }
    } else if (encryptedPassword.regionMatches (true, 0, "{SMD5}", 0, 6)) {
        size = 16;
        base64 = encryptedPassword.substring (6);
        try {
            digest = MessageDigest.getInstance ("MD5");
        } catch (final NoSuchAlgorithmException e) {
            throw new IllegalStateException ("Invalid algorithm");
        }
    } else {
        return false;
    }

    try {
        final byte [] data = Base64.decodeBase64 (base64.getBytes ("UTF-8"));
        final byte [] orig = new byte [size];
        System.arraycopy (data, 0, orig, 0, size);
        digest.reset ();
        digest.update (new String (password).getBytes ("UTF-8"));
        if (data.length > size) {
            digest.update (data, size, data.length - size);
        }
        return MessageDigest.isEqual (digest.digest (), orig);
    } catch (UnsupportedEncodingException e) {
        throw new IllegalStateException ("UTF-8 Unsupported");
    }
}

Function 2:
public static String hashStringMD5 (String string) throws NoSuchAlgorithmException {
    MessageDigest md = MessageDigest.getInstance ("MD5");
    md.update (string.getBytes ());
    byte byteData [] = md.digest ();
    StringBuffer sb = new StringBuffer ();
    for (int i = 0;
    i < byteData.length; i ++) {
        sb.append (Integer.toString ((byteData [i] & 0xff) + 0x100, 16).substring (1));
    }
    StringBuffer hexString = new StringBuffer ();
    for (int i = 0;
    i < byteData.length; i ++) {
        String hex = Integer.toHexString (0xff & byteData [i]);
        if (hex.length () == 1) hexString.append ('0');

        hexString.append (hex);
    }
    return hexString.toString ();
}
Functionality: Copy File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
private void displayDiffResults () throws IOException {
    File outFile = File.createTempFile ("diff", ".htm");
    outFile.deleteOnExit ();
    FileOutputStream outStream = new FileOutputStream (outFile);
    BufferedWriter out = new BufferedWriter (new OutputStreamWriter (outStream));
    out.write ("<html><head><title>LOC Differences</title>\n" + SCRIPT + "</head>\n" + "<body bgcolor='#ffffff'>\n" + "<div onMouseOver=\"window.defaultStatus='Metrics'\">\n");
    if (addedTable.length () > 0) {
        out.write ("<table border><tr><th>Files Added:</th>" + "<th>Add</th><th>Type</th></tr>");
        out.write (addedTable.toString ());
        out.write ("</table><br><br>");
    }
    if (modifiedTable.length () > 0) {
        out.write ("<table border><tr><th>Files Modified:</th>" + "<th>Base</th><th>Del</th><th>Mod</th><th>Add</th>" + "<th>Total</th><th>Type</th></tr>");
        out.write (modifiedTable.toString ());
        out.write ("</table><br><br>");
    }
    if (deletedTable.length () > 0) {
        out.write ("<table border><tr><th>Files Deleted:</th>" + "<th>Del</th><th>Type</th></tr>");
        out.write (deletedTable.toString ());
        out.write ("</table><br><br>");
    }
    out.write ("<table name=METRICS BORDER>\n");
    if (modifiedTable.length () > 0 || deletedTable.length () > 0) {
        out.write ("<tr><td>Base:&nbsp;</td><td>");
        out.write (Long.toString (base));
        out.write ("</td></tr>\n<tr><td>Deleted:&nbsp;</td><td>");
        out.write (Long.toString (deleted));
        out.write ("</td></tr>\n<tr><td>Modified:&nbsp;</td><td>");
        out.write (Long.toString (modified));
        out.write ("</td></tr>\n<tr><td>Added:&nbsp;</td><td>");
        out.write (Long.toString (added));
        out.write ("</td></tr>\n<tr><td>New & Changed:&nbsp;</td><td>");
        out.write (Long.toString (added + modified));
        out.write ("</td></tr>\n");
    }
    out.write ("<tr><td>Total:&nbsp;</td><td>");
    out.write (Long.toString (total));
    out.write ("</td></tr>\n</table></div>");
    redlinesOut.close ();
    out.flush ();
    InputStream redlines = new FileInputStream (redlinesTempFile);
    byte [] buffer = new byte [4096];
    int bytesRead;
    while ((bytesRead = redlines.read (buffer)) != - 1) outStream.write (buffer, 0, bytesRead);

    outStream.write ("</BODY></HTML>".getBytes ());
    outStream.close ();
    Browser.launch (outFile.toURL ().toString ());
}

Function 2:
public void render (ServiceContext serviceContext) throws Exception {
    if (serviceContext.getTemplateName () == null) throw new Exception ("no Template defined for service: " + serviceContext.getServiceInfo ().getRefName ());

    File f = new File (serviceContext.getTemplateName ());
    serviceContext.getResponse ().setContentLength ((int) f.length ());
    InputStream in = new FileInputStream (f);
    IOUtils.copy (in, serviceContext.getResponse ().getOutputStream (), 0, (int) f.length ());
    in.close ();
}
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:
public void setVariables (Properties varDef) throws Exception {
    sendMsg ("Setting  the variables ...");
    outJar.putNextEntry (new ZipEntry ("vars"));
    ObjectOutputStream objOut = new ObjectOutputStream (outJar);
    objOut.writeObject (varDef);
    objOut.flush ();
    outJar.closeEntry ();
}
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 writeJar (JarOutputStream out) throws IOException, Pack200Exception {
    String [] fileName = fileBands.getFileName ();
    int [] fileModtime = fileBands.getFileModtime ();
    long [] fileSize = fileBands.getFileSize ();
    byte [] [] fileBits = fileBands.getFileBits ();
    int classNum = 0;
    int numberOfFiles = header.getNumberOfFiles ();
    long archiveModtime = header.getArchiveModtime ();
    for (int i = 0;
    i < numberOfFiles; i ++) {
        String name = fileName [i];
        long modtime = 1000 * (archiveModtime + fileModtime [i]);
        boolean deflate = fileDeflate [i];
        JarEntry entry = new JarEntry (name);
        if (deflate) {
            entry.setMethod (ZipEntry.DEFLATED);
        } else {
            entry.setMethod (ZipEntry.STORED);
            CRC32 crc = new CRC32 ();
            if (fileIsClass [i]) {
                crc.update (classFilesContents [classNum]);
                entry.setSize (classFilesContents [classNum].length);
            } else {
                crc.update (fileBits [i]);
                entry.setSize (fileSize [i]);
            }
            entry.setCrc (crc.getValue ());
        }
        entry.setTime (modtime - TimeZone.getDefault ().getRawOffset ());
        out.putNextEntry (entry);
        if (fileIsClass [i]) {
            entry.setSize (classFilesContents [classNum].length);
            out.write (classFilesContents [classNum]);
            classNum ++;
        } else {
            entry.setSize (fileSize [i]);
            out.write (fileBits [i]);
        }
    }
}
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:
@Test
public void testCopy_inputStreamToOutputStream_nullIn () throws Exception {
    OutputStream out = new ByteArrayOutputStream ();
    try {
        IOUtils.copy ((InputStream) null, out);
        fail ();
    } catch (NullPointerException ex) {
    }
}
Functionality: Copy File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
static void copy (String src, String dest) throws IOException {
    File ifp = new File (src);
    File ofp = new File (dest);
    if (ifp.exists () == false) {
        throw new IOException ("file '" + src + "' does not exist");
    }
    FileInputStream fis = new FileInputStream (ifp);
    FileOutputStream fos = new FileOutputStream (ofp);
    byte [] b = new byte [1024];
    while (fis.read (b) > 0) fos.write (b);

    fis.close ();
    fos.close ();
}

Function 2:
private void sendFile (File file, HttpServletResponse response) throws IOException {
    response.setContentLength ((int) file.length ());
    InputStream inputStream = null;
    try {
        inputStream = new FileInputStream (file);
        IOUtils.copy (inputStream, response.getOutputStream ());
    } finally {
        IOUtils.closeQuietly (inputStream);
    }
}