semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private static void getClasses(Collection<Class<?>> classes, String... packageNames) throws ClassNotFoundException {
        boolean recursive = true;
        for (String packageName : packageNames) {
            if (StringUtil.isEmpty(packageName)) continue;
            String packageDirName = packageName.replace('.', '/');
            Enumeration<URL> dirs = null;
            try {
                dirs = Thread.currentThread().getContextClassLoader().getResources(packageDirName);
                while (dirs.hasMoreElements()) {
                    URL url = dirs.nextElement();
                    String protocol = url.getProtocol();
                    if ("file".equals(protocol)) {
                        String filePath = URLDecoder.decode(url.getFile(), DECODING);
                        getClassesByPackageFile(packageName, filePath, recursive, classes);
                    } else if ("jar".equals(protocol)) {
                        JarFile jar = null;
                        try {
                            jar = ((JarURLConnection) url.openConnection()).getJarFile();
                            Enumeration<JarEntry> entries = jar.entries();
                            while (entries.hasMoreElements()) {
                                JarEntry entry = entries.nextElement();
                                String name = entry.getName();
                                if (name.charAt(0) == '/') {
                                    name = name.substring(1);
                                }
                                if (name.startsWith(packageDirName)) {
                                    int idx = name.lastIndexOf('/');
                                    if (idx != -1) {
                                        packageName = name.substring(0, idx).replace('/', '.');
                                    }
                                    if ((idx != -1) || recursive) {
                                        if (name.endsWith(JAVA_CLASS_SUFFIX) && !entry.isDirectory()) {
                                            String className = name.substring(packageName.length() + 1, name.length() - 6);
                                            classes.add(loadClass(packageName + '.' + className));
                                        }
                                    }
                                }
                            }
                        } catch (IOException e) {
                            LOG.error("IOException when loading files from : " + url, e);
                        }
                    }
                }
            } catch (IOException e) {
                LOG.error("IOException when get classes from : " + packageName, e);
            }
        }
    }
public static byte[] expandPasswordToKey(String password, int keyLen, byte[] salt) {
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            int digLen = md5.getDigestLength();
            byte[] mdBuf = new byte[digLen];
            byte[] key = new byte[keyLen];
            int cnt = 0;
            while (cnt < keyLen) {
                if (cnt > 0) {
                    md5.update(mdBuf);
                }
                md5.update(password.getBytes());
                md5.update(salt);
                md5.digest(mdBuf, 0, digLen);
                int n = ((digLen > (keyLen - cnt)) ? keyLen - cnt : digLen);
                System.arraycopy(mdBuf, 0, key, cnt, n);
                cnt += n;
            }
            return key;
        } catch (Exception e) {
            throw new Error("Error in SSH2KeyPairFile.expandPasswordToKey: " + e);
        }
    }
public static byte[] expandPasswordToKeySSHCom(String password, int keyLen) {
        try {
            if (password == null) {
                password = "";
            }
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            int digLen = md5.getDigestLength();
            byte[] buf = new byte[((keyLen + digLen) / digLen) * digLen];
            int cnt = 0;
            while (cnt < keyLen) {
                md5.update(password.getBytes());
                if (cnt > 0) {
                    md5.update(buf, 0, cnt);
                }
                md5.digest(buf, cnt, digLen);
                cnt += digLen;
            }
            byte[] key = new byte[keyLen];
            System.arraycopy(buf, 0, key, 0, keyLen);
            return key;
        } catch (Exception e) {
            throw new Error("Error in SSH2KeyPairFile.expandPasswordToKeySSHCom: " + e);
        }
    }
private void copyFileNFS(String sSource, String sTarget) throws Exception {
        FileInputStream fis = new FileInputStream(sSource);
        FileOutputStream fos = new FileOutputStream(sTarget);
        BufferedInputStream bis = new BufferedInputStream(fis);
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        byte[] buf = new byte[2048];
        int i = 0;
        while ((i = bis.read(buf)) != -1) bos.write(buf, 0, i);
        bis.close();
        bos.close();
        fis.close();
        fos.close();
    }
private void convertClasses(File source, File destination) throws PostProcessingException, CodeCheckException, IOException {
        Stack sourceStack = new Stack();
        Stack destinationStack = new Stack();
        sourceStack.push(source);
        destinationStack.push(destination);
        while (!sourceStack.isEmpty()) {
            source = (File) sourceStack.pop();
            destination = (File) destinationStack.pop();
            if (!destination.exists()) destination.mkdirs();
            File[] files = source.listFiles();
            for (int i = 0; i < files.length; i++) {
                File current = (File) files[i];
                if (current.isDirectory()) {
                    sourceStack.push(current);
                    destinationStack.push(new File(destination, current.getName()));
                } else if (current.getName().endsWith(".class")) {
                    ClassWriter writer = new ClassWriter();
                    InputStream is = new BufferedInputStream(new FileInputStream(current));
                    writer.readClass(is);
                    is.close();
                    if ((getStatusFlags(writer.getClassName(writer.getCurrentClassIndex())) & PP_PROCESSED) != 0) {
                        ClassWriter[] auxWriter = new ClassWriter[1];
                        transformClass(writer, auxWriter);
                        File output = new File(destination, current.getName());
                        OutputStream os = new BufferedOutputStream(new FileOutputStream(output));
                        writer.writeClass(os);
                        os.close();
                        if (auxWriter[0] != null) {
                            String className = auxWriter[0].getClassName(auxWriter[0].getCurrentClassIndex());
                            className = className.substring(className.lastIndexOf('.') + 1, className.length());
                            output = new File(destination, className + ".class");
                            os = new BufferedOutputStream(new FileOutputStream(output));
                            auxWriter[0].writeClass(os);
                            os.close();
                        }
                    }
                }
            }
        }
    }
public String sendSMS(String destinationNumber, String txt, String id) throws IOException {
        String out = "";
        String smsdata = "";
        smsdata += URLEncoder.encode("id", enc) + "=" + URLEncoder.encode(id, enc);
        smsdata += "&" + URLEncoder.encode("phoneNumber", enc) + "=" + URLEncoder.encode(destinationNumber, enc);
        smsdata += "&" + URLEncoder.encode("conversationId", enc) + "=" + URLEncoder.encode(id, enc);
        smsdata += "&" + URLEncoder.encode("text", enc) + "=" + URLEncoder.encode(txt, enc);
        smsdata += "&" + URLEncoder.encode("_rnr_se", enc) + "=" + URLEncoder.encode(rnrSEE, enc);
        System.out.println("smsdata: " + smsdata);
        URL smsurl = new URL("https://www.google.com/voice/b/0/sms/send/");
        URLConnection smsconn = smsurl.openConnection();
        smsconn.setRequestProperty("Authorization", "GoogleLogin auth=" + authToken);
        smsconn.setRequestProperty("User-agent", USER_AGENT);
        smsconn.setDoOutput(true);
        OutputStreamWriter callwr = new OutputStreamWriter(smsconn.getOutputStream());
        callwr.write(smsdata);
        callwr.flush();
        BufferedReader callrd = new BufferedReader(new InputStreamReader(smsconn.getInputStream()));
        String line;
        while ((line = callrd.readLine()) != null) {
            out += line + "\n\r";
        }
        callwr.close();
        callrd.close();
        if (out.equals("")) {
            throw new IOException("No Response Data Received.");
        }
        return out;
    }
public static void changeStructure(double version) throws DException {
        try {
            Class cl = Class.forName("com.daffodilwoods.daffodildb.server.datadictionarysystem.SystemTablesCreator");
            java.net.URL urlw = cl.getResource("/com/daffodilwoods/daffodildb/server/datadictionarysystem/systemtablesStructure.obj");
            ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(urlw.openStream()));
            structureMap = (HashMap) ois.readObject();
            if (version >= 3.4) {
                Object[][] columnsTableStructure = (Object[][]) structureMap.get((Object) SystemTables.columns_TableName);
                columnsTableStructure[9][2] = new Integer(1027);
            }
            ois.close();
        } catch (IOException ex) {
        } catch (ClassNotFoundException ex) {
        }
    }
@Override
    public void execute() throws BuildException {
        if (this.toFile == null && this.toDir == null) throw new BuildException("Missing Destination File/Dir");
        if (this.toFile != null && this.toDir != null) throw new BuildException("Both Defined Destination File/Dir");
        if (this.urlStr == null) throw new BuildException("Missing URL");
        URL base = null;
        try {
            if (baseStr != null) base = new URL(this.baseStr + (baseStr.endsWith("/") ? "" : "/"));
        } catch (MalformedURLException e) {
            throw new BuildException(e);
        }
        String tokens[] = this.urlStr.split("[ \t\n]+");
        try {
            for (String nextURL : tokens) {
                nextURL = nextURL.trim();
                if (nextURL.length() == 0) continue;
                URL url = null;
                try {
                    url = new URL(base, nextURL);
                } catch (MalformedURLException e) {
                    throw new BuildException(e);
                }
                File dest = null;
                if (this.toDir != null) {
                    String file = url.getFile();
                    int i = file.lastIndexOf('/');
                    if (i != -1 && i + 1 != file.length()) file = file.substring(i + 1);
                    dest = new File(this.toDir, file);
                } else {
                    dest = this.toFile;
                }
                if (dest.exists()) continue;
                byte buff[] = new byte[2048];
                FileOutputStream out = new FileOutputStream(dest);
                InputStream in = url.openStream();
                int n = 0;
                while ((n = in.read(buff)) != -1) {
                    out.write(buff, 0, n);
                }
                in.close();
                out.flush();
                out.close();
                System.out.println("Downloaded " + url + " to " + dest);
            }
        } catch (IOException e) {
            throw new BuildException(e);
        }
    }
public static byte[] resolveRef(String url) throws MalformedURLException, IOException {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        URL addressurl = new URL(url);
        InputStream in = addressurl.openStream();
        BufferedReader bin = new BufferedReader(new InputStreamReader(in));
        int bufferSize = 4096;
        byte[] buffer = new byte[bufferSize];
        int bytesRead;
        while ((bytesRead = in.read(buffer, 0, bufferSize)) != -1) {
            out.write(buffer, 0, bytesRead);
            out.flush();
        }
        return out.toByteArray();
    }
private String encryptPassword(String password) throws NoSuchAlgorithmException {
        MessageDigest encript = MessageDigest.getInstance("MD5");
        encript.update(password.getBytes());
        byte[] b = encript.digest();
        int size = b.length;
        StringBuffer h = new StringBuffer(size);
        for (int i = 0; i < size; i++) {
            h.append(b[i]);
        }
        return h.toString();
    }
public void run() {
        try {
            ThreadGroup transfers = new ThreadGroup("transfers");
            URL url = new URL("jar:http://jopenrpg.sourceforge.net/files/dev/pythonlib.jar!/");
            JarURLConnection juc = (JarURLConnection) url.openConnection();
            File top = new File(System.getProperty("user.home"), "jopenrpg");
            final JarFile jarfile = juc.getJarFile();
            Enumeration enumer = jarfile.entries();
            while (enumer.hasMoreElements()) {
                final JarEntry entry = (JarEntry) enumer.nextElement();
                final File f = new File(top, entry.getName());
                if (entry.isDirectory()) {
                    f.mkdirs();
                } else {
                    if (!entry.getName().startsWith("META-INF")) new Thread(transfers, new Runnable() {

                        public void run() {
                            try {
                                BufferedReader br = new BufferedReader(new InputStreamReader(jarfile.getInputStream(entry)));
                                BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f)));
                                StringBuffer buf = new StringBuffer();
                                while (br.ready()) {
                                    buf.append(br.read());
                                }
                                bw.write(buf.toString(), 0, buf.length());
                                bw.close();
                                br.close();
                            } catch (Exception ex) {
                                System.out.println(ex);
                            }
                        }
                    }).start();
                }
            }
            while (transfers.activeCount() > 0) yield();
            SwingUtilities.invokeLater(new Runnable() {

                public void run() {
                    JOptionPane.showMessageDialog(ReferenceManager.getInstance().getMainFrame(), "Jython libraries installed.");
                }
            });
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
public void run() {
        try {
            URL url = new URL("http://mydiversite.appspot.com/version.html");
            BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
            String line;
            while ((line = reader.readLine()) != null) {
                System.out.println(line);
            }
            reader.close();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
public int extractDocumentsInternal(DocumentHolder holder, DocumentFactory docFactory) {
        FTPClient client = new FTPClient();
        try {
            client.connect(site, port == 0 ? 21 : port);
            client.login(user, password);
            visitDirectory(client, "", path, holder, docFactory);
            client.disconnect();
        } catch (SocketException e) {
            e.printStackTrace();
        } catch (IOException e) {
        }
        return fileCount;
    }
public synchronized void downloadTile(TileNumber tn) {
        try {
            Bitmap tile = getMapFromSdCache(tn);
            if (tile == null) {
                URL url = new URL("http://tile.openstreetmap.org/" + tn.getZoom() + "/" + tn.getX() + "/" + tn.getY() + ".png");
                tile = BitmapFactory.decodeStream(url.openStream());
                File sdCardPath = Environment.getExternalStorageDirectory();
                Log.d(ctx.getResources().getString(open.gps.gopens.R.string.TEST), "Path to SD :: " + sdCardPath.getAbsolutePath());
                File dir = new File(sdCardPath + ctx.getResources().getString(open.gps.gopens.R.string.CACHE_PATH) + tn.getZoom() + "/" + tn.getX() + "/");
                dir.mkdirs();
                File imgFile = new File(dir.getAbsolutePath() + "/" + tn.getY() + ".png");
                imgFile.createNewFile();
                FileOutputStream fOut = new FileOutputStream(imgFile);
                tile.compress(Bitmap.CompressFormat.PNG, 100, fOut);
            }
            cacheManager.put(tn.toString(), tile);
            setChanged();
            notifyObservers();
            Log.d("OBS", "OBS : Notify");
        } catch (MalformedURLException e) {
            Log.e("Error", e.getMessage());
        } catch (IOException e) {
            Log.e("Error", e.getMessage());
        }
    }
public TempFileTextBody(InputStream is, String mimeCharset) throws IOException {
        this.mimeCharset = mimeCharset;
        TempPath tempPath = TempStorage.getInstance().getRootTempPath();
        tempFile = tempPath.createTempFile("attachment", ".txt");
        OutputStream out = tempFile.getOutputStream();
        IOUtils.copy(is, out);
        out.close();
    }
public void handler(Map<String, String> result, TargetPage target) {
        try {
            URL url = new URL(target.getUrl());
            BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
            String line = null;
            while ((line = reader.readLine()) != null) {
                for (Map.Entry<String, String> entry : result.entrySet()) {
                    if (line.indexOf(target.getInclude()) != -1) {
                        int fromIndex = line.indexOf(target.getFromStr());
                        String r = line.substring(fromIndex + target.getFromStr().length(), line.indexOf(target.getToStr(), fromIndex));
                        entry.setValue(r);
                        line = line.substring(line.indexOf(target.getToStr()) + target.getToStr().length());
                    }
                }
            }
            reader.close();
        } catch (MalformedURLException e) {
        } catch (IOException e) {
        }
    }
public boolean GetExternalLanguage() {
        String thisURL, newURL, TheLine;
        boolean ReadOK = true;
        int SlashPos = -1;
        thisURL = getDocumentBase().toString();
        SlashPos = thisURL.lastIndexOf("/");
        newURL = thisURL.substring(0, (SlashPos + 1)) + "language.txt";
        try {
            URL url = new URL(newURL);
            try {
                InputStream TheFile = url.openStream();
                try {
                    DataInputStream MyData = new DataInputStream(TheFile);
                    try {
                        while ((TheLine = MyData.readLine()) != null) {
                            if (TheLine.substring(0, 1).compareTo("*") == 0) {
                                if (!ExternalLanguageVariable(TheLine)) {
                                    ReadOK = false;
                                    break;
                                }
                            }
                        }
                    } catch (Exception e) {
                        System.out.println("Error " + e.toString());
                        ReadOK = false;
                    }
                } catch (Exception e) {
                    System.out.println("Error " + e.toString());
                    ReadOK = false;
                }
            } catch (Exception f) {
                System.out.println("Error " + f.toString());
                ReadOK = false;
            }
        } catch (Exception g) {
            System.out.println("Error " + g.toString());
            ReadOK = false;
        }
        return ReadOK;
    }
public static void copyFile(File in, File out) throws IOException {
        FileChannel sourceChannel = new FileInputStream(in).getChannel();
        FileChannel destinationChannel = new FileOutputStream(out).getChannel();
        try {
            sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
        } finally {
            sourceChannel.close();
            destinationChannel.close();
        }
    }
public static void fileCopy(final File src, final File dest, final boolean overwrite) throws IOException {
        if (!dest.exists() || (dest.exists() && overwrite)) {
            final FileChannel srcChannel = new FileInputStream(src).getChannel();
            final FileChannel dstChannel = new FileOutputStream(dest).getChannel();
            dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
            srcChannel.close();
            dstChannel.close();
        }
    }
public static void copyFileStreams(File fromFile, File toFile) throws IOException {
        if (!fromFile.exists()) {
            return;
        }
        FileInputStream fis = new FileInputStream(fromFile);
        FileOutputStream fos = new FileOutputStream(toFile);
        int read = 0;
        byte[] buf = new byte[1024];
        while (-1 != read) {
            read = fis.read(buf);
            if (read >= 0) {
                fos.write(buf, 0, read);
            }
        }
        fos.close();
        fis.close();
    }
public void testReleaseOnEntityWriteTo() throws Exception {
        HttpParams params = defaultParams.copy();
        ConnManagerParams.setMaxTotalConnections(params, 1);
        ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(1));
        ThreadSafeClientConnManager mgr = createTSCCM(params, null);
        assertEquals(0, mgr.getConnectionsInPool());
        DefaultHttpClient client = new DefaultHttpClient(mgr, params);
        HttpGet httpget = new HttpGet("/random/20000");
        HttpHost target = getServerHttp();
        HttpResponse response = client.execute(target, httpget);
        ClientConnectionRequest connreq = mgr.requestConnection(new HttpRoute(target), null);
        try {
            connreq.getConnection(250, TimeUnit.MILLISECONDS);
            fail("ConnectionPoolTimeoutException should have been thrown");
        } catch (ConnectionPoolTimeoutException expected) {
        }
        HttpEntity e = response.getEntity();
        assertNotNull(e);
        ByteArrayOutputStream outsteam = new ByteArrayOutputStream();
        e.writeTo(outsteam);
        assertEquals(1, mgr.getConnectionsInPool());
        connreq = mgr.requestConnection(new HttpRoute(target), null);
        ManagedClientConnection conn = connreq.getConnection(250, TimeUnit.MILLISECONDS);
        mgr.releaseConnection(conn, -1, null);
        mgr.shutdown();
    }