semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static void main(String[] args) throws Exception {
        File rootDir = new File("C:\\dev\\workspace_fgd\\gouvqc_crggid\\WebContent\\WEB-INF\\upload");
        File storeDir = new File(rootDir, "storeDir");
        File workDir = new File(rootDir, "workDir");
        LoggerFacade loggerFacade = new CommonsLoggingLogger(logger);
        final FileResourceManager frm = new SmbFileResourceManager(storeDir.getPath(), workDir.getPath(), true, loggerFacade);
        frm.start();
        final String resourceId = "811375c8-7cae-4429-9a0e-9222f47dab45";
        {
            if (!frm.resourceExists(resourceId)) {
                String txId = frm.generatedUniqueTxId();
                frm.startTransaction(txId);
                FileInputStream inputStream = new FileInputStream(resourceId);
                frm.createResource(txId, resourceId);
                OutputStream outputStream = frm.writeResource(txId, resourceId);
                IOUtils.copy(inputStream, outputStream);
                IOUtils.closeQuietly(inputStream);
                IOUtils.closeQuietly(outputStream);
                frm.prepareTransaction(txId);
                frm.commitTransaction(txId);
            }
        }
        for (int i = 0; i < 30; i++) {
            final int index = i;
            new Thread() {

                @Override
                public void run() {
                    try {
                        String txId = frm.generatedUniqueTxId();
                        frm.startTransaction(txId);
                        InputStream inputStream = frm.readResource(resourceId);
                        frm.prepareTransaction(txId);
                        frm.commitTransaction(txId);
                        synchronized (System.out) {
                            System.out.println(index + " ***********************" + txId + " (début)");
                        }
                        String contenu = TikaUtils.getParsedContent(inputStream, "file.pdf");
                        synchronized (System.out) {
                            System.out.println(index + " ***********************" + txId + " (fin)");
                        }
                    } catch (ResourceManagerSystemException e) {
                        throw new RuntimeException(e);
                    } catch (ResourceManagerException e) {
                        throw new RuntimeException(e);
                    } catch (TikaException e) {
                        throw new RuntimeException(e);
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                }
            }.start();
        }
        Thread.sleep(60000);
        frm.stop(FileResourceManager.SHUTDOWN_MODE_NORMAL);
    }
public static String hash(String arg) throws NoSuchAlgorithmException {
        String input = arg;
        String output;
        MessageDigest md = MessageDigest.getInstance("SHA");
        md.update(input.getBytes());
        output = Hex.encodeHexString(md.digest());
        return output;
    }
@Override
    protected Metadata doGet(final String url) throws WebServiceException, MbXMLException {
        final HttpGet method = new HttpGet(url);
        this.log.debug(url);
        Metadata metadata = null;
        try {
            final HttpResponse response = this.httpClient.execute(method);
            final int statusCode = response.getStatusLine().getStatusCode();
            if (HttpStatus.SC_OK == statusCode) {
                final InputStream responseStream = response.getEntity().getContent();
                metadata = this.getParser().parse(responseStream);
            } else {
                final String responseString = response.getEntity() != null ? EntityUtils.toString(response.getEntity()) : "";
                switch(statusCode) {
                    case HttpStatus.SC_NOT_FOUND:
                        throw new ResourceNotFoundException(responseString);
                    case HttpStatus.SC_BAD_REQUEST:
                        throw new RequestException(responseString);
                    case HttpStatus.SC_FORBIDDEN:
                        throw new AuthorizationException(responseString);
                    case HttpStatus.SC_UNAUTHORIZED:
                        throw new AuthorizationException(responseString);
                    default:
                        String em = "web service returned unknown status '" + statusCode + "', response was: " + responseString;
                        this.log.error(em);
                        throw new WebServiceException(em);
                }
            }
        } catch (IOException e) {
            this.log.error("Fatal transport error: " + e.getMessage());
            throw new WebServiceException(e.getMessage(), e);
        }
        return metadata;
    }
@Override
    protected void doPost(final String url, final InputStream data) throws WebServiceException {
        final HttpPost method = new HttpPost(url);
        method.setEntity(new InputStreamEntity(data, -1));
        try {
            final HttpResponse response = this.httpClient.execute(method);
            final String responseString = response.getEntity() != null ? EntityUtils.toString(response.getEntity()) : "";
            final int statusCode = response.getStatusLine().getStatusCode();
            switch(statusCode) {
                case HttpStatus.SC_OK:
                    return;
                case HttpStatus.SC_NOT_FOUND:
                    throw new ResourceNotFoundException(responseString);
                case HttpStatus.SC_BAD_REQUEST:
                    throw new RequestException(responseString);
                case HttpStatus.SC_FORBIDDEN:
                    throw new AuthorizationException(responseString);
                case HttpStatus.SC_UNAUTHORIZED:
                    throw new AuthorizationException(responseString);
                default:
                    String em = "web service returned unknown status '" + statusCode + "', response was: " + responseString;
                    this.log.error(em);
                    throw new WebServiceException(em);
            }
        } catch (IOException e) {
            this.log.error("Fatal transport error: " + e.getMessage());
            throw new WebServiceException(e.getMessage(), e);
        }
    }
private void javaToHtml(File source, File destination) throws IOException {
        Reader reader = new FileReader(source);
        Writer writer = new FileWriter(destination);
        JavaUtils.writeJava(reader, writer);
        writer.flush();
        writer.close();
    }
private void copy(File source, File dest) throws IOException {
        FileChannel in = null;
        FileChannel out = null;
        try {
            in = new FileInputStream(source).getChannel();
            out = new FileOutputStream(dest).getChannel();
            long size = in.size();
            MappedByteBuffer buf = in.map(FileChannel.MapMode.READ_ONLY, 0, size);
            out.write(buf);
        } finally {
            close(in);
            close(out);
        }
    }
public String getMethod(String url) {
        logger.info("Facebook: @executing facebookGetMethod():" + url);
        String responseStr = null;
        try {
            HttpGet loginGet = new HttpGet(url);
            loginGet.addHeader("Accept-Encoding", "gzip");
            HttpResponse response = httpClient.execute(loginGet);
            HttpEntity entity = response.getEntity();
            logger.trace("Facebook: facebookGetMethod: " + response.getStatusLine());
            if (entity != null) {
                InputStream in = response.getEntity().getContent();
                if (response.getEntity().getContentEncoding().getValue().equals("gzip")) {
                    in = new GZIPInputStream(in);
                }
                StringBuffer sb = new StringBuffer();
                byte[] b = new byte[4096];
                int n;
                while ((n = in.read(b)) != -1) {
                    sb.append(new String(b, 0, n));
                }
                responseStr = sb.toString();
                in.close();
                entity.consumeContent();
            }
            int statusCode = response.getStatusLine().getStatusCode();
            if (statusCode != 200) {
                logger.warn("Facebook: Error Occured! Status Code = " + statusCode);
                responseStr = null;
            }
            logger.info("Facebook: Get Method done(" + statusCode + "), response string length: " + (responseStr == null ? 0 : responseStr.length()));
        } catch (IOException e) {
            logger.warn("Facebook: ", e);
        }
        return responseStr;
    }
public byte[] getBytesMethod(String url) {
        logger.info("Facebook: @executing facebookGetMethod():" + url);
        byte[] responseBytes = null;
        try {
            HttpGet loginGet = new HttpGet(url);
            loginGet.addHeader("Accept-Encoding", "gzip");
            HttpResponse response = httpClient.execute(loginGet);
            HttpEntity entity = response.getEntity();
            logger.trace("Facebook: getBytesMethod: " + response.getStatusLine());
            if (entity != null) {
                InputStream in = response.getEntity().getContent();
                if (response.getEntity().getContentEncoding().getValue().equals("gzip")) {
                    in = new GZIPInputStream(in);
                }
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                byte[] b = new byte[4096];
                int n;
                while ((n = in.read(b)) != -1) {
                    out.write(b, 0, n);
                }
                responseBytes = out.toByteArray();
                in.close();
                entity.consumeContent();
            }
            int statusCode = response.getStatusLine().getStatusCode();
            if (statusCode != 200) {
                logger.warn("Facebook: Error Occured! Status Code = " + statusCode);
                responseBytes = null;
            }
            logger.info("Facebook: Get Bytes Method done(" + statusCode + "), response bytes length: " + (responseBytes == null ? 0 : responseBytes.length));
        } catch (IOException e) {
            logger.warn("Facebook: ", e);
        }
        return responseBytes;
    }
public void init(ConnectionManager mgr, Hashtable cfg, Socket sock) throws RemoteException {
        _cman = mgr;
        _sock = sock;
        try {
            _sout = new PrintWriter(_sock.getOutputStream(), true);
            _sinp = new BufferedReader(new InputStreamReader(_sock.getInputStream()));
            String seed = "";
            Random rand = new Random();
            for (int i = 0; i < 16; i++) {
                String hex = Integer.toHexString(rand.nextInt(256));
                if (hex.length() < 2) hex = "0" + hex;
                seed += hex.substring(hex.length() - 2);
            }
            String pass = _mpsw + seed + _spsw;
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.reset();
            md5.update(pass.getBytes());
            String hash = hash2hex(md5.digest()).toLowerCase();
            String banner = "INIT " + "servername" + " " + hash + " " + seed;
            sendLine(banner);
            String txt = readLine(5);
            if (txt == null) {
                throw new IOException("Slave did not send banner !!");
            }
            String sname = "";
            String spass = "";
            String sseed = "";
            try {
                String[] items = txt.split(" ");
                sname = items[1].trim();
                spass = items[2].trim();
                sseed = items[3].trim();
            } catch (Exception e) {
                SocketSlaveListener.invalidSlave("INITFAIL BadKey", _sock);
            }
            pass = _spsw + sseed + _mpsw;
            md5 = MessageDigest.getInstance("MD5");
            md5.reset();
            md5.update(pass.getBytes());
            hash = hash2hex(md5.digest()).toLowerCase();
            if (!sname.equals(_name)) {
                SocketSlaveListener.invalidSlave("INITFAIL Unknown", _sock);
            }
            if (!spass.toLowerCase().equals(hash.toLowerCase())) {
                SocketSlaveListener.invalidSlave("INITFAIL BadKey", _sock);
            }
            start();
            _cman.getSlaveManager().addSlave(_name, this, getSlaveStatus(), -1);
        } catch (IOException e) {
            if (e instanceof ConnectIOException && e.getCause() instanceof EOFException) {
                logger.info("Check slaves.xml on the master that you are allowed to connect.");
            }
            logger.info("IOException: " + e.toString());
            try {
                sock.close();
            } catch (Exception e1) {
            }
        } catch (Exception e) {
            logger.warn("Exception: " + e.toString());
            try {
                sock.close();
            } catch (Exception e2) {
            }
        }
        System.gc();
    }
public String merge(int width, int height) throws Exception {
        htErrors.clear();
        sendGetImageRequests(width, height);
        Vector files = new Vector();
        ConcurrentHTTPTransactionHandler c = new ConcurrentHTTPTransactionHandler();
        c.setCache(cache);
        c.checkIfModified(false);
        for (int i = 0; i < vImageUrls.size(); i++) {
            if ((String) vImageUrls.get(i) != null) {
                c.register((String) vImageUrls.get(i));
            } else {
            }
        }
        c.doTransactions();
        vTransparency = new Vector();
        for (int i = 0; i < vImageUrls.size(); i++) {
            if (vImageUrls.get(i) != null) {
                String path = c.getResponseFilePath((String) vImageUrls.get(i));
                if (path != null) {
                    String contentType = c.getHeaderValue((String) vImageUrls.get(i), "content-type");
                    if (contentType.startsWith("image")) {
                        files.add(path);
                        vTransparency.add(htTransparency.get(vRank.get(i)));
                    }
                }
            }
        }
        if (files.size() > 1) {
            File output = TempFiles.getFile();
            String path = output.getPath();
            ImageMerger.mergeAndSave(files, vTransparency, path, ImageMerger.GIF);
            imageName = output.getName();
            imagePath = output.getPath();
            return (imageName);
        } else if (files.size() == 1) {
            File f = new File((String) files.get(0));
            File out = TempFiles.getFile();
            BufferedInputStream is = new BufferedInputStream(new FileInputStream(f));
            BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(out));
            byte buf[] = new byte[1024];
            for (int nRead; (nRead = is.read(buf, 0, 1024)) > 0; os.write(buf, 0, nRead)) ;
            os.flush();
            os.close();
            is.close();
            imageName = out.getName();
            return imageName;
        } else return "";
    }
public static Document getDocument(URL url, EntityResolver resolver, boolean validating) throws IllegalArgumentException, IOException {
        if (url == null) throw new IllegalArgumentException("URL is null");
        InputStream is = null;
        try {
            is = url.openStream();
            InputSource source = new InputSource(is);
            source.setSystemId(url.toString());
            return getDocument(source, resolver, validating);
        } finally {
            try {
                if (is != null) is.close();
            } catch (IOException ioe) {
            }
        }
    }
private boolean isReservaOK(String urlAddress, String operationId, String idioma, String codigo_pedido, String merchantId) throws ServletException {
        StringBuffer buf = new StringBuffer();
        try {
            URL url = new URL(urlAddress + "?Num_operacion=" + operationId + "&Idioma=" + idioma + "&Codigo_pedido=" + codigo_pedido + "&MerchantID=" + merchantId);
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String str;
            while ((str = in.readLine()) != null) {
                buf.append(str);
            }
            in.close();
        } catch (IOException e) {
            throw new ServletException(e);
        }
        return buf.indexOf("$*$OKY$*$") != -1;
    }
private boolean copy_to_file_io(File src, File dst) throws IOException {
        InputStream is = null;
        OutputStream os = null;
        try {
            is = new FileInputStream(src);
            is = new BufferedInputStream(is);
            os = new FileOutputStream(dst);
            os = new BufferedOutputStream(os);
            byte buffer[] = new byte[1024 * 64];
            int read;
            while ((read = is.read(buffer)) > 0) {
                os.write(buffer, 0, read);
            }
            return true;
        } finally {
            try {
                if (is != null) is.close();
            } catch (IOException e) {
                Debug.debug(e);
            }
            try {
                if (os != null) os.close();
            } catch (IOException e) {
                Debug.debug(e);
            }
        }
    }
private final boolean copy_to_file_nio(File src, File dst) throws IOException {
        FileChannel srcChannel = null, dstChannel = null;
        try {
            srcChannel = new FileInputStream(src).getChannel();
            dstChannel = new FileOutputStream(dst).getChannel();
            {
                int safe_max = (64 * 1024 * 1024) / 4;
                long size = srcChannel.size();
                long position = 0;
                while (position < size) {
                    position += srcChannel.transferTo(position, safe_max, dstChannel);
                }
            }
            return true;
        } finally {
            try {
                if (srcChannel != null) srcChannel.close();
            } catch (IOException e) {
                Debug.debug(e);
            }
            try {
                if (dstChannel != null) dstChannel.close();
            } catch (IOException e) {
                Debug.debug(e);
            }
        }
    }
public static HttpURLConnection createSoapHttpURLConnection(String url) throws MalformedURLException, IOException {
        HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
        connection.setRequestMethod("POST");
        connection.addRequestProperty("Connection", "close");
        connection.addRequestProperty("Content-Type", "application/soap+xml; charset=utf-8");
        connection.setDoOutput(true);
        connection.setDoInput(true);
        return connection;
    }
private static String deviceIdFromCombined_Device_ID(Context context) {
        StringBuilder builder = new StringBuilder();
        builder.append(deviceIdFromIMEI(context));
        builder.append(deviceIdFromPseudo_Unique_Id());
        builder.append(deviceIdFromAndroidId(context));
        builder.append(deviceIdFromWLAN_MAC_Address(context));
        builder.append(deviceIdFromBT_MAC_Address(context));
        String m_szLongID = builder.toString();
        MessageDigest m = null;
        try {
            m = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        m.update(m_szLongID.getBytes(), 0, m_szLongID.length());
        byte p_md5Data[] = m.digest();
        String m_szUniqueID = new String();
        for (int i = 0; i < p_md5Data.length; i++) {
            int b = (0xFF & p_md5Data[i]);
            if (b <= 0xF) m_szUniqueID += "0";
            m_szUniqueID += Integer.toHexString(b);
        }
        return m_szUniqueID;
    }
private Drawable fetchImage(String iconUrl, Context ctx) {
        URL url;
        HttpClient httpClient = new DefaultHttpClient();
        try {
            if (PreferenceManager.getDefaultSharedPreferences(ctx).getBoolean("use.urlimg.com", true)) {
                iconUrl = iconUrl.substring(iconUrl.indexOf("//") + 2);
                iconUrl = "http://urlimg.com/width/100/" + iconUrl;
            }
            Log.d(ImageCache.class.getName(), "Loading image from: " + iconUrl);
            HttpGet httpGet = new HttpGet(iconUrl);
            HttpResponse response = httpClient.execute(httpGet);
            InputStream content = response.getEntity().getContent();
            Drawable d = Drawable.createFromStream(content, "src");
            content.close();
            httpGet.abort();
            return d;
        } catch (IOException e) {
            Log.e(ImageCache.class.getName(), "IOException while fetching: " + iconUrl);
            return TELKA;
        } finally {
        }
    }
private void removeCollection(long oid, Connection conn) throws XMLDBException {
        try {
            String sql = "DELETE FROM X_DOCUMENT WHERE X_DOCUMENT.XDB_COLLECTION_OID = ?";
            PreparedStatement pstmt = conn.prepareStatement(sql);
            pstmt.setLong(1, oid);
            pstmt.executeUpdate();
            pstmt.close();
            sql = "DELETE FROM XDB_COLLECTION WHERE XDB_COLLECTION.XDB_COLLECTION_OID = ?";
            pstmt = conn.prepareStatement(sql);
            pstmt.setLong(1, oid);
            pstmt.executeUpdate();
            pstmt.close();
            removeChildCollection(oid, conn);
        } catch (java.sql.SQLException se) {
            try {
                conn.rollback();
            } catch (java.sql.SQLException se2) {
                se2.printStackTrace();
            }
            se.printStackTrace();
        }
    }
private static void checkForUpgrade() {
        try {
            Log.out("Checking for updates...");
            URL u = ClassLoader.getSystemResource(Settings.readme);
            if (u == null) {
                u = HImage.class.getResource("/" + Settings.readme);
            }
            DataInputStream i = new DataInputStream(u.openStream());
            String tmp = i.readLine();
            tmp = tmp.substring(tmp.lastIndexOf(">"));
            tmp = tmp.substring(tmp.indexOf(".") + 1);
            tmp = tmp.substring(0, tmp.indexOf("<"));
            int x = Integer.parseInt(tmp) + 1;
            String nextVersion = "jftp-1.";
            if (x < 10) {
                nextVersion = nextVersion + "0";
            }
            nextVersion = nextVersion + x + ".tar.gz";
            File dl = new File(nextVersion);
            if (!dl.exists() || (dl.length() <= 0)) {
                URL url = new URL("http://osdn.dl.sourceforge.net/sourceforge/j-ftp/" + nextVersion);
                BufferedOutputStream f = new BufferedOutputStream(new FileOutputStream(dl));
                BufferedInputStream in = new BufferedInputStream(url.openStream());
                byte[] buf = new byte[4096];
                int stat = 1;
                Log.out("\ndownloading update: " + dl.getAbsolutePath() + "\n\n");
                while (stat > 0) {
                    stat = in.read(buf);
                    if (stat == -1) {
                        break;
                    }
                    f.write(buf, 0, stat);
                    System.out.print(".");
                }
                f.flush();
                f.close();
                in.close();
            }
            Log.out("\n\n\na newer version was found!\nplease install the File " + dl.getAbsolutePath() + " or even better visit the homepage to download the latest version...\n" + "you can turn this feature off if you don't like it (view readme for details)\n\nStarting anyway...\n\n");
        } catch (Exception ex) {
        }
        Log.out("finished check...");
    }