primakov/ML4SE2023_Group4_Dataset.csv huggingface dataset:
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 run (IProgressMonitor runnerMonitor) throws CoreException {
    try {
        Map < String, File > projectFiles = new HashMap < String, File > ();
        IPath basePath = new Path ("/");
        for (File nextLocation : filesToZip) {
            projectFiles.putAll (getFilesToZip (nextLocation, basePath, fileFilter));
        }
        if (projectFiles.isEmpty ()) {
            PlatformActivator.logDebug ("Zip file (" + zipFileName + ") not created because there were no files to zip");
            return;
        }
        IPath resultsPath = PlatformActivator.getDefault ().getResultsPath ();
        File copyRoot = resultsPath.toFile ();
        copyRoot.mkdirs ();
        IPath zipFilePath = resultsPath.append (new Path (finalZip));
        String zipFileName = zipFilePath.toPortableString ();
        ZipOutputStream out = new ZipOutputStream (new FileOutputStream (zipFileName));
        try {
            out.setLevel (Deflater.DEFAULT_COMPRESSION);
            for (String filePath : projectFiles.keySet ()) {
                File nextFile = projectFiles.get (filePath);
                FileInputStream fin = new FileInputStream (nextFile);
                try {
                    out.putNextEntry (new ZipEntry (filePath));
                    try {
                        byte [] bin = new byte [4096];
                        int bread = fin.read (bin, 0, 4096);
                        while (bread != - 1) {
                            out.write (bin, 0, bread);
                            bread = fin.read (bin, 0, 4096);
                        }
                    } finally {
                        out.closeEntry ();
                    }
                } finally {
                    fin.close ();
                }
            }
        } finally {
            out.close ();
        }
    } catch (FileNotFoundException e) {
        Status error = new Status (Status.ERROR, PlatformActivator.PLUGIN_ID, Status.ERROR, e.getLocalizedMessage (), e);
        throw new CoreException (error);
    } catch (IOException e) {
        Status error = new Status (Status.ERROR, PlatformActivator.PLUGIN_ID, Status.ERROR, e.getLocalizedMessage (), e);
        throw new CoreException (error);
    }
}
Functionality: CRC32 File Checksum
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
public static long getCRC (String content) {
    if (content.length () == 0) return 0;

    final java.util.zip.CRC32 crc = new java.util.zip.CRC32 ();
    java.io.OutputStream crcOut = new java.io.OutputStream () {
        @Override
        public void write (int b) throws java.io.IOException {
            crc.update (b);
        }}

    ;
    try {
        new java.io.OutputStreamWriter (crcOut).write (content);
    } catch (java.io.IOException e) {
        throw new IllegalStateException ("Could not check CRC of message");
    }
    return crc.getValue ();
}

Function 2:
public static long checksum1 (File file) throws IOException {
    CRC32 crc = new CRC32 ();
    FileReader fr = new FileReader (file);
    int data;
    while ((data = fr.read ()) != - 1) {
        crc.update (data);
    }
    fr.close ();
    return crc.getValue ();
}
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 static < T extends ZipNode > void saveAll (OutputStream outputstream, Collection < T > list, ZipStreamFilter filter) throws Exception {
    ZipOutputStream zip_out = new ZipOutputStream (outputstream);
    try {
        ZipEntry entry = new ZipEntry (".info/info.properties");
        entry.setTime (0);
        zip_out.putNextEntry (entry);
        String info = "filter = " + filter.getClass ().getName () + "\n" + "count  = " + list.size () + "\n";
        zip_out.write (info.getBytes ());
        for (T object : list) {
            save (zip_out, object, filter);
        }
    } catch (Throwable ex) {
        ex.printStackTrace ();
    } finally {
        try {
            zip_out.close ();
        } catch (IOException e) {
        }
    }
}
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 zipFiles () throws ZipException, IOException {
    ZipOutputStream zipOuputStream = new ZipOutputStream (new FileOutputStream (zipFile));
    for (File sourceDir : sourceDirs) {
        File [] sourceFiles = sourceDir.listFiles (new SourceFileFilter ());
        if (sourceFiles != null) {
            for (File sourceFile : sourceFiles) {
                ZipEntry zipEntry = new ZipEntry (sourceFile.getName ());
                zipOuputStream.putNextEntry (zipEntry);
                if (logger.isInfoEnabled ()) {
                    logger.info ("Adding zip entry " + sourceFile.getAbsolutePath () + " to " + zipFile.getAbsolutePath ());
                }
                if (sourceFile.length () > BYTE_ARRAY_BUFF_SIZE) {
                    BufferedInputStream bis = new BufferedInputStream (new FileInputStream (sourceFile), BYTE_ARRAY_BUFF_SIZE);
                    byte [] buf = new byte [BYTE_ARRAY_BUFF_SIZE];
                    int b;
                    while ((b = bis.read (buf, 0, BYTE_ARRAY_BUFF_SIZE)) != - 1) {
                        zipOuputStream.write (buf, 0, b);
                    }
                    bis.close ();
                } else {
                    byte [] fileContents = FileUtil.getFileContentsAsByteArray (sourceFile);
                    zipOuputStream.write (fileContents);
                }
                zipOuputStream.closeEntry ();
            }
        }
    }
    zipOuputStream.close ();
}
Functionality: CRC32 File Checksum
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
static void writeZipEntry (final byte [] data, final ZipOutputStream out, final ZipEntry entry, final boolean isCopy) throws IOException {
    if (isCopy) {
        out.putNextEntry (entry);
        try {
            out.write (data);
        } finally {
            out.closeEntry ();
        }
    } else {
        final ZipEntry entryCopy = new ZipEntry (entry.getName ());
        entryCopy.setTime (entry.getTime ());
        entryCopy.setMethod (ZipOutputStream.STORED);
        entryCopy.setSize (data.length);
        entryCopy.setCompressedSize (data.length);
        final CRC32 crc = new CRC32 ();
        crc.update (data);
        entryCopy.setCrc (crc.getValue ());
        out.putNextEntry (entryCopy);
        try {
            out.write (data);
        } finally {
            out.closeEntry ();
        }
    }
}

Function 2:
public int calculateCRC () {
    CRC32 crc = new CRC32 ();
    crc.reset ();
    crc.update (getData (), 2, getData ().length - 2);
    return (short) (crc.getValue ());
}
Functionality: Zip Files
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
@Override
public void write (DataOutput dataOutput, byte [] object) throws IOException {
    ZipOutputStream zos = new ZipOutputStream (new DataOutputOutputStream (dataOutput));
    zos.setMethod (ZipOutputStream.DEFLATED);
    zos.putNextEntry (new ZipEntry ("a"));
    zos.write (object, 0, object.length);
    zos.finish ();
    zos.close ();
}

Function 2:
private void archiveDirectory (ZipOutputStream out, File dir, String path) throws IOException {
    byte [] buf = new byte [16384];
    File [] files = dir.listFiles ();
    if (files.length > 0) {
        for (int x = 0;
        x < files.length; x ++) {
            if (files [x].isFile ()) {
                FileInputStream in = new FileInputStream (files [x]);
                out.putNextEntry (new ZipEntry (path + files [x].getName ()));
                int len;
                while ((len = in.read (buf)) > 0) {
                    out.write (buf, 0, len);
                }
                out.closeEntry ();
                in.close ();
            } else {
                archiveDirectory (out, files [x], path + files [x].getName () + File.separator);
            }
        }
    } else {
        out.putNextEntry (new ZipEntry (path));
        out.closeEntry ();
    }
}
Functionality: Zip Files
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
private void ZipCode (NpsContext ctxt, ZipOutputStream out) throws Exception {
    String filename = "JOB" + GetId () + ".data";
    out.putNextEntry (new ZipEntry (filename));
    try {
        ZipWriter writer = new ZipWriter (out);
        writer.print (code);
    } finally {
        out.closeEntry ();
    }
}

Function 2:
@Override
protected void doGet (HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    ZipOutputStream zipout = new ZipOutputStream (resp.getOutputStream ());
    ZipOutputStream zipout2 = new ZipOutputStream (new FileOutputStream (new File ("c:/t.zip")));
    for (int i = 0;
    i < 200; i ++) {
        BufferedImage img = new BufferedImage (800 + i, 600 + i, BufferedImage.TYPE_INT_RGB);
        Graphics2D g = (Graphics2D) img.getGraphics ();
        g.setPaint (new GradientPaint (0, 0, Color.YELLOW, img.getWidth () - 1, img.getHeight () - 1, Color.BLUE, true));
        g.fillRect (0, 0, img.getWidth (), img.getHeight ());
        for (int t = 0;
        t < img.getHeight (); t += 10) {
            g.setColor (new Color (t + 1 * 100 + 1 * 10000));
            g.drawLine (0, t, img.getWidth (), t);
        }
        g.dispose ();
        ZipEntry entry = new ZipEntry ("hoge" + i + ".bmp");
        zipout.putNextEntry (entry);
        ImageIO.write (img, "bmp", zipout);
        ZipEntry entry2 = new ZipEntry ("hoge" + i + ".bmp");
        zipout2.putNextEntry (entry2);
        ImageIO.write (img, "bmp", zipout2);
    }
    zipout.close ();
    zipout2.close ();
}
Functionality: Copy File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
protected boolean doRequest (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String path = request.getPathInfo ();
    if (! path.startsWith (alias)) {
        throw new ServletException ("Path '" + path + "' does not start with registered alias '" + alias + "'");
    }
    String internal;
    if (alias.equals ("/")) {
        internal = name + path;
    } else {
        internal = name + path.substring (alias.length (), path.length ());
    }
    URL resource = httpContext.getResource (internal);
    if (resource == null) {
        return false;
    }
    String mimeType = servletContext.getMimeType (internal);
    if (mimeType != null) {
        response.setContentType (mimeType);
    }
    InputStream is = resource.openStream ();
    OutputStream os = response.getOutputStream ();
    IOUtils.copyAndClose (is, os);
    return true;
}

Function 2:
public CmsSetupTestResult execute (CmsSetupBean setupBean) {
    CmsSetupTestResult testResult = new CmsSetupTestResult (this);
    String basePath = setupBean.getWebAppRfsPath ();
    if (! basePath.endsWith (File.separator)) {
        basePath += File.separator;
    }
    File file1;
    Random rnd = new Random ();
    do {
        file1 = new File (basePath + "test" + rnd.nextInt (1000));
    } while (file1.exists ());
    boolean success = false;
    try {
        file1.createNewFile ();
        FileWriter fw = new FileWriter (file1);
        fw.write ("aA1");
        fw.close ();
        success = true;
        FileReader fr = new FileReader (file1);
        success = success && (fr.read () == 'a');
        success = success && (fr.read () == 'A');
        success = success && (fr.read () == '1');
        success = success && (fr.read () == - 1);
        fr.close ();
        success = file1.delete ();
        success = ! file1.exists ();
    } catch (Exception e) {
        success = false;
    }
    if (! success) {
        testResult.setRed ();
        testResult.setInfo ("OpenCms cannot be installed without read and write privileges for path " + basePath + "! Please check you are running your servlet container with the right user and privileges.");
        testResult.setHelp ("Not enough permissions to create/read/write a file");
        testResult.setResult (RESULT_FAILED);
    } else {
        testResult.setGreen ();
        testResult.setResult (RESULT_PASSED);
    }
    return testResult;
}
Functionality: Zip Files
Clone type: Type-3 (WT3/4)
Is clone: FALSE

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

Function 2:
void writeRawDataFile (RawDataFileImpl rawDataFile, int number) throws IOException, TransformerConfigurationException, SAXException {
    numOfScans = rawDataFile.getNumOfScans ();
    dataPointsOffsets = rawDataFile.getDataPointsOffsets ();
    dataPointsLengths = rawDataFile.getDataPointsLengths ();
    consolidatedDataPointsOffsets = new TreeMap < Integer, Long > ();
    logger.info ("Saving data points of: " + rawDataFile.getName ());
    String rawDataSavedName = "Raw data file #" + number + " " + rawDataFile.getName ();
    zipOutputStream.putNextEntry (new ZipEntry (rawDataSavedName + ".scans"));
    long newOffset = 0;
    byte buffer [] = new byte [1 << 20];
    RandomAccessFile dataPointsFile = rawDataFile.getDataPointsFile ();
    for (Integer storageID : dataPointsOffsets.keySet ()) {
        if (canceled) return;

        final long offset = dataPointsOffsets.get (storageID);
        dataPointsFile.seek (offset);
        final int bytes = dataPointsLengths.get (storageID) * 4 * 2;
        consolidatedDataPointsOffsets.put (storageID, newOffset);
        if (buffer.length < bytes) {
            buffer = new byte [bytes * 2];
        }
        dataPointsFile.read (buffer, 0, bytes);
        zipOutputStream.write (buffer, 0, bytes);
        newOffset += bytes;
        progress = 0.9 * ((double) offset / dataPointsFile.length ());
    }
    if (canceled) return;

    logger.info ("Saving raw data description of: " + rawDataFile.getName ());
    zipOutputStream.putNextEntry (new ZipEntry (rawDataSavedName + ".xml"));
    OutputStream finalStream = zipOutputStream;
    StreamResult streamResult = new StreamResult (finalStream);
    SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance ();
    TransformerHandler hd = tf.newTransformerHandler ();
    Transformer serializer = hd.getTransformer ();
    serializer.setOutputProperty (OutputKeys.INDENT, "yes");
    serializer.setOutputProperty (OutputKeys.ENCODING, "UTF-8");
    hd.setResult (streamResult);
    hd.startDocument ();
    saveRawDataInformation (rawDataFile, hd);
    hd.endDocument ();
}
Functionality: Copy File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
private void loadMap () {
    final String wordList = "vietwordlist.txt";
    try {
        File dataFile = new File (supportDir, wordList);
        if (! dataFile.exists ()) {
            final ReadableByteChannel input = Channels.newChannel (ClassLoader.getSystemResourceAsStream ("dict/" + dataFile.getName ()));
            final FileChannel output = new FileOutputStream (dataFile).getChannel ();
            output.transferFrom (input, 0, 1000000L);
            input.close ();
            output.close ();
        }
        long fileLastModified = dataFile.lastModified ();
        if (map == null) {
            map = new HashMap ();
        } else {
            if (fileLastModified <= mapLastModified) {
                return;
            }
            map.clear ();
        }
        mapLastModified = fileLastModified;
        BufferedReader bs = new BufferedReader (new InputStreamReader (new FileInputStream (dataFile), "UTF-8"));
        String accented;
        while ((accented = bs.readLine ()) != null) {
            String plain = VietUtilities.stripDiacritics (accented);
            map.put (plain.toLowerCase (), accented);
        }
        bs.close ();
    } catch (IOException e) {
        map = null;
        e.printStackTrace ();
        JOptionPane.showMessageDialog (this, myResources.getString ("Cannot_find_\"") + wordList + myResources.getString ("\"_in\n") + supportDir.toString (), VietPad.APP_NAME, JOptionPane.ERROR_MESSAGE);
    }
}

Function 2:
private void copyFile (File sourcefile, File targetfile) {
    BufferedInputStream in = null;
    BufferedOutputStream out = null;
    try {
        in = new BufferedInputStream (new FileInputStream (sourcefile));
        out = new BufferedOutputStream (new FileOutputStream (targetfile));
        byte [] buffer = new byte [4096];
        int bytesread = 0;
        while ((bytesread = in.read (buffer)) >= 0) {
            out.write (buffer, 0, bytesread);
        }
    } catch (IOException e) {
        e.printStackTrace ();
    } finally {
        try {
            if (in != null) {
                in.close ();
            }
            if (out != null) {
                out.close ();
            }
        } catch (IOException e) {
            e.printStackTrace ();
        }
    }
}
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 writeDynData (final int time_s) throws IOException {
    this.zos.putNextEntry (new ZipEntry ("step." + time_s + ".bin"));
    this.outFile = new DataOutputStream (this.zos);
    this.buf.position (0);
    this.outFile.writeDouble (time_s);
    this.quad.writeDynData (null, this.buf);
    this.outFile.writeInt (this.buf.position ());
    this.outFile.write (this.buf.array (), 0, this.buf.position ());
    this.zos.closeEntry ();
}
Functionality: Zip Files
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
public static int save () {
    try {
        String filename = "tyrant.sav";
        FileDialog fd = new FileDialog (new Frame (), "Save Game", FileDialog.SAVE);
        fd.setFile (filename);
        fd.setVisible (true);
        if (fd.getFile () != null) {
            filename = fd.getDirectory () + fd.getFile ();
        } else {
            return 0;
        }
        FileOutputStream f = new FileOutputStream (filename);
        ZipOutputStream z = new ZipOutputStream (f);
        z.putNextEntry (new ZipEntry ("data.xml"));
        if (! save (new ObjectOutputStream (z))) {
            throw new Error ("Save game failed");
        }
        Game.message ("Game saved - " + filename);
        z.closeEntry ();
        z.close ();
        if (saveHasBeenCalledAlready) Game.message ("Please note that you can only restore the game with the same version of Tyrant (v" + VERSION + ").");

        saveHasBeenCalledAlready = false;
    } catch (Exception e) {
        Game.message ("Error while saving: " + e.toString ());
        if (QuestApp.isapplet) {
            Game.message ("This may be due to your browser security restrictions");
            Game.message ("If so, run the web start or downloaded application version instead");
        }
        System.out.println (e);
        return - 1;
    }
    return 1;
}

Function 2:
private void writeEntry (byte [] data, String name, ZipOutputStream outStream) throws IOException {
    ZipEntry entry = new ZipEntry (name);
    entry.setSize (data.length);
    entry.setTime (System.currentTimeMillis ());
    if (outStream != null) {
        outStream.putNextEntry (entry);
        outStream.write (data);
        outStream.closeEntry ();
    }
}