primakov/ML4SE2023_Group4_Dataset.csv huggingface dataset:
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 zipDirectoryRecursive (File path, File zipFileName, String excludeRegEx, boolean relative, boolean compress) {
    ArrayList < File > filesToZip = new ArrayList < File > ();
    if (path.exists ()) {
        File [] files = path.listFiles ();
        for (int i = 0;
        i < files.length; i ++) {
            if (files [i].isDirectory ()) {
                FileTools.listFilesRecursive (files [i], filesToZip);
            } else {
                filesToZip.add (files [i]);
            }
        }
    }
    try {
        byte [] buffer = new byte [18024];
        ZipOutputStream out = new ZipOutputStream (new FileOutputStream (zipFileName));
        if (! compress) {
            out.setLevel (Deflater.NO_COMPRESSION);
        } else {
            out.setLevel (Deflater.DEFAULT_COMPRESSION);
        }
        for (int i = 0;
        i < filesToZip.size (); i ++) {
            if (excludeRegEx == null || ! filesToZip.get (i).getName ().contains (excludeRegEx)) {
                FileInputStream in = new FileInputStream (filesToZip.get (i));
                String filePath = filesToZip.get (i).getPath ();
                if (relative) {
                    filePath = filePath.replaceFirst (path.getAbsolutePath () + File.separator, "");
                }
                System.out.println ("Deflating: " + filePath);
                out.putNextEntry (new ZipEntry (filePath));
                int len;
                while ((len = in.read (buffer)) > 0) {
                    out.write (buffer, 0, len);
                }
                out.closeEntry ();
                in.close ();
            }
        }
        out.close ();
    } catch (IllegalArgumentException iae) {
        iae.printStackTrace ();
        return (false);
    } catch (FileNotFoundException fnfe) {
        fnfe.printStackTrace ();
        return (false);
    } catch (IOException ioe) {
        ioe.printStackTrace ();
        return (false);
    }
    return (true);
}
Functionality: CRC32 File Checksum
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
public static long getDummyCRC (long count) throws IOException {
    CRC32 crc = new CRC32 ();
    byte [] data = new byte [1024];
    int done = 0;
    while (done < count) {
        int tbw = (int) Math.min (count - done, data.length);
        crc.update (data, 0, tbw);
        done += tbw;
    }
    return crc.getValue ();
}

Function 2:
public void decode (File input) throws DecoderException {
    try {
        YEncFile yencFile = new YEncFile (input);
        StringBuffer outputName = new StringBuffer (outputDirName);
        outputName.append (File.separator);
        outputName.append (yencFile.getHeader ().getName ());
        RandomAccessFile output = new RandomAccessFile (outputName.toString (), "rw");
        long pos = yencFile.getDataBegin ();
        yencFile.getInput ().seek (pos);
        ByteArrayOutputStream baos = new ByteArrayOutputStream ();
        while (pos < yencFile.getDataEnd ()) {
            baos.write (yencFile.getInput ().read ());
            pos ++;
        }
        byte [] buff = decoder.decode (baos.toByteArray ());
        output.write (buff);
        output.close ();
        CRC32 crc32 = new CRC32 ();
        crc32.update (buff);
        if (! yencFile.getTrailer ().getCrc32 ().equals (Long.toHexString (crc32.getValue ()).toUpperCase ())) throw new DecoderException ("Error in CRC32 check.");

    } catch (YEncException ye) {
        throw new DecoderException ("Input file is not a YEnc file or contains error : " + ye.getMessage ());
    } catch (FileNotFoundException fnfe) {
        throw new DecoderException ("Enable to create output file : " + fnfe.getMessage ());
    } catch (IOException ioe) {
        throw new DecoderException ("Enable to read input file : " + ioe.getMessage ());
    }
}
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:
public String getID () {
    CRC32 checksum = new CRC32 ();
    int i = 0;
    checksum.reset ();
    while ((i < data.length ()) && (i < 5000)) {
        checksum.update ((int) data.charAt (i));
        i ++;
    }
    return (Long.toHexString (checksum.getValue ()) + Integer.toHexString (data.hashCode ()));
}
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:
protected void renderResource (final HttpServletRequest request, final HttpServletResponse response, final InputStream is) throws IOException {
    try {
        IOUtils.copy (is, response.getOutputStream ());
    } finally {
        IOUtils.closeQuietly (is);
    }
}
Functionality: Zip Files
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
private void backupDiskFile (ZipOutputStream out, String fileName, DiskFile file) throws SQLException, IOException {
    Database db = session.getDatabase ();
    fileName = FileUtils.getFileName (fileName);
    out.putNextEntry (new ZipEntry (fileName));
    int pos = - 1;
    int max = file.getReadCount ();
    while (true) {
        pos = file.copyDirect (pos, out);
        if (pos < 0) {
            break;
        }
        db.setProgress (DatabaseEventListener.STATE_BACKUP_FILE, fileName, pos, max);
    }
    out.closeEntry ();
}

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 ++) {
        String fileName = files [i];
        File file = en.uploadPath (virtualWiki, fileName);
        if (file.isDirectory ()) {
            continue;
        }
        progress = Math.min (progressStart + (int) ((double) i * (double) progressLength / files.length), 99);
        logger.fine ("Adding uploaded file " + fileName);
        ZipEntry entry = new ZipEntry (safename (fileName));
        try {
            FileInputStream in = new FileInputStream (file);
            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.log (Level.WARNING, "Could not open file!", e);
        } catch (IOException e) {
            logger.log (Level.WARNING, "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 BufferedWriter createOutputStream (String inFile, String outFile) throws IOException {
    int k_blockSize = 1024;
    int byteCount;
    char [] buf = new char [k_blockSize];
    File ofp = new File (outFile);
    ZipOutputStream zos = new ZipOutputStream (new FileOutputStream (ofp));
    zos.setMethod (ZipOutputStream.DEFLATED);
    OutputStreamWriter osw = new OutputStreamWriter (zos, "ISO-8859-1");
    BufferedWriter bw = new BufferedWriter (osw);
    ZipEntry zot = null;
    File ifp = new File (inFile);
    ZipInputStream zis = new ZipInputStream (new FileInputStream (ifp));
    InputStreamReader isr = new InputStreamReader (zis, "ISO-8859-1");
    BufferedReader br = new BufferedReader (isr);
    ZipEntry zit = null;
    while ((zit = zis.getNextEntry ()) != null) {
        if (zit.getName ().equals ("content.xml")) {
            continue;
        }
        zot = new ZipEntry (zit.getName ());
        zos.putNextEntry (zot);
        while ((byteCount = br.read (buf, 0, k_blockSize)) >= 0) bw.write (buf, 0, byteCount);

        bw.flush ();
        zos.closeEntry ();
    }
    zos.putNextEntry (new ZipEntry ("content.xml"));
    bw.flush ();
    osw = new OutputStreamWriter (zos, "UTF8");
    bw = new BufferedWriter (osw);
    return bw;
}

Function 2:
private void writeManifestEntry (File f, JarOutputStream out) {
    byte [] buffer = new byte [BUFFERSIZE];
    int bytes_read;
    try {
        BufferedInputStream in = new BufferedInputStream (new FileInputStream (f), BUFFERSIZE);
        String en = "META-INF" + "/" + "MANIFEST.MF";
        out.putNextEntry (new ZipEntry (en));
        while ((bytes_read = in.read (buffer)) != - 1) {
            out.write (buffer, 0, bytes_read);
        }
        in.close ();
        out.closeEntry ();
    } catch (Exception e) {
        System.out.println ("[writeManifestEntry(), JarWriter] ERROR\n" + e);
    }
}
Functionality: Copy File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
boolean copyFileStructure (File oldFile, File newFile) {
    if (oldFile == null || newFile == null) return false;

    File searchFile = newFile;
    do {
        if (oldFile.equals (searchFile)) return false;

        searchFile = searchFile.getParentFile ();
    } while (searchFile != null);
    if (oldFile.isDirectory ()) {
        if (progressDialog != null) {
            progressDialog.setDetailFile (oldFile, ProgressDialog.COPY);
        }
        if (simulateOnly) {
        } else {
            if (! newFile.mkdirs ()) return false;

        }
        File [] subFiles = oldFile.listFiles ();
        if (subFiles != null) {
            if (progressDialog != null) {
                progressDialog.addWorkUnits (subFiles.length);
            }
            for (int i = 0;
            i < subFiles.length; i ++) {
                File oldSubFile = subFiles [i];
                File newSubFile = new File (newFile, oldSubFile.getName ());
                if (! copyFileStructure (oldSubFile, newSubFile)) return false;

                if (progressDialog != null) {
                    progressDialog.addProgress (1);
                    if (progressDialog.isCancelled ()) return false;

                }
            }
        }
    } else {
        if (simulateOnly) {
        } else {
            FileReader in = null;
            FileWriter out = null;
            try {
                in = new FileReader (oldFile);
                out = new FileWriter (newFile);
                int count;
                while ((count = in.read ()) != - 1) out.write (count);

            } catch (FileNotFoundException e) {
                return false;
            } catch (IOException e) {
                return false;
            } finally {
                try {
                    if (in != null) in.close ();

                    if (out != null) out.close ();

                } catch (IOException e) {
                    return false;
                }
            }
        }
    }
    return true;
}

Function 2:
public static boolean encodeFileToFile (String infile, String outfile) {
    boolean success = false;
    java.io.InputStream in = null;
    java.io.OutputStream out = null;
    try {
        in = new Base64.InputStream (new java.io.BufferedInputStream (new java.io.FileInputStream (infile)), Base64.ENCODE);
        out = new java.io.BufferedOutputStream (new java.io.FileOutputStream (outfile));
        byte [] buffer = new byte [65536];
        int read = - 1;
        while ((read = in.read (buffer)) >= 0) {
            out.write (buffer, 0, read);
        }
        success = true;
    } catch (java.io.IOException exc) {
        exc.printStackTrace ();
    } finally {
        try {
            in.close ();
        } catch (Exception exc) {
        }
        try {
            out.close ();
        } catch (Exception exc) {
        }
    }
    return success;
}
Functionality: Zip Files
Clone type: Type-3 (WT3/4)
Is clone: FALSE

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

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

Function 2:
protected void addFileToJar (JarOutputStream jStream, File inputFile, String logicalFilename) throws BuildException {
    FileInputStream iStream = null;
    try {
        if (! addedfiles.contains (logicalFilename)) {
            iStream = new FileInputStream (inputFile);
            ZipEntry zipEntry = new ZipEntry (logicalFilename.replace ('\\', '/'));
            jStream.putNextEntry (zipEntry);
            byte [] byteBuffer = new byte [2 * DEFAULT_BUFFER_SIZE];
            int count = 0;
            do {
                jStream.write (byteBuffer, 0, count);
                count = iStream.read (byteBuffer, 0, byteBuffer.length);
            } while (count != - 1);
            addedfiles.add (logicalFilename);
        }
    } catch (IOException ioe) {
        log ("WARNING: IOException while adding entry " + logicalFilename + " to jarfile from " + inputFile.getPath () + " " + ioe.getClass ().getName () + "-" + ioe.getMessage (), Project.MSG_WARN);
    } finally {
        if (iStream != null) {
            try {
                iStream.close ();
            } catch (IOException closeException) {
            }
        }
    }
}
Functionality: Copy File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
private boolean copyFile (File _file1, File _file2) {
    FileInputStream fis;
    FileOutputStream fos;
    try {
        fis = new FileInputStream (_file1);
        fos = new FileOutputStream (_file2);
        FileChannel canalFuente = fis.getChannel ();
        canalFuente.transferTo (0, canalFuente.size (), fos.getChannel ());
        fis.close ();
        fos.close ();
        return true;
    } catch (FileNotFoundException e) {
    } catch (IOException e) {
    }
    return false;
}

Function 2:
public static void entering (String [] args) throws IOException, CodeCheckException {
    ClassWriter writer = new ClassWriter ();
    writer.readClass (new BufferedInputStream (new FileInputStream (args [0])));
    int constantIndex = writer.getStringConstantIndex ("Entering ");
    int fieldRefIndex = writer.getReferenceIndex (ClassWriter.CONSTANT_Fieldref, "java/lang/System", "out", "Ljava/io/PrintStream;");
    int printlnRefIndex = writer.getReferenceIndex (ClassWriter.CONSTANT_Methodref, "java/io/PrintStream", "println", "(Ljava/lang/String;)V");
    int printRefIndex = writer.getReferenceIndex (ClassWriter.CONSTANT_Methodref, "java/io/PrintStream", "print", "(Ljava/lang/String;)V");
    for (Iterator i = writer.getMethods ().iterator ();
    i.hasNext ();) {
        MethodInfo method = (MethodInfo) i.next ();
        if (method.getName ().equals ("readConstant")) continue;

        CodeAttribute attribute = method.getCodeAttribute ();
        ArrayList instructions = new ArrayList (10);
        byte [] operands;
        operands = new byte [2];
        NetByte.intToPair (fieldRefIndex, operands, 0);
        instructions.add (new Instruction (OpCode.getOpCodeByMnemonic ("getstatic"), 0, operands, false));
        instructions.add (new Instruction (OpCode.getOpCodeByMnemonic ("dup"), 0, null, false));
        instructions.add (Instruction.appropriateLdc (constantIndex, false));
        operands = new byte [2];
        NetByte.intToPair (printRefIndex, operands, 0);
        instructions.add (new Instruction (OpCode.getOpCodeByMnemonic ("invokevirtual"), 0, operands, false));
        instructions.add (Instruction.appropriateLdc (writer.getStringConstantIndex (method.getName ()), false));
        operands = new byte [2];
        NetByte.intToPair (printlnRefIndex, operands, 0);
        instructions.add (new Instruction (OpCode.getOpCodeByMnemonic ("invokevirtual"), 0, operands, false));
        attribute.insertInstructions (0, 0, instructions);
        attribute.codeCheck ();
    }
    BufferedOutputStream outStream = new BufferedOutputStream (new FileOutputStream (args [1]));
    writer.writeClass (outStream);
    outStream.close ();
}
Functionality: Zip Files
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
public BufferedWriter createOutputStream (String inFile, String outFile) throws IOException {
    int k_blockSize = 1024;
    int byteCount;
    char [] buf = new char [k_blockSize];
    File ofp = new File (outFile);
    ZipOutputStream zos = new ZipOutputStream (new FileOutputStream (ofp));
    zos.setMethod (ZipOutputStream.DEFLATED);
    OutputStreamWriter osw = new OutputStreamWriter (zos, "ISO-8859-1");
    BufferedWriter bw = new BufferedWriter (osw);
    ZipEntry zot = null;
    File ifp = new File (inFile);
    ZipInputStream zis = new ZipInputStream (new FileInputStream (ifp));
    InputStreamReader isr = new InputStreamReader (zis, "ISO-8859-1");
    BufferedReader br = new BufferedReader (isr);
    ZipEntry zit = null;
    while ((zit = zis.getNextEntry ()) != null) {
        if (zit.getName ().equals ("content.xml")) {
            continue;
        }
        zot = new ZipEntry (zit.getName ());
        zos.putNextEntry (zot);
        while ((byteCount = br.read (buf, 0, k_blockSize)) >= 0) bw.write (buf, 0, byteCount);

        bw.flush ();
        zos.closeEntry ();
    }
    zos.putNextEntry (new ZipEntry ("content.xml"));
    bw.flush ();
    osw = new OutputStreamWriter (zos, "UTF8");
    bw = new BufferedWriter (osw);
    return bw;
}

Function 2:
private void writeFileToZip (ZipOutputStream out, String sourceFilename, String vPath) throws IOException {
    FileInputStream in = new FileInputStream (sourceFilename);
    out.putNextEntry (new ZipEntry (vPath));
    int len;
    byte [] buf = new byte [1024];
    while ((len = in.read (buf)) > 0) {
        out.write (buf, 0, len);
    }
    out.closeEntry ();
    in.close ();
}
Functionality: Zip Files
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
public BufferedWriter createOutputStream (String inFile, String outFile) throws IOException {
    int k_blockSize = 1024;
    int byteCount;
    char [] buf = new char [k_blockSize];
    File ofp = new File (outFile);
    ZipOutputStream zos = new ZipOutputStream (new FileOutputStream (ofp));
    zos.setMethod (ZipOutputStream.DEFLATED);
    OutputStreamWriter osw = new OutputStreamWriter (zos, "ISO-8859-1");
    BufferedWriter bw = new BufferedWriter (osw);
    ZipEntry zot = null;
    File ifp = new File (inFile);
    ZipInputStream zis = new ZipInputStream (new FileInputStream (ifp));
    InputStreamReader isr = new InputStreamReader (zis, "ISO-8859-1");
    BufferedReader br = new BufferedReader (isr);
    ZipEntry zit = null;
    while ((zit = zis.getNextEntry ()) != null) {
        if (zit.getName ().equals ("content.xml")) {
            continue;
        }
        zot = new ZipEntry (zit.getName ());
        zos.putNextEntry (zot);
        while ((byteCount = br.read (buf, 0, k_blockSize)) >= 0) bw.write (buf, 0, byteCount);

        bw.flush ();
        zos.closeEntry ();
    }
    zos.putNextEntry (new ZipEntry ("content.xml"));
    bw.flush ();
    osw = new OutputStreamWriter (zos, "UTF8");
    bw = new BufferedWriter (osw);
    return bw;
}

Function 2:
public OCFContainerWriter (OutputStream out, String mime) throws IOException {
    zip = new ZipOutputStream (out);
    try {
        byte [] bytes = mime.getBytes ("UTF-8");
        ZipEntry mimetype = new ZipEntry ("mimetype");
        mimetype.setMethod (ZipOutputStream.STORED);
        mimetype.setSize (bytes.length);
        mimetype.setCompressedSize (bytes.length);
        CRC32 crc = new CRC32 ();
        crc.update (bytes);
        mimetype.setCrc (crc.getValue ());
        zip.putNextEntry (mimetype);
        zip.write (bytes);
        zip.closeEntry ();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace ();
    }
}
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:
public static byte [] zipFiles (Map < String, byte [] > files) throws IOException {
    ByteArrayOutputStream dest = new ByteArrayOutputStream ();
    ZipOutputStream out = new ZipOutputStream (new BufferedOutputStream (dest));
    Iterator < Entry < String, byte [] > > itr = files.entrySet ().iterator ();
    while (itr.hasNext ()) {
        Entry < String, byte [] > entry = itr.next ();
        ZipEntry zipEntry = new ZipEntry (entry.getKey ());
        out.putNextEntry (zipEntry);
        IOUtils.write (entry.getValue (), out);
    }
    out.close ();
    byte [] outBytes = dest.toByteArray ();
    dest.close ();
    return outBytes;
}