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

Function 1:
public static PO FactoryPO (Class < ? > c, Properties ctx, ResultSet rs, String trx) throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {
    Constructor < ? > con = c.getConstructor (Properties.class, ResultSet.class, String.class);
    PO p = (PO) con.newInstance (ctx, rs, trx);
    return p;
}

Function 2:
protected Object instantiate (Class < ? > type, Object [] args) {
    try {
        if (args.length == 0 || this.constructors.length == 0) return type.newInstance ();

        if (this.constructors.length == 1) if (this.constructors [0].getParameterTypes ().length == 0) return this.constructors [0].newInstance (new Object [0]);
        else return this.constructors [0].newInstance (args);

        else {
            Class < ? > [] types = new Class < ? > [args.length];
            for (int i = 0;
            i < args.length; i ++) types [i] = args [i].getClass ();

            try {
                return type.getConstructor (types).newInstance (args);
            } catch (NoSuchMethodException e) {
                return type.newInstance ();
            }
        }
    } catch (InstantiationException e) {
        throw new RuntimeException (instantiationError (type, "It is probably a non-static inner class or an abstract class."), e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException (instantiationError (type, "Either the class itself or its constructor are not public."), e);
    } catch (IllegalArgumentException e) {
        List < String > types = new ArrayList < String > ();
        for (Object arg : args) types.add (arg.getClass ().getName ());

        throw new RuntimeException (instantiationError (type, "Argument mismatch in calling the constructor with arguments." + "\nExpected types are (probably): " + Arrays.asList (this.constructors [0].getParameterTypes ()) + "\nProvided types are (sure): " + types.toString ()), e);
    } catch (InvocationTargetException e) {
        throw new RuntimeException (instantiationError (type, "Its construtor has thrown an exception, probably of type: " + e.getCause () + ". See the stack trace for details"), e);
    }
}
Functionality: Copy File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public void copy (String sourcePath, String targetPath) throws IOException {
    File sourceFile = new File (sourcePath);
    File targetFile = new File (targetPath);
    FileInputStream fileInputStream = null;
    FileOutputStream fileOutputStream = null;
    try {
        fileInputStream = new FileInputStream (sourceFile);
        fileOutputStream = new FileOutputStream (targetFile);
        byte [] buffer = new byte [4096];
        int bytesRead;
        while ((bytesRead = fileInputStream.read (buffer)) != - 1) fileOutputStream.write (buffer, 0, bytesRead);

    } finally {
        if (fileInputStream != null) try {
            fileInputStream.close ();
        } catch (IOException exception) {
            JOptionPane.showMessageDialog (null, AcideLanguageManager.getInstance ().getLabels ().getString ("s265") + sourcePath, AcideLanguageManager.getInstance ().getLabels ().getString ("s266"), JOptionPane.ERROR_MESSAGE);
            AcideLog.getLog ().error (exception.getMessage ());
        }

        if (fileOutputStream != null) try {
            fileOutputStream.close ();
        } catch (IOException exception) {
            JOptionPane.showMessageDialog (null, AcideLanguageManager.getInstance ().getLabels ().getString ("s267") + targetPath, AcideLanguageManager.getInstance ().getLabels ().getString ("268"), JOptionPane.ERROR_MESSAGE);
            AcideLog.getLog ().error (exception.getMessage ());
        }

    }
}

Function 2:
public static void copy (File file1, File file2) throws IOException {
    FileReader in = new FileReader (file1);
    FileWriter out = new FileWriter (file2);
    int c;
    while ((c = in.read ()) != - 1) out.write (c);

    in.close ();
    out.close ();
}
Functionality: Instantiate Using Reflection
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public CustomArticle NewInstance (NpsContext ctxt, Topic top, ResultSet rs) throws Exception {
    if (top == null) throw new NpsException (ErrorHelper.SYS_NOTOPIC);

    if (top.GetTable () == null || top.GetTable ().length () == 0) throw new NpsException (ErrorHelper.SYS_NEED_CUSTOM_TOPIC);

    String table_name = top.GetTable ().toUpperCase ();
    if (classes == null || classes.isEmpty () || ! classes.containsKey (table_name)) {
        return new CustomArticle (ctxt, top, rs);
    }
    Class clazz = GetArticleClass (table_name);
    java.lang.reflect.Constructor aconstructor = clazz.getConstructor (new Class [] {NpsContext.class, Topic.class, ResultSet.class});
    return (CustomArticle) aconstructor.newInstance (new Object [] {ctxt, top, rs});
}

Function 2:
private AppNode getAppNode (AppContext app) {
    AppDescriptor appDescriptor = app.getDescriptor ();
    ClassLoader classLoader = Thread.currentThread ().getContextClassLoader ();
    ImageIcon icon = null;
    try {
        String pkg = Tools.getPackage (appDescriptor.getClassName ());
        URL url = classLoader.getResource (pkg + "/icon.png");
        if (url == null) url = classLoader.getResource ("icon.png");

        icon = new ImageIcon (new ImageIcon (url).getImage ().getScaledInstance (16, 16, Image.SCALE_SMOOTH));
    } catch (Exception ex) {
        Tools.logException (OptionsPanelManager.class, ex, "Could not load icon " + " for app " + appDescriptor.getClassName ());
    }
    if (! appDescriptor.isHME ()) {
        AppConfigurationPanel appConfigurationPanel = null;
        try {
            Class configurationPanel = classLoader.loadClass (appDescriptor.getConfigurationPanel ());
            Class [] parameters = new Class [1];
            parameters [0] = AppConfiguration.class;
            Constructor constructor = configurationPanel.getConstructor (parameters);
            AppConfiguration [] values = new AppConfiguration [1];
            values [0] = (AppConfiguration) app.getConfiguration ();
            appConfigurationPanel = (AppConfigurationPanel) constructor.newInstance ((Object []) values);
        } catch (Exception ex) {
            ex.printStackTrace ();
            Tools.logException (OptionsPanelManager.class, ex, "Could not load configuration panel " + appDescriptor.getConfigurationPanel () + " for app " + appDescriptor.getClassName ());
        }
        AppNode appNode = new AppNode (app, icon, appConfigurationPanel);
        return appNode;
    } else {
        return new AppNode (app, icon, new HMEConfigurationPanel (app.getConfiguration ()));
    }
}
Functionality: Copy File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public void copyFile (File sourceFile, String toDir, boolean create, boolean overwrite) throws FileNotFoundException, IOException {
    FileInputStream source = null;
    FileOutputStream destination = null;
    byte [] buffer;
    int bytes_read;
    File toFile = new File (toDir);
    if (create && ! toFile.exists ()) toFile.mkdirs ();

    if (toFile.exists ()) {
        File destFile = new File (toDir + "/" + sourceFile.getName ());
        try {
            if (! destFile.exists () || overwrite) {
                source = new FileInputStream (sourceFile);
                destination = new FileOutputStream (destFile);
                buffer = new byte [1024];
                while (true) {
                    bytes_read = source.read (buffer);
                    if (bytes_read == - 1) break;

                    destination.write (buffer, 0, bytes_read);
                }
            }
        } catch (Exception exx) {
            exx.printStackTrace ();
        } finally {
            if (source != null) try {
                source.close ();
            } catch (IOException e) {
            }

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

        }
    }
}

Function 2:
private static void loadFromZip () {
    InputStream in = Resources.class.getResourceAsStream ("data.zip");
    if (in == null) {
        return;
    }
    ZipInputStream zipIn = new ZipInputStream (in);
    try {
        while (true) {
            ZipEntry entry = zipIn.getNextEntry ();
            if (entry == null) {
                break;
            }
            String entryName = entry.getName ();
            if (! entryName.startsWith ("/")) {
                entryName = "/" + entryName;
            }
            ByteArrayOutputStream out = new ByteArrayOutputStream ();
            IOUtils.copy (zipIn, out);
            zipIn.closeEntry ();
            FILES.put (entryName, out.toByteArray ());
        }
        zipIn.close ();
    } catch (IOException e) {
        e.printStackTrace ();
    }
}
Functionality: Copy File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
@Test
public void testLargePut () throws Throwable {
    int size = CommonParameters.BLOCK_SIZE;
    InputStream is = new FileInputStream (_fileName);
    RepositoryFileOutputStream ostream = new RepositoryFileOutputStream (_nodeName, _putHandle, CommonParameters.local);
    int readLen = 0;
    int writeLen = 0;
    byte [] buffer = new byte [CommonParameters.BLOCK_SIZE];
    while ((readLen = is.read (buffer, 0, size)) != - 1) {
        ostream.write (buffer, 0, readLen);
        writeLen += readLen;
    }
    ostream.close ();
    CCNStats stats = _putHandle.getNetworkManager ().getStats ();
    Assert.assertEquals (0, stats.getCounter ("DeliverInterestFailed"));
}

Function 2:
public static void copyDirectory (File sourceDirectory, File targetDirectory) throws IOException {
    File [] sourceFiles = sourceDirectory.listFiles (FILE_FILTER);
    File [] sourceDirectories = sourceDirectory.listFiles (DIRECTORY_FILTER);
    targetDirectory.mkdirs ();
    if (sourceFiles != null && sourceFiles.length > 0) {
        for (int i = 0;
        i < sourceFiles.length; i ++) {
            File sourceFile = sourceFiles [i];
            FileInputStream fis = new FileInputStream (sourceFile);
            FileOutputStream fos = new FileOutputStream (targetDirectory + File.separator + sourceFile.getName ());
            FileChannel fcin = fis.getChannel ();
            FileChannel fcout = fos.getChannel ();
            ByteBuffer buf = ByteBuffer.allocateDirect (8192);
            long size = fcin.size ();
            long n = 0;
            while (n < size) {
                buf.clear ();
                if (fcin.read (buf) < 0) {
                    break;
                }
                buf.flip ();
                n += fcout.write (buf);
            }
            fcin.close ();
            fcout.close ();
            fis.close ();
            fos.close ();
        }
    }
    if (sourceDirectories != null && sourceDirectories.length > 0) {
        for (int i = 0;
        i < sourceDirectories.length; i ++) {
            File directory = sourceDirectories [i];
            File newTargetDirectory = new File (targetDirectory, directory.getName ());
            copyDirectory (directory, newTargetDirectory);
        }
    }
}
Functionality: Download From Web
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
private static String getData (String myurl) throws Exception {
    System.out.println ("getdata");
    URL url = new URL (myurl);
    uc = (HttpURLConnection) url.openConnection ();
    br = new BufferedReader (new InputStreamReader (uc.getInputStream ()));
    String temp = "", k = "";
    while ((temp = br.readLine ()) != null) {
        System.out.println (temp);
        k += temp;
    }
    br.close ();
    return k;
}

Function 2:
private String [] read (String path) throws Exception {
    final String [] names = {"index.txt", "", "index.html", "index.htm"};
    String [] list = null;
    for (int i = 0;
    i < names.length; i ++) {
        URL url = new URL (path + names [i]);
        try {
            BufferedReader in = new BufferedReader (new InputStreamReader (url.openStream ()));
            StringBuffer sb = new StringBuffer ();
            String s = null;
            while ((s = in.readLine ()) != null) {
                s = s.trim ();
                if (s.length () > 0) {
                    sb.append (s + "\n");
                }
            }
            in.close ();
            if (sb.indexOf ("<") != - 1 && sb.indexOf (">") != - 1) {
                List links = LinkExtractor.scan (url, sb.toString ());
                HashSet set = new HashSet ();
                int prefixLen = path.length ();
                for (Iterator it = links.iterator ();
                it.hasNext ();) {
                    String link = it.next ().toString ();
                    if (! link.startsWith (path)) {
                        continue;
                    }
                    link = link.substring (prefixLen);
                    int idx = link.indexOf ("/");
                    int idxq = link.indexOf ("?");
                    if (idx > 0 && (idxq == - 1 || idx < idxq)) {
                        set.add (link.substring (0, idx + 1));
                    } else {
                        set.add (link);
                    }
                }
                list = (String []) set.toArray (new String [0]);
            } else {
                list = sb.toString ().split ("\n");
            }
            return list;
        } catch (FileNotFoundException e) {
            e.printStackTrace ();
            continue;
        }
    }
    return new String [0];
}
Functionality: Open URL in System Browser
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public void hyperlinkUpdate (HyperlinkEvent event) {
    URL url = event.getURL ();
    if (event.getEventType () == HyperlinkEvent.EventType.ENTERED && ! event.getDescription ().startsWith ("copyUrl:")) {
        updatesEditorPane.setToolTipText (url.toString ());
    } else if (event.getEventType () == HyperlinkEvent.EventType.EXITED) {
        updatesEditorPane.setToolTipText (null);
    } else if (event.getEventType () == HyperlinkEvent.EventType.ACTIVATED) {
        if (event.getDescription ().startsWith ("copyUrl:")) {
            String toCopy = event.getDescription ().replaceFirst ("copyUrl:", "");
            StringSelection data = new StringSelection (toCopy);
            Clipboard clipboard = Toolkit.getDefaultToolkit ().getSystemClipboard ();
            clipboard.setContents (data, data);
        } else {
            String browser = configManager.getBrowser ();
            if (! Desktop.isDesktopSupported ()) {
                try {
                    if (! browser.equals ("")) {
                        Runtime.getRuntime ().exec (browser + " " + url.toString ());
                    } else {
                        Runtime.getRuntime ().exec ("firefox " + url.toString ());
                    }
                } catch (Exception ex) {
                    JOptionPane.showMessageDialog (this, "Unable to find a web browser, please set up one on settings window", "Web browser error", JOptionPane.WARNING_MESSAGE);
                }
            }
            try {
                Desktop desktop = Desktop.getDesktop ();
                URI uri = new URI (url.toString ());
                desktop.browse (uri);
            } catch (Exception e) {
                return;
            }
        }
    }

}

Function 2:
public void hyperlinkUpdate (HyperlinkEvent e) {
    if (e.getEventType () == HyperlinkEvent.EventType.ACTIVATED) {
        try {
            if (Desktop.isDesktopSupported ()) {
                Desktop.getDesktop ().browse (e.getURL ().toURI ());
            } else Tools.openURL (e.getURL ().toString ());

        } catch (Exception x) {
            JOptionPane.showMessageDialog (null, x.getMessage ());
        }
    }
}
Functionality: CRC32 File Checksum
Clone type: Type-3 (WT3/4)
Is clone: FALSE

Function 1:
public static long calculateCheckSum (CharSequence data) {
    final Checksum checksummer = new CRC32 ();
    for (int i = 0;
    i < data.length (); i ++) {
        checksummer.update (data.charAt (i));
    }
    return checksummer.getValue ();
}

Function 2:
private byte [] gettEXtBytes (String keyword, String content) {
    byte [] keywordBytes = getISO8859_1Bytes (keyword);
    byte [] contentBytes = getISO8859_1Bytes (content);
    byte [] array = new byte [keywordBytes.length + contentBytes.length + 13];
    ByteBuffer buffer = ByteBuffer.wrap (array);
    buffer.putInt (keywordBytes.length + contentBytes.length + 1);
    buffer.put (getISO8859_1Bytes (CHUNK_TYPE_tEXT));
    buffer.put (keywordBytes);
    buffer.put ((byte) 0);
    buffer.put (contentBytes);
    CRC32 crc = new CRC32 ();
    crc.update (array, 4, keywordBytes.length + contentBytes.length + 5);
    buffer.putInt ((int) crc.getValue ());
    return array;
}
Functionality: Copy File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public File copyFile (File f) throws IOException {
    File t = createNewFile ("fm", "cpy");
    FileOutputStream fos = new FileOutputStream (t);
    FileChannel foc = fos.getChannel ();
    FileInputStream fis = new FileInputStream (f);
    FileChannel fic = fis.getChannel ();
    foc.transferFrom (fic, 0, fic.size ());
    foc.close ();
    fic.close ();
    return t;
}

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:
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 static void addToZip (File [] files, ZipOutputStream out) throws IOException {
    byte [] buf = new byte [1024];
    for (int i = 0;
    i < files.length; i ++) {
        if (files [i].isDirectory ()) {
            addToZip (files [i].listFiles (), out);
        } else {
            FileInputStream in = new FileInputStream (files [i]);
            out.putNextEntry (new ZipEntry (files [i].getPath ()));
            int len;
            while ((len = in.read (buf)) > 0) {
                out.write (buf, 0, len);
            }
            out.closeEntry ();
            in.close ();
        }
    }
}
Functionality: Transpose a Matrix.
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
private float [] [] Transpose (float [] [] a) {
    if (INFO) {
        System.out.println ("Performing Transpose...");
    }
    float m [] [] = new float [a [0].length] [a.length];
    for (int i = 0;
    i < a.length; i ++) for (int j = 0;
    j < a [i].length; j ++) m [j] [i] = a [i] [j];

    return m;
}

Function 2:
private void updateWeightAnalog (int trackID, int k, float ts, boolean increase) {
    if (increase) {
        float targetV = neurons [trackID].getV (ts);
        float otherV = neurons [k].getV (ts);
        float targetMean = neurons [trackID].getMeanActivation ();
        float otherMean = neurons [k].getMeanActivation ();
        float delta1 = otherV * (otherV - otherMean) * targetV;
        float delta2 = targetV * (targetV - targetMean) * otherV;
        float mDelta = sigmoid ((delta1 + delta2) / 2.0f);
        w [trackID] [k] += alpha * mDelta;
        if (w [trackID] [k] > 1.0f) w [trackID] [k] = 1.0f;

        w [k] [trackID] = w [trackID] [k];
    } else {
        w [trackID] [k] -= reduceW;
        if (w [trackID] [k] < - 1.0f) w [trackID] [k] = - 1.0f;

        w [k] [trackID] = w [trackID] [k];
    }
}
Functionality: Copy File
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
public String stringOfUrl (String addr) throws IOException {
    ByteArrayOutputStream output = new ByteArrayOutputStream ();
    URL url = new URL (addr);
    IOUtils.copy (url.openStream (), output);
    return output.toString ();
}

Function 2:
private void copy (final File file) throws IOException {
    String targetFilename = targetFilename (file);
    FileInputStream fis = new FileInputStream (file);
    try {
        FileChannel source = fis.getChannel ();
        try {
            FileOutputStream fos = new FileOutputStream (targetFilename);
            try {
                FileChannel target = fos.getChannel ();
                try {
                    target.transferFrom (source, 0, source.size ());
                } finally {
                    target.close ();
                }
            } finally {
                fos.close ();
            }
        } finally {
            source.close ();
        }
    } finally {
        fis.close ();
    }
}
Functionality: Zip Files
Clone type: Type-3 (WT3/4)
Is clone: TRUE

Function 1:
private void writeEntry (JarOutputStream jos, ZipEntry entry, InputStream data) throws IOException {
    jos.putNextEntry (entry);
    byte [] newBytes = InputStreamUtil.createReadBuffer ();
    int size = data.read (newBytes);
    while (size != - 1) {
        jos.write (newBytes, 0, size);
        size = data.read (newBytes);
    }
    data.close ();
}

Function 2:
@Override
protected void handleFile (File file, int depth, Collection results) throws IOException {
    String path = "";
    File parent = file.getParentFile ();
    for (int i = 0;
    i < depth - 1; i ++) {
        path = parent.getName () + "/" + path;
        parent = parent.getParentFile ();
    }
    ZipEntry entry = new ZipEntry (path + file.getName ());
    output.putNextEntry (entry);
    int size = (int) file.length ();
    byte [] buffer = new byte [size];
    FileInputStream fis = new FileInputStream (file);
    fis.read (buffer);
    output.write (buffer);
}