semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private void loadMap(URI uri) throws IOException {
        BufferedReader reader = null;
        InputStream stream = null;
        try {
            URL url = uri.toURL();
            stream = url.openStream();
            if (url.getFile().endsWith(".gz")) {
                stream = new GZIPInputStream(stream);
            }
            reader = new BufferedReader(new InputStreamReader(stream));
            String line;
            while ((line = reader.readLine()) != null) {
                line = line.trim();
                if (line.length() > 0) {
                    String[] parts = line.split(" ");
                    if (parts.length == 2) {
                        pinyinZhuyinMap.put(parts[0], parts[1]);
                        zhuyinPinyinMap.put(parts[1], parts[0]);
                    }
                }
            }
        } finally {
            if (reader != null) {
                reader.close();
            }
        }
    }
private void executeRequest(OperationContext context) throws java.lang.Throwable {
        long t1 = System.currentTimeMillis();
        DirectoryParams params = context.getRequestOptions().getDirectoryOptions();
        try {
            String srvCfg = context.getRequestContext().getApplicationConfiguration().getCatalogConfiguration().getParameters().getValue("openls.directory");
            HashMap<String, String> poiProperties = params.getPoiProperties();
            Set<String> keys = poiProperties.keySet();
            Iterator<String> iter = keys.iterator();
            StringBuffer filter = new StringBuffer();
            while (iter.hasNext()) {
                String key = iter.next();
                QueryFilter queryFilter = new QueryFilter(key, poiProperties.get(key));
                filter.append(makePOIRequest(queryFilter));
            }
            String sUrl = srvCfg + "/query?" + filter.toString();
            LOGGER.info("REQUEST=\n" + sUrl);
            URL url = new URL(sUrl);
            URLConnection conn = url.openConnection();
            String line = "";
            String sResponse = "";
            InputStream is = conn.getInputStream();
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader rd = new BufferedReader(isr);
            while ((line = rd.readLine()) != null) {
                sResponse += line;
            }
            rd.close();
            url = null;
            parsePOIResponse(sResponse, params);
        } catch (Exception p_e) {
            LOGGER.severe("Throwing exception" + p_e.getMessage());
            throw p_e;
        } finally {
            long t2 = System.currentTimeMillis();
            LOGGER.info("PERFORMANCE: " + (t2 - t1) + " ms spent performing service");
        }
    }
private String[] readFile(String filename) {
        final Vector<String> buf = new Vector<String>();
        try {
            final URL url = new URL(getCodeBase(), filename);
            final InputStream in = url.openStream();
            BufferedReader dis = new BufferedReader(new InputStreamReader(in));
            String line;
            while ((line = dis.readLine()) != null) {
                buf.add(line);
            }
            in.close();
        } catch (IOException e) {
            System.out.println("catch: " + e);
            return null;
        }
        return buf.toArray(new String[0]);
    }
public ResourceBundle getResources() {
        if (resources == null) {
            String lang = userProps.getProperty("language");
            lang = "en";
            try {
                URL myurl = getResource("Resources_" + lang.trim() + ".properties");
                InputStream in = myurl.openStream();
                resources = new PropertyResourceBundle(in);
                in.close();
            } catch (Exception ex) {
                System.err.println("Error loading Resources");
                return null;
            }
        }
        return resources;
    }
public static String md5(String texto) {
        String resultado;
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(texto.getBytes());
            BigInteger hash = new BigInteger(1, md5.digest());
            resultado = hash.toString(16);
            if (resultado.length() < 32) {
                char chars[] = new char[32 - resultado.length()];
                Arrays.fill(chars, '0');
                resultado = new String(chars) + resultado;
            }
        } catch (NoSuchAlgorithmException e) {
            resultado = e.toString();
        }
        return resultado;
    }
private String doRawGet(URI uri) throws XdsInternalException {
        HttpURLConnection conn = null;
        String response = null;
        try {
            URL url;
            try {
                url = uri.toURL();
            } catch (Exception e) {
                throw HttpClient.getException(e, uri.toString());
            }
            HttpsURLConnection.setDefaultHostnameVerifier(this);
            conn = (HttpURLConnection) url.openConnection();
            conn.setDoOutput(true);
            conn.setUseCaches(false);
            conn.setRequestMethod("GET");
            conn.setRequestProperty("Accept", "text/html, text/xml, text/plain, */*");
            conn.connect();
            response = this.getResponse(conn);
        } catch (IOException e) {
            throw HttpClient.getException(e, uri.toString());
        } finally {
            if (conn != null) {
                conn.disconnect();
            }
        }
        return response;
    }
public static void main(String[] args) {
        FTPClient client = new FTPClient();
        String sFTP = "ftp.servidor.com";
        String sUser = "usuario";
        String sPassword = "pasword";
        try {
            System.out.println("Conectandose a " + sFTP);
            client.connect(sFTP);
            client.login(sUser, sPassword);
            System.out.println(client.printWorkingDirectory());
            client.changeWorkingDirectory("\\httpdocs");
            System.out.println(client.printWorkingDirectory());
            System.out.println("Desconectando.");
            client.logout();
            client.disconnect();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String[] path = StringUtils.split(request.getRequestURI(), "/");
        String file = path[path.length - 1];
        File f = new File(pathToImages + "/" + file);
        response.setContentType(getServletContext().getMimeType(f.getName()));
        FileInputStream fis = new FileInputStream(f);
        IOUtils.copy(fis, response.getOutputStream());
        fis.close();
    }
public static void copyFile(File destFile, File src) throws IOException {
        File destDir = destFile.getParentFile();
        File tempFile = new File(destFile + "_tmp");
        destDir.mkdirs();
        InputStream is = new FileInputStream(src);
        try {
            FileOutputStream os = new FileOutputStream(tempFile);
            try {
                byte[] buf = new byte[8192];
                int len;
                while ((len = is.read(buf)) > 0) os.write(buf, 0, len);
            } finally {
                os.close();
            }
        } finally {
            is.close();
        }
        destFile.delete();
        if (!tempFile.renameTo(destFile)) throw new IOException("Unable to rename " + tempFile + " to " + destFile);
    }
public InputStream doRemoteCall(NamedList<String> params) throws IOException {
        String protocol = "http";
        String host = getHost();
        int port = Integer.parseInt(getPort());
        StringBuilder sb = new StringBuilder();
        for (Map.Entry entry : params) {
            Object key = entry.getKey();
            Object value = entry.getValue();
            sb.append(key).append("=").append(value).append("&");
        }
        sb.setLength(sb.length() - 1);
        String file = "/" + getUrl() + "/?" + sb.toString();
        URL url = new URL(protocol, host, port, file);
        logger.debug(url.toString());
        InputStream stream;
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        try {
            stream = conn.getInputStream();
        } catch (IOException ioe) {
            InputStream is = conn.getErrorStream();
            if (is != null) {
                String msg = getStringFromInputStream(conn.getErrorStream());
                throw new IOException(msg);
            } else {
                throw ioe;
            }
        }
        return stream;
    }
public static int sendMessage(String auth_token, String registrationId, String message) throws IOException {
        StringBuilder postDataBuilder = new StringBuilder();
        postDataBuilder.append(PARAM_REGISTRATION_ID).append("=").append(registrationId);
        postDataBuilder.append("&").append(PARAM_COLLAPSE_KEY).append("=").append("0");
        postDataBuilder.append("&").append("data.payload").append("=").append(URLEncoder.encode(message, UTF8));
        byte[] postData = postDataBuilder.toString().getBytes(UTF8);
        URL url = new URL(C2DM_SEND_ENDPOINT);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setDoOutput(true);
        conn.setUseCaches(false);
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
        conn.setRequestProperty("Content-Length", Integer.toString(postData.length));
        conn.setRequestProperty("Authorization", "GoogleLogin auth=" + auth_token);
        OutputStream out = conn.getOutputStream();
        out.write(postData);
        out.close();
        int responseCode = conn.getResponseCode();
        if (responseCode == HttpServletResponse.SC_UNAUTHORIZED || responseCode == HttpServletResponse.SC_FORBIDDEN) {
            AuthenticationUtil.getTokenFromServer(Util.USER, Util.PASSWORD);
            sendMessage(auth_token, registrationId, message);
        }
        String updatedAuthToken = conn.getHeaderField(UPDATE_CLIENT_AUTH);
        if (updatedAuthToken != null && !auth_token.equals(updatedAuthToken)) {
            Util.updateToken(updatedAuthToken);
        }
        return responseCode;
    }
public void run() {
        StringBuffer messageStringBuffer = new StringBuffer();
        messageStringBuffer.append("Program: \t" + UpdateChannel.getCurrentChannel().getApplicationTitle() + "\n");
        messageStringBuffer.append("Version: \t" + Lister.version + "\n");
        messageStringBuffer.append("Revision: \t" + Lister.revision + "\n");
        messageStringBuffer.append("Channel: \t" + UpdateChannel.getCurrentChannel().getName() + "\n");
        messageStringBuffer.append("Date: \t\t" + Lister.date + "\n\n");
        messageStringBuffer.append("OS: \t\t" + System.getProperty("os.name") + " (" + System.getProperty("os.version") + ")\n");
        messageStringBuffer.append("JAVA: \t\t" + System.getProperty("java.version") + " (" + System.getProperty("java.specification.vendor") + ")\n");
        messageStringBuffer.append("Desktop: \t" + System.getProperty("sun.desktop") + "\n");
        messageStringBuffer.append("Language: \t" + Language.getCurrentInstance() + "\n\n");
        messageStringBuffer.append("------------------------------------------\n");
        if (summary != null) {
            messageStringBuffer.append(summary + "\n\n");
        }
        messageStringBuffer.append("Details:\n");
        if (description != null) {
            messageStringBuffer.append(description);
        }
        if (exception != null) {
            messageStringBuffer.append("\n\nStacktrace:\n");
            printStackTrace(exception, messageStringBuffer);
        }
        try {
            if (dialog != null) {
                setComponentsEnabled(dialog.getContentPane(), false);
            }
            URL url = UpdateChannel.getCurrentChannel().getErrorReportURL();
            URLConnection urlConnection = url.openConnection();
            urlConnection.setDoOutput(true);
            OutputStreamWriter outputStreamWriter = new OutputStreamWriter(urlConnection.getOutputStream());
            if (sender != null) {
                outputStreamWriter.write(URLEncoder.encode("sender", "UTF-8") + "=" + URLEncoder.encode(sender, "UTF-8"));
                outputStreamWriter.write("&");
            }
            outputStreamWriter.write(URLEncoder.encode("report", "UTF-8") + "=" + URLEncoder.encode(messageStringBuffer.toString(), "UTF-8"));
            if (attachErrorLog) {
                outputStreamWriter.write("&");
                outputStreamWriter.write(URLEncoder.encode("error.log", "UTF-8") + "=" + URLEncoder.encode(Logger.getErrorLogContent(), "UTF-8"));
            }
            outputStreamWriter.flush();
            urlConnection.getInputStream().close();
            outputStreamWriter.close();
            if (dialog != null) {
                dialog.dispose();
            }
            JOptionPane.showMessageDialog(Lister.getCurrentInstance(), Language.translateStatic("MESSAGE_ERRORREPORTSENT"));
        } catch (Exception exception) {
            ErrorJDialog.showErrorDialog(dialog, exception);
            if (dialog != null) {
                setComponentsEnabled(dialog.getContentPane(), true);
            }
        }
    }
public static synchronized String hash(String data) {
        if (digest == null) {
            try {
                digest = MessageDigest.getInstance("SHA-1");
            } catch (NoSuchAlgorithmException nsae) {
                System.err.println("Failed to load the SHA-1 MessageDigest. " + "Jive will be unable to function normally.");
            }
        }
        try {
            digest.update(data.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            System.err.println(e);
        }
        return encodeHex(digest.digest());
    }
private void unzipEntry(ZipFile zipfile, ZipEntry entry, File outputDir, BackUpInfoFileGroup fileGroup, LinkedList<String> restoreList) {
        LinkedList<BackUpInfoFile> fileList = fileGroup.getFileList();
        if (entry.isDirectory()) {
            createDir(new File(outputDir, entry.getName()));
            return;
        }
        for (int i = 0; i < fileList.size(); i++) {
            if (fileList.get(i).getId().equals(entry.getName())) {
                for (int j = 0; j < restoreList.size(); j++) {
                    if ((fileList.get(i).getName() + "." + fileList.get(i).getType()).equals(restoreList.get(j))) {
                        counter += 1;
                        File outputFile = new File(outputDir, fileList.get(i).getName() + "." + fileList.get(i).getType());
                        if (!outputFile.getParentFile().exists()) {
                            createDir(outputFile.getParentFile());
                        }
                        BufferedInputStream inputStream;
                        BufferedOutputStream outputStream;
                        try {
                            inputStream = new BufferedInputStream(zipfile.getInputStream(entry));
                            outputStream = new BufferedOutputStream(new FileOutputStream(outputFile));
                            IOUtils.copy(inputStream, outputStream);
                            outputStream.close();
                            inputStream.close();
                        } catch (IOException ex) {
                            throw new BackupException(ex.getMessage());
                        }
                    }
                }
            }
        }
    }
public static Map<VariableLengthInteger, ElementDescriptor> readDescriptors(URL url) throws IOException, XMLStreamException {
        if (url == null) {
            throw new IllegalArgumentException("url is null");
        }
        InputStream stream = new BufferedInputStream(url.openStream());
        try {
            return readDescriptors(stream);
        } finally {
            try {
                stream.close();
            } catch (IOException ignored) {
            }
        }
    }
@Override
    protected String doInBackground(String... params) {
        HttpURLConnection conn = null;
        String localFilePath = params[0];
        if (localFilePath == null) {
            return null;
        }
        try {
            URL url = new URL(ConnectionHandler.getServerURL() + ":" + ConnectionHandler.getServerPort() + "/");
            conn = (HttpURLConnection) url.openConnection();
            conn.setDoInput(true);
            conn.setDoOutput(true);
            conn.setUseCaches(false);
            conn.setRequestMethod("POST");
            conn.addRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
            DataOutputStream dos = new DataOutputStream(conn.getOutputStream());
            DataInputStream fileReader = new DataInputStream(new FileInputStream(localFilePath));
            dos.write(toByte(twoHyphens + boundary + lineEnd));
            dos.write(toByte("Content-Disposition: form-data; name=\"uploadfile\"; filename=\"redpinfile\"" + lineEnd));
            dos.write(toByte("Content-Type: application/octet-stream" + lineEnd));
            dos.write(toByte("Content-Length: " + fileReader.available() + lineEnd));
            dos.write(toByte(lineEnd));
            byte[] buffer = new byte[1024];
            int bytesRead;
            while ((bytesRead = fileReader.read(buffer)) != -1) {
                dos.write(buffer, 0, bytesRead);
            }
            dos.write(toByte(lineEnd));
            dos.write(toByte(twoHyphens + boundary + twoHyphens + lineEnd));
            dos.flush();
            dos.close();
            if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
                InputStream is = conn.getInputStream();
                int ch;
                StringBuffer b = new StringBuffer();
                while ((ch = is.read()) != -1) {
                    b.append((char) ch);
                }
                return b.toString();
            }
        } catch (MalformedURLException ex) {
            Log.w(TAG, "error: " + ex.getMessage(), ex);
        } catch (IOException ioe) {
            Log.w(TAG, "error: " + ioe.getMessage(), ioe);
        } finally {
            if (conn != null) {
                conn.disconnect();
            }
        }
        return null;
    }
public void migrateTo(String newExt) throws IOException {
        DigitalObject input = new DigitalObject.Builder(Content.byReference(new File(AllJavaSEServiceTestsuite.TEST_FILE_LOCATION + "PlanetsLogo.png").toURI().toURL())).build();
        System.out.println("Input: " + input);
        FormatRegistry format = FormatRegistryFactory.getFormatRegistry();
        MigrateResult mr = dom.migrate(input, format.createExtensionUri("png"), format.createExtensionUri(newExt), null);
        ServiceReport sr = mr.getReport();
        System.out.println("Got Report: " + sr);
        DigitalObject doOut = mr.getDigitalObject();
        assertTrue("Resulting digital object is null.", doOut != null);
        System.out.println("Output: " + doOut);
        System.out.println("Output.content: " + doOut.getContent());
        File out = new File("services/java-se/test/results/test." + newExt);
        FileOutputStream fo = new FileOutputStream(out);
        IOUtils.copyLarge(doOut.getContent().getInputStream(), fo);
        fo.close();
        System.out.println("Recieved service report: " + mr.getReport());
        System.out.println("Recieved service properties: ");
        ServiceProperties.printProperties(System.out, mr.getReport().getProperties());
    }
public static String getHash(String key) {
        try {
            MessageDigest digest = MessageDigest.getInstance("MD5");
            digest.update(key.getBytes());
            return new BigInteger(digest.digest()).toString(16);
        } catch (NoSuchAlgorithmException e) {
            return key;
        }
    }
public static String calcCRC(String phrase) {
        StringBuffer crcCalc = new StringBuffer();
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(phrase.getBytes());
            byte[] tabDigest = md.digest();
            for (int i = 0; i < tabDigest.length; i++) {
                String octet = "0" + Integer.toHexString(tabDigest[i]);
                crcCalc.append(octet.substring(octet.length() - 2));
            }
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return crcCalc.toString();
    }
private void loadProperties() throws IOException {
        if (properties == null) {
            return;
        }
        printDebugIfEnabled("Loading properties");
        InputStream inputStream = configurationSource.openStream();
        Properties newProperties = new Properties();
        try {
            newProperties.load(inputStream);
        } finally {
            inputStream.close();
        }
        String importList = newProperties.getProperty(KEY_IMPORT);
        if (importList != null) {
            importList = importList.trim();
            if (importList.length() > 0) {
                String[] filesToImport = importList.split(",");
                if (filesToImport != null && filesToImport.length != 0) {
                    String configurationContext = configurationSource.toExternalForm();
                    int lastSlash = configurationContext.lastIndexOf('/');
                    lastSlash += 1;
                    configurationContext = configurationContext.substring(0, lastSlash);
                    for (int i = 0; i < filesToImport.length; i++) {
                        String filenameToImport = filesToImport[i];
                        URL urlToImport = new URL(configurationContext + filenameToImport);
                        InputStream importStream = null;
                        try {
                            printDebugIfEnabled("Importing file", urlToImport);
                            importStream = urlToImport.openStream();
                            newProperties.load(importStream);
                        } catch (IOException e) {
                            printError("Error importing properties file: " + filenameToImport + "(" + urlToImport + ")", e, true);
                        } finally {
                            if (importStream != null) importStream.close();
                        }
                    }
                }
            }
        }
        if (devDebug) {
            Set properties = newProperties.entrySet();
            printDebugIfEnabled("_____ Properties List START _____");
            for (Iterator iterator = properties.iterator(); iterator.hasNext(); ) {
                Map.Entry entry = (Map.Entry) iterator.next();
                printDebugIfEnabled((String) entry.getKey(), entry.getValue());
            }
            printDebugIfEnabled("______ Properties List END ______");
        }
        properties.clear();
        properties.putAll(newProperties);
    }
public void setKey(String key) {
        MessageDigest md5;
        byte[] mdKey = new byte[32];
        try {
            md5 = MessageDigest.getInstance("MD5");
            md5.update(key.getBytes());
            byte[] digest = md5.digest();
            System.arraycopy(digest, 0, mdKey, 0, 16);
            System.arraycopy(digest, 0, mdKey, 16, 16);
        } catch (Exception e) {
            System.out.println("MD5 not implemented, can't generate key out of string!");
            System.exit(1);
        }
        setKey(mdKey);
    }