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

Function 1:
public MotixFileItem (final InputStream is, final String name, final String contentType, final int index) throws IOException {
    this.name = name;
    this.contentType = contentType;
    this.index = index;
    this.extension = FilenameUtils.getExtension (this.name);
    this.isImage = ImageUtils.isImage (name);
    ArrayInputStream isAux = null;
    final ByteArrayOutputStream out = new ByteArrayOutputStream ();
    try {
        IOUtils.copy (is, out);
        isAux = new ArrayInputStream (out.toByteArray ());
        if (this.isImage) {
            this.bufferedImage = imaging.read (isAux);
        }
    } finally {
        IOUtils.closeQuietly (out);
        IOUtils.closeQuietly (isAux);
    }
    this.inputStream = new ArrayInputStream (out.toByteArray ());
}

Function 2:
public static void copyFiles (String strPath, String dstPath) throws IOException {
    File src = new File (strPath);
    File dest = new File (dstPath);
    if (src.isDirectory ()) {
        dest.mkdirs ();
        String list [] = src.list ();
        for (int i = 0;
        i < list.length; i ++) {
            if (list [i].lastIndexOf (SVN) != - 1) {
                if (! SVN.equalsIgnoreCase (list [i].substring (list [i].length () - 4, list [i].length ()))) {
                    String dest1 = dest.getAbsolutePath () + "\\" + list [i];
                    String src1 = src.getAbsolutePath () + "\\" + list [i];
                    copyFiles (src1, dest1);
                }
            } else {
                String dest1 = dest.getAbsolutePath () + "\\" + list [i];
                String src1 = src.getAbsolutePath () + "\\" + list [i];
                copyFiles (src1, dest1);
            }
        }
    } else {
        FileInputStream fin = new FileInputStream (src);
        FileOutputStream fout = new FileOutputStream (dest);
        int c;
        while ((c = fin.read ()) >= 0) fout.write (c);

        fin.close ();
        fout.close ();
    }
}
Functionality: CRC32 File Checksum
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
public Thread transmitThread (final Socket s, final CountDownLatch abortLatch) {
    final Thread theThread = new Thread () {
        @Override
        public void run () {
            final Random r = new Random ();
            final Counter counter = new Counter ("TRANSMIT", plotter);
            counter.start ();
            try {
                final DataOutputStream dos = new DataOutputStream (new BufferedOutputStream (s.getOutputStream ()));
                while (! Thread.interrupted ()) {
                    if (! running.get ()) {
                        Thread.sleep (1000);
                        continue;
                    }
                    final int packetSize = r.nextInt (8192) + 2048;
                    final byte [] packet = new byte [packetSize];
                    r.nextBytes (packet);
                    final CRC32 crc = new CRC32 ();
                    crc.update (packet);
                    dos.writeInt (packetSize);
                    counter.addBytes (INTEGER_BYTES);
                    dos.write (packet);
                    counter.addBytes (packetSize);
                    dos.writeLong (crc.getValue ());
                    counter.addBytes (CRC_BYTES);
                    dos.flush ();
                }
            } catch (InterruptedException e) {
                System.out.println ("Transmitter thread interrupted!");
            } catch (Exception e) {
                System.err.println ("Unexpected error in transmitter thread: " + e.getMessage ());
            } finally {
                abortLatch.countDown ();
                counter.interrupt ();
            }
        }}

    ;
    return theThread;
}

Function 2:
private static String getUnicodeStringIfOriginalMatches (AbstractUnicodeExtraField f, byte [] orig) {
    if (f != null) {
        CRC32 crc32 = new CRC32 ();
        crc32.update (orig);
        long origCRC32 = crc32.getValue ();
        if (origCRC32 == f.getNameCRC32 ()) {
            try {
                return ZipEncodingHelper.UTF8_ZIP_ENCODING.decode (f.getUnicodeName ());
            } catch (IOException ex) {
                return null;
            }
        }
    }
    return null;
}
Functionality: Copy File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public static InputStream gunzip (final InputStream inputStream) throws IOException {
    Assert.notNull (inputStream, "inputStream");
    GZIPInputStream gzipInputStream = new GZIPInputStream (inputStream);
    InputOutputStream inputOutputStream = new InputOutputStream ();
    IOUtils.copy (gzipInputStream, inputOutputStream);
    return inputOutputStream.getInputStream ();
}

Function 2:
public void writeConfigurationFile () throws IOException, ComponentException {
    SystemConfig config = parent.getParentSystem ().getConfiguration ();
    File original = config.getLocation ();
    File backup = new File (original.getParentFile (), original.getName () + "." + System.currentTimeMillis ());
    FileInputStream in = new FileInputStream (original);
    FileOutputStream out = new FileOutputStream (backup);
    byte [] buffer = new byte [2048];
    try {
        int bytesread = 0;
        while ((bytesread = in.read (buffer)) > 0) {
            out.write (buffer, 0, bytesread);
        }
    } catch (IOException e) {
        logger.warn ("Failed to copy backup of configuration file");
        throw e;
    } finally {
        in.close ();
        out.close ();
    }
    FileWriter replace = new FileWriter (original);
    replace.write (config.toFileFormat ());
    replace.close ();
    logger.info ("Re-wrote configuration file " + original.getPath ());
}
Functionality: Copy File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public SWORDEntry ingestDepost (final DepositCollection pDeposit, final ServiceDocument pServiceDocument) throws SWORDException {
    try {
        ZipFileAccess tZipFile = new ZipFileAccess (super.getTempDir ());
        LOG.debug ("copying file");
        String tZipTempFileName = super.getTempDir () + "uploaded-file.tmp";
        IOUtils.copy (pDeposit.getFile (), new FileOutputStream (tZipTempFileName));
        Datastream tDatastream = new LocalDatastream (super.getGenericFileName (pDeposit), this.getContentType (), tZipTempFileName);
        _datastreamList.add (tDatastream);
        _datastreamList.addAll (tZipFile.getFiles (tZipTempFileName));
        int i = 0;
        boolean found = false;
        for (i = 0; i < _datastreamList.size (); i ++) {
            if (_datastreamList.get (i).getId ().equalsIgnoreCase ("mets")) {
                found = true;
                break;
            }
        }
        if (found) {
            SAXBuilder tBuilder = new SAXBuilder ();
            _mets = new METSObject (tBuilder.build (((LocalDatastream) _datastreamList.get (i)).getPath ()));
            LocalDatastream tLocalMETSDS = (LocalDatastream) _datastreamList.remove (i);
            new File (tLocalMETSDS.getPath ()).delete ();
            _datastreamList.add (_mets.getMETSDs ());
            _datastreamList.addAll (_mets.getMetadataDatastreams ());
        } else {
            throw new SWORDException ("Couldn't find a METS document in the zip file, ensure it is named mets.xml or METS.xml");
        }
        SWORDEntry tEntry = super.ingestDepost (pDeposit, pServiceDocument);
        tZipFile.removeLocalFiles ();
        return tEntry;
    } catch (IOException tIOExcpt) {
        String tMessage = "Couldn't retrieve METS from deposit: " + tIOExcpt.toString ();
        LOG.error (tMessage);
        tIOExcpt.printStackTrace ();
        throw new SWORDException (tMessage, tIOExcpt);
    } catch (JDOMException tJDOMExcpt) {
        String tMessage = "Couldn't build METS from deposit: " + tJDOMExcpt.toString ();
        LOG.error (tMessage);
        tJDOMExcpt.printStackTrace ();
        throw new SWORDException (tMessage, tJDOMExcpt);
    }
}

Function 2:
public void testReadPerMemberSixSmall () throws IOException {
    GZIPMembersInputStream gzin = new GZIPMembersInputStream (new ByteArrayInputStream (sixsmall_gz));
    gzin.setEofEachMember (true);
    for (int i = 0;
    i < 3; i ++) {
        int count2 = IOUtils.copy (gzin, new NullOutputStream ());
        assertEquals ("wrong 1-byte member count", 1, count2);
        gzin.nextMember ();
        int count3 = IOUtils.copy (gzin, new NullOutputStream ());
        assertEquals ("wrong 5-byte member count", 5, count3);
        gzin.nextMember ();
    }
    int countEnd = IOUtils.copy (gzin, new NullOutputStream ());
    assertEquals ("wrong eof count", 0, countEnd);
}
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:
private void writeEntry (File file, ZipOutputStream output, File oya) throws IOException {
    BufferedInputStream input = new BufferedInputStream (new FileInputStream (file));
    String fn = extractRelativeZipPath (file.getAbsolutePath (), oya.getAbsolutePath ());
    ZipEntry entry = new ZipEntry (this.convertZipEntrySeparator (fn));
    output.putNextEntry (entry);
    int b;
    while ((b = input.read ()) != - 1) {
        output.write (b);
    }
    input.close ();
    output.closeEntry ();
}
Functionality: Copy File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
private static void readAndRewrite (File inFile, File outFile) throws IOException {
    ImageInputStream iis = ImageIO.createImageInputStream (new BufferedInputStream (new FileInputStream (inFile)));
    DcmParser dcmParser = DcmParserFactory.getInstance ().newDcmParser (iis);
    Dataset ds = DcmObjectFactory.getInstance ().newDataset ();
    dcmParser.setDcmHandler (ds.getDcmHandler ());
    dcmParser.parseDcmFile (null, Tags.PixelData);
    PixelDataReader pdReader = pdFact.newReader (ds, iis, dcmParser.getDcmDecodeParam ().byteOrder, dcmParser.getReadVR ());
    System.out.println ("reading " + inFile + "...");
    pdReader.readPixelData (false);
    ImageOutputStream out = ImageIO.createImageOutputStream (new BufferedOutputStream (new FileOutputStream (outFile)));
    DcmEncodeParam dcmEncParam = DcmEncodeParam.IVR_LE;
    ds.writeDataset (out, dcmEncParam);
    ds.writeHeader (out, dcmEncParam, Tags.PixelData, dcmParser.getReadVR (), dcmParser.getReadLength ());
    System.out.println ("writing " + outFile + "...");
    PixelDataWriter pdWriter = pdFact.newWriter (pdReader.getPixelDataArray (), false, ds, out, dcmParser.getDcmDecodeParam ().byteOrder, dcmParser.getReadVR ());
    pdWriter.writePixelData ();
    out.flush ();
    out.close ();
    System.out.println ("done!");
}

Function 2:
public void putFile (CompoundName file, FileInputStream fileInput) throws IOException {
    File fullDir = new File (REMOTE_BASE_DIR.getCanonicalPath ());
    for (int i = 0;
    i < file.size () - 1; i ++) fullDir = new File (fullDir, file.get (i));

    fullDir.mkdirs ();
    File outputFile = new File (fullDir, file.get (file.size () - 1));
    FileOutputStream outStream = new FileOutputStream (outputFile);
    for (int byteIn = fileInput.read ();
    byteIn != - 1; byteIn = fileInput.read ()) outStream.write (byteIn);

    fileInput.close ();
    outStream.close ();
}
Functionality: CRC32 File Checksum
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
public static int getCrc32asInt (byte [] in) {
    if (in == null || in.length == 0) return - 1;

    CRC32 crc = new CRC32 ();
    crc.update (in);
    return (int) crc.getValue ();
}

Function 2:
private void readHeader () throws IOException {
    CRC32 headCRC = new CRC32 ();
    int magic = in.read ();
    if (magic < 0) {
        eos = true;
        return;
    }
    headCRC.update (magic);
    if (magic != (GZIP_MAGIC>> 8)) throw new IOException ("Error in GZIP header, first byte doesn't match");

    magic = in.read ();
    if (magic != (GZIP_MAGIC & 0xff)) throw new IOException ("Error in GZIP header, second byte doesn't match");

    headCRC.update (magic);
    int CM = in.read ();
    if (CM != 8) throw new IOException ("Error in GZIP header, data not in deflate format");

    headCRC.update (CM);
    int flags = in.read ();
    if (flags < 0) throw new EOFException ("Early EOF in GZIP header");

    headCRC.update (flags);
    if ((flags & 0xd0) != 0) throw new IOException ("Reserved flag bits in GZIP header != 0");

    for (int i = 0;
    i < 6; i ++) {
        int readByte = in.read ();
        if (readByte < 0) throw new EOFException ("Early EOF in GZIP header");

        headCRC.update (readByte);
    }
    if ((flags & FEXTRA) != 0) {
        for (int i = 0;
        i < 2; i ++) {
            int readByte = in.read ();
            if (readByte < 0) throw new EOFException ("Early EOF in GZIP header");

            headCRC.update (readByte);
        }
        if (in.read () < 0 || in.read () < 0) throw new EOFException ("Early EOF in GZIP header");

        int len1, len2, extraLen;
        len1 = in.read ();
        len2 = in.read ();
        if ((len1 < 0) || (len2 < 0)) throw new EOFException ("Early EOF in GZIP header");

        headCRC.update (len1);
        headCRC.update (len2);
        extraLen = (len1 << 8) | len2;
        for (int i = 0;
        i < extraLen; i ++) {
            int readByte = in.read ();
            if (readByte < 0) throw new EOFException ("Early EOF in GZIP header");

            headCRC.update (readByte);
        }
    }
    if ((flags & FNAME) != 0) {
        int readByte;
        while ((readByte = in.read ()) > 0) headCRC.update (readByte);

        if (readByte < 0) throw new EOFException ("Early EOF in GZIP file name");

        headCRC.update (readByte);
    }
    if ((flags & FCOMMENT) != 0) {
        int readByte;
        while ((readByte = in.read ()) > 0) headCRC.update (readByte);

        if (readByte < 0) throw new EOFException ("Early EOF in GZIP comment");

        headCRC.update (readByte);
    }
    if ((flags & FHCRC) != 0) {
        int tempByte;
        int crcval = in.read ();
        if (crcval < 0) throw new EOFException ("Early EOF in GZIP header");

        tempByte = in.read ();
        if (tempByte < 0) throw new EOFException ("Early EOF in GZIP header");

        crcval = (crcval << 8) | tempByte;
        if (crcval != ((int) headCRC.getValue () & 0xffff)) throw new IOException ("Header CRC value mismatch");

    }
    readGZIPHeader = true;
}
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 close () {
    logger.debug ("Closing output file.");
    outfile.close ();
    tempFile.renameTo (new File (fileName));
    if (toZIP) {
        logger.debug ("ZIPping output file.");
        try {
            ZipOutputStream zipout = new ZipOutputStream (new FileOutputStream (fileName + ".zip"));
            zipout.setLevel (9);
            String outfilezipname = fileName.substring (fileName.lastIndexOf (System.getProperty ("file.separator")) + 1);
            zipout.putNextEntry (new ZipEntry (outfilezipname));
            FileInputStream fis = new FileInputStream (fileName);
            byte [] buffer = new byte [65536];
            int len;
            while ((len = fis.read (buffer)) > 0) {
                zipout.write (buffer, 0, len);
            }
            zipout.close ();
            fis.close ();
            logger.debug ("ZIPping output file ok.");
            logger.debug ("Removing " + fileName);
            (new File (fileName)).delete ();
        } catch (IOException ex) {
            logger.debug ("Error when zipping file", ex);
        }
    }
}
Functionality: Zip Files
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
@BeforeClass
public static void createProblem () throws IOException, ParserConfigurationException, TransformerException {
    problem = File.createTempFile ("___prb___", ".problem");
    System.out.println ("created temporary problem " + problem);
    ZipOutputStream zos = new ZipOutputStream (new FileOutputStream (problem));
    PrintStream ps = new PrintStream (zos);
    zos.putNextEntry (new ZipEntry ("MANIFEST"));
    DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance ();
    DocumentBuilder builder = builderFactory.newDocumentBuilder ();
    Document doc = builder.newDocument ();
    Element root = doc.createElement ("resources");
    doc.appendChild (root);
    Element alias = doc.createElement ("alias");
    alias.setAttribute ("path", "STATEMENT");
    alias.setAttribute ("target", "statement.txt");
    root.appendChild (alias);
    Element contents1 = doc.createElement ("contents");
    contents1.setAttribute ("path", "ANSWER");
    contents1.setTextContent ("42");
    root.appendChild (contents1);
    Element contents2 = doc.createElement ("contents");
    contents2.setAttribute ("path", "STATEMENT EXT");
    contents2.setTextContent ("TXT");
    root.appendChild (contents2);
    Element teacher = doc.createElement ("teacher");
    teacher.setAttribute ("path", "ANSWER");
    root.appendChild (teacher);
    Source source = new DOMSource (doc);
    Result result = new StreamResult (zos);
    Transformer xformer = TransformerFactory.newInstance ().newTransformer ();
    xformer.transform (source, result);
    zos.putNextEntry (new ZipEntry ("statement.txt"));
    ps.println ("���� ����� ������������ ����� � ����?");
    zos.closeEntry ();
    zos.close ();
}

Function 2:
public static boolean exportStandalone (String projectDirectory, String destinyJARPath) {
    boolean exported = true;
    try {
        File destinyJarFile = new File (destinyJARPath);
        FileOutputStream mergedFile = new FileOutputStream (destinyJarFile);
        ZipOutputStream os = new ZipOutputStream (mergedFile);
        String manifest = Writer.defaultManifestFile ("es.eucm.eadventure.engine.EAdventureStandalone");
        ZipEntry manifestEntry = new ZipEntry ("META-INF/MANIFEST.MF");
        os.putNextEntry (manifestEntry);
        os.write (manifest.getBytes ());
        os.closeEntry ();
        os.flush ();
        File.mergeZipAndDirToJar ("web/eAdventure_temp.jar", projectDirectory, os);
        addNeededLibrariesToJar (os, Controller.getInstance ());
        os.close ();
    } catch (FileNotFoundException e) {
        exported = false;
        ReportDialog.GenerateErrorReport (e, true, "UNKNOWNERROR");
    } catch (IOException e) {
        exported = false;
        ReportDialog.GenerateErrorReport (e, true, "UNKNOWNERROR");
    }
    return exported;
}
Functionality: Copy File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
@Override
public boolean copy (Document document, Folder folder) throws Exception {
    boolean isCopied = false;
    if (document.getId () != null && folder.getId () != null) {
        Document copiedDoc = new DocumentModel ();
        copiedDoc.setValues (document.getValues ());
        copiedDoc.setFolder (folder);
        copiedDoc.setId (null);
        em.persist (copiedDoc);
        resourceAuthorityService.applyAuthority (copiedDoc);
        List < Preference > preferences = prefService.findAll ();
        Preference preference = new PreferenceModel ();
        if (preferences != null && ! preferences.isEmpty ()) {
            preference = preferences.get (0);
        }
        String repo = preference.getRepository ();
        SimpleDateFormat sdf = new SimpleDateFormat (Constants.DATEFORMAT_YYYYMMDD);
        Calendar calendar = Calendar.getInstance ();
        StringBuffer sbRepo = new StringBuffer (repo);
        sbRepo.append (File.separator);
        StringBuffer sbFolder = new StringBuffer (sdf.format (calendar.getTime ()));
        sbFolder.append (File.separator).append (calendar.get (Calendar.HOUR_OF_DAY));
        File fFolder = new File (sbRepo.append (sbFolder).toString ());
        if (! fFolder.exists ()) {
            fFolder.mkdirs ();
        }
        copiedDoc.setLocation (sbFolder.toString ());
        em.merge (copiedDoc);
        File in = new File (repo + File.separator + document.getLocation () + File.separator + document.getId () + "." + document.getExt ());
        File out = new File (fFolder.getAbsolutePath () + File.separator + copiedDoc.getId () + "." + copiedDoc.getExt ());
        FileChannel inChannel = new FileInputStream (in).getChannel ();
        FileChannel outChannel = new FileOutputStream (out).getChannel ();
        try {
            inChannel.transferTo (0, inChannel.size (), outChannel);
        } catch (IOException e) {
            throw e;
        } finally {
            if (inChannel != null) inChannel.close ();

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

        }
    }
    return isCopied;
}

Function 2:
private static void copy (File source, File target) throws IOException {
    FileInputStream from = null;
    FileOutputStream to = null;
    try {
        from = new FileInputStream (source);
        to = new FileOutputStream (target);
        byte [] buffer = new byte [4096];
        int bytesRead;
        while ((bytesRead = from.read (buffer)) != - 1) to.write (buffer, 0, bytesRead);

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

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

    }
}