semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static String getMD5Hash(String original) {
        StringBuffer sb = new StringBuffer();
        try {
            StringReader sr = null;
            int crypt_byte = 0;
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.reset();
            md.update(original.getBytes());
            byte[] digest = md.digest();
            sr = new StringReader(new String(digest, "ISO8859_1"));
            while ((crypt_byte = sr.read()) != -1) {
                String hexString = Integer.toHexString(crypt_byte);
                if (crypt_byte < 16) {
                    hexString = "0" + hexString;
                }
                sb.append(hexString);
            }
        } catch (NoSuchAlgorithmException nsae) {
        } catch (IOException ioe) {
        }
        return sb.toString();
    }
protected void initializeFromURL(URL url, AVList params) throws IOException {
        URLConnection connection = url.openConnection();
        String message = this.validateURLConnection(connection, SHAPE_CONTENT_TYPES);
        if (message != null) {
            throw new IOException(message);
        }
        this.shpChannel = Channels.newChannel(WWIO.getBufferedInputStream(connection.getInputStream()));
        URLConnection shxConnection = this.getURLConnection(WWIO.replaceSuffix(url.toString(), INDEX_FILE_SUFFIX));
        if (shxConnection != null) {
            message = this.validateURLConnection(shxConnection, INDEX_CONTENT_TYPES);
            if (message != null) Logging.logger().warning(message); else {
                InputStream shxStream = this.getURLStream(shxConnection);
                if (shxStream != null) this.shxChannel = Channels.newChannel(WWIO.getBufferedInputStream(shxStream));
            }
        }
        URLConnection prjConnection = this.getURLConnection(WWIO.replaceSuffix(url.toString(), PROJECTION_FILE_SUFFIX));
        if (prjConnection != null) {
            message = this.validateURLConnection(prjConnection, PROJECTION_CONTENT_TYPES);
            if (message != null) Logging.logger().warning(message); else {
                InputStream prjStream = this.getURLStream(prjConnection);
                if (prjStream != null) this.prjChannel = Channels.newChannel(WWIO.getBufferedInputStream(prjStream));
            }
        }
        this.setValue(AVKey.DISPLAY_NAME, url.toString());
        this.initialize(params);
        URL dbfURL = WWIO.makeURL(WWIO.replaceSuffix(url.toString(), ATTRIBUTE_FILE_SUFFIX));
        if (dbfURL != null) {
            try {
                this.attributeFile = new DBaseFile(dbfURL);
            } catch (Exception e) {
            }
        }
    }
public static int numberofLines(JApplet ja, String filename) {
        int count = 0;
        URL url = null;
        String FileToRead;
        FileToRead = "data/" + filename + ".csv";
        try {
            url = new URL(ja.getCodeBase(), FileToRead);
        } catch (MalformedURLException e) {
            System.out.println("Malformed URL ");
            ja.stop();
        }
        System.out.println(url.toString());
        try {
            InputStream in = url.openStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(in));
            while ((reader.readLine()) != null) {
                count++;
            }
            in.close();
        } catch (IOException e) {
        }
        return count;
    }
public void doRecurringPayment(Subscription subscription) {
        int amount = Math.round(subscription.getTotalCostWithDiscounts() * 100.0f);
        String currency = subscription.getCurrency();
        String aliasCC = subscription.getAliasCC();
        String expm = subscription.getLastCardExpm();
        String expy = subscription.getLastCardExpy();
        String subscriptionId = String.valueOf(subscription.getSubscriptionId());
        StringBuffer xmlSB = new StringBuffer("");
        xmlSB.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
        xmlSB.append("<authorizationService version=\"1\">\n");
        xmlSB.append(" <body merchantId=\"" + getMerchantId() + "\" testOnly=\"" + getTestOnly() + "\">\n");
        xmlSB.append("    <transaction refno=\"" + REF_NO + "\">\n");
        xmlSB.append("      <request>\n");
        xmlSB.append("        <amount>" + amount + "</amount>\n");
        xmlSB.append("        <currency>" + currency + "</currency>\n");
        xmlSB.append("        <aliasCC>" + aliasCC + "</aliasCC>\n");
        xmlSB.append("        <expm>" + expm + "</expm>\n");
        xmlSB.append("        <expy>" + expy + "</expy>\n");
        xmlSB.append("        <subscriptionId>" + subscriptionId + "</subscriptionId>\n");
        xmlSB.append("      </request>\n");
        xmlSB.append("    </transaction>\n");
        xmlSB.append(" </body>\n");
        xmlSB.append("</authorizationService>\n");
        String xmlS = xmlSB.toString();
        try {
            java.net.URL murl = new java.net.URL(getRecurringPaymentUrl());
            java.net.HttpURLConnection mcon = (java.net.HttpURLConnection) murl.openConnection();
            mcon.setRequestMethod("POST");
            mcon.setRequestProperty("encoding", "UTF-8");
            mcon.setRequestProperty("Content-Type", "text/xml");
            mcon.setRequestProperty("Content-length", String.valueOf(xmlS.length()));
            mcon.setDoOutput(true);
            java.io.OutputStream outs = mcon.getOutputStream();
            outs.write(xmlS.getBytes("UTF-8"));
            outs.close();
            java.io.BufferedReader inps = new java.io.BufferedReader(new java.io.InputStreamReader(mcon.getInputStream()));
            StringBuffer respSB = new StringBuffer("");
            String s = null;
            while ((s = inps.readLine()) != null) {
                respSB.append(s);
            }
            inps.close();
            String respXML = respSB.toString();
            processReccurentPaymentResponce(respXML);
        } catch (Exception ex) {
            throw new SecurusException(ex);
        }
    }
public void run() {
        try {
            URL url = new URL("http://www.sourceforge.net/projects/beobachter/files/beobachter_version.html");
            InputStreamReader reader = new InputStreamReader(url.openStream());
            BufferedReader buffer = new BufferedReader(reader);
            String version = buffer.readLine();
            buffer.close();
            reader.close();
            int serverVersion = Integer.valueOf(version.replaceAll("\\.", "")).intValue();
            int currentVersion = Integer.valueOf(Constants.APP_VERSION.replaceAll("\\.", "")).intValue();
            if (serverVersion > currentVersion) {
                StringBuilder sb = new StringBuilder();
                sb.append(MessageFormat.format(Translator.t("New_version_0_available"), new Object[] { version })).append(Constants.LINE_SEP).append(Constants.LINE_SEP);
                sb.append(Translator.t("Please_visit_us_on_sourceforge")).append(Constants.LINE_SEP);
                DialogFactory.showInformationMessage(MainGUI.instance, sb.toString());
            } else if (serverVersion <= currentVersion) {
                DialogFactory.showInformationMessage(MainGUI.instance, Translator.t("There_are_not_updates_available"));
            }
        } catch (Exception e) {
            DialogFactory.showErrorMessage(MainGUI.instance, Translator.t("Unable_to_fetch_server_information"));
        }
    }
public MemoryTextBody(InputStream is, String mimeCharset) throws IOException {
        this.mimeCharset = mimeCharset;
        TempPath tempPath = TempStorage.getInstance().getRootTempPath();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        IOUtils.copy(is, out);
        out.close();
        tempFile = out.toByteArray();
    }
private String md5Digest(String plain) throws Exception {
        MessageDigest digest = MessageDigest.getInstance("MD5");
        digest.update(plain.trim().getBytes());
        byte pwdDigest[] = digest.digest();
        StringBuilder md5buffer = new StringBuilder();
        for (int i = 0; i < pwdDigest.length; i++) {
            int number = 0xFF & pwdDigest[i];
            if (number <= 0xF) {
                md5buffer.append('0');
            }
            md5buffer.append(Integer.toHexString(number));
        }
        return md5buffer.toString();
    }
public static String getETag(final String uri, final long lastModified) {
        try {
            final MessageDigest dg = MessageDigest.getInstance("MD5");
            dg.update(uri.getBytes("utf-8"));
            dg.update(new byte[] { (byte) ((lastModified >> 24) & 0xFF), (byte) ((lastModified >> 16) & 0xFF), (byte) ((lastModified >> 8) & 0xFF), (byte) (lastModified & 0xFF) });
            return CBASE64Codec.encode(dg.digest());
        } catch (final Exception ignore) {
            return uri + lastModified;
        }
    }
public static void copyFileChannel(File src, File dst, boolean preserveModificationTime) throws IOException {
        FileChannel inputChannel = null;
        FileChannel outputChannel = null;
        long length = 0;
        try {
            inputChannel = new FileInputStream(src).getChannel();
            length = inputChannel.size();
            outputChannel = new FileOutputStream(dst).getChannel();
            long total = 0;
            while (total < length) {
                total += inputChannel.transferTo(0, length, outputChannel);
            }
            if (preserveModificationTime) {
                dst.setLastModified(src.lastModified());
            }
        } finally {
            if (inputChannel != null) {
                inputChannel.close();
            }
            if (outputChannel != null) {
                outputChannel.close();
            }
        }
    }
static ConversionMap create(String file) {
        ConversionMap out = new ConversionMap();
        URL url = ConversionMap.class.getResource(file);
        try {
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String line = in.readLine();
            while (line != null) {
                if (line.length() > 0) {
                    String[] arr = line.split("\t");
                    try {
                        double value = Double.parseDouble(arr[1]);
                        out.put(translate(lowercase(arr[0].getBytes())), value);
                        out.defaultValue += value;
                        out.length = arr[0].length();
                    } catch (NumberFormatException e) {
                        throw new RuntimeException("Something is wrong with in conversion file: " + e);
                    }
                }
                line = in.readLine();
            }
            in.close();
            out.defaultValue /= Math.pow(4, out.length);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("Their was an error while reading the conversion map: " + e);
        }
        return out;
    }
public Vocabulary build(String url) {
        HttpGet get = new HttpGet(url);
        try {
            HttpResponse response = client.execute(get);
            HttpEntity entity = response.getEntity();
            if (entity != null) {
                InputStream is = entity.getContent();
                try {
                    Vocabulary tv = build(is);
                    LOG.info("Successfully parsed Thesaurus: " + tv.getTitle());
                    return tv;
                } catch (SAXException e) {
                    LOG.error("Unable to parse XML for extension: " + e.getMessage(), e);
                } finally {
                    is.close();
                }
                entity.consumeContent();
            }
        } catch (Exception e) {
            LOG.error(e);
        }
        return null;
    }
private void init() throws IOException {
        JarInputStream jis = new JarInputStream(new BufferedInputStream(url.openStream()));
        try {
            do {
                ZipEntry ze = jis.getNextEntry();
                if (ze == null) {
                    break;
                }
                if (!ze.isDirectory()) {
                    entries.add(ze.getName());
                }
            } while (true);
        } finally {
            jis.close();
        }
    }
public InputStream getEntry(String entryPath) throws IOException {
        if (!entries.contains(entryPath)) {
            return null;
        }
        JarInputStream jis = new JarInputStream(new BufferedInputStream(url.openStream()));
        do {
            ZipEntry ze = jis.getNextEntry();
            if (ze == null) {
                break;
            }
            if (ze.getName().equals(entryPath)) {
                return jis;
            }
        } while (true);
        assert (false);
        return null;
    }
public InputStream getConfResourceAsInputStream(String name) {
        try {
            URL url = getResource(name);
            if (url == null) {
                LOG.info(name + " not found");
                return null;
            } else {
                LOG.info("found resource " + name + " at " + url);
            }
            return url.openStream();
        } catch (Exception e) {
            return null;
        }
    }
public Reader getConfResourceAsReader(String name) {
        try {
            URL url = getResource(name);
            if (url == null) {
                LOG.info(name + " not found");
                return null;
            } else {
                LOG.info("found resource " + name + " at " + url);
            }
            return new InputStreamReader(url.openStream());
        } catch (Exception e) {
            return null;
        }
    }
@Override
    public CelShadingModel loadModel(URL url, String skin) throws IOException, IncorrectFormatException, ParsingErrorException {
        boolean baseURLWasNull = setBaseURLFromModelURL(url);
        CelShadingModel model = loadModel(url.openStream(), skin);
        if (baseURLWasNull) {
            popBaseURL();
        }
        return (model);
    }
public String getHash(String key, boolean base64) throws Exception {
        MessageDigest md = MessageDigest.getInstance("SHA");
        md.update(key.getBytes());
        if (base64) return new String(new Base64().encode(md.digest()), "UTF8"); else return new String(md.digest(), "UTF8");
    }
public static byte[] post(String path, Map<String, String> params, String encode) throws Exception {
        StringBuilder parambuilder = new StringBuilder("");
        if (params != null && !params.isEmpty()) {
            for (Map.Entry<String, String> entry : params.entrySet()) {
                parambuilder.append(entry.getKey()).append("=").append(URLEncoder.encode(entry.getValue(), encode)).append("&");
            }
            parambuilder.deleteCharAt(parambuilder.length() - 1);
        }
        byte[] data = parambuilder.toString().getBytes();
        URL url = new URL(path);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setDoOutput(true);
        conn.setUseCaches(false);
        conn.setConnectTimeout(5 * 1000);
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Accept", "image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*");
        conn.setRequestProperty("Accept-Language", "zh-CN");
        conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)");
        conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        conn.setRequestProperty("Content-Length", String.valueOf(data.length));
        conn.setRequestProperty("Connection", "Keep-Alive");
        DataOutputStream outStream = new DataOutputStream(conn.getOutputStream());
        outStream.write(data);
        outStream.flush();
        outStream.close();
        if (conn.getResponseCode() == 200) {
            return StreamTool.readInputStream(conn.getInputStream());
        }
        return null;
    }
private String xifraPassword() throws Exception {
        String password2 = instance.getUsuaris().getPassword2();
        MessageDigest m = MessageDigest.getInstance("MD5");
        m.update(password2.getBytes(), 0, password2.length());
        password2 = new BigInteger(1, m.digest()).toString(16);
        return password2;
    }
public void testCreateNewXMLFile() throws InvalidNodeTypeDefException, ParseException, Exception {
        JCRNodeSource emptySource = loadTestSource();
        assertEquals(false, emptySource.exists());
        OutputStream sourceOut = emptySource.getOutputStream();
        assertNotNull(sourceOut);
        InputStream contentIn = getClass().getResourceAsStream(CONTENT_FILE);
        try {
            IOUtils.copy(contentIn, sourceOut);
            sourceOut.flush();
        } finally {
            sourceOut.close();
            contentIn.close();
        }
        InputStream expected = getClass().getResourceAsStream(CONTENT_FILE);
        JCRNodeSource persistentSource = loadTestSource();
        assertEquals(true, persistentSource.exists());
        InputStream actual = persistentSource.getInputStream();
        try {
            assertTrue(isXmlEqual(expected, actual));
        } finally {
            expected.close();
            actual.close();
        }
        JCRNodeSource tmpSrc = (JCRNodeSource) resolveSource(BASE_URL + "users/alexander.saar");
        persistentSource.delete();
        tmpSrc.delete();
    }
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
            String resource = schemaMapping.get(systemId);
            if (resource != null) {
                URL url = getClass().getClassLoader().getResource(resource);
                return new InputSource(url.openStream());
            }
            return null;
        }
public boolean receiveFile(FileDescriptor fileDescriptor) {
        try {
            byte[] block = new byte[1024];
            int sizeRead = 0;
            int totalRead = 0;
            File dir = new File(Constants.DOWNLOAD_DIR + fileDescriptor.getLocation());
            if (!dir.exists()) {
                dir.mkdirs();
            }
            File file = new File(Constants.DOWNLOAD_DIR + fileDescriptor.getLocation() + fileDescriptor.getName());
            if (!file.exists()) {
                file.createNewFile();
            }
            SSLSocket sslsocket = getFileTransferConectionConnectMode(ServerAdress.getServerAdress());
            OutputStream fileOut = new FileOutputStream(file);
            InputStream dataIn = sslsocket.getInputStream();
            while ((sizeRead = dataIn.read(block)) >= 0) {
                totalRead += sizeRead;
                fileOut.write(block, 0, sizeRead);
                propertyChangeSupport.firePropertyChange("fileByte", 0, totalRead);
            }
            fileOut.close();
            dataIn.close();
            sslsocket.close();
            if (fileDescriptor.getName().contains(".snapshot")) {
                try {
                    File fileData = new File(Constants.DOWNLOAD_DIR + fileDescriptor.getLocation() + fileDescriptor.getName());
                    File dirData = new File(Constants.PREVAYLER_DATA_DIRETORY + Constants.FILE_SEPARATOR);
                    File destino = new File(dirData, fileData.getName());
                    boolean success = fileData.renameTo(destino);
                    if (!success) {
                        deleteDir(Constants.DOWNLOAD_DIR);
                        return false;
                    }
                    deleteDir(Constants.DOWNLOAD_DIR);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                if (Server.isServerOpen()) {
                    FileChannel inFileChannel = new FileInputStream(file).getChannel();
                    File dirServer = new File(Constants.DOWNLOAD_DIR + fileDescriptor.getLocation());
                    if (!dirServer.exists()) {
                        dirServer.mkdirs();
                    }
                    File fileServer = new File(Constants.DOWNLOAD_DIR + fileDescriptor.getName());
                    if (!fileServer.exists()) {
                        fileServer.createNewFile();
                    }
                    inFileChannel.transferTo(0, inFileChannel.size(), new FileOutputStream(fileServer).getChannel());
                    inFileChannel.close();
                }
            }
            if (totalRead == fileDescriptor.getSize()) {
                return true;
            }
        } catch (Exception e) {
            logger.error("Receive File:", e);
        }
        return false;
    }
public static Properties load(URL url) {
        if (url == null) {
            return new Properties();
        }
        InputStream in = null;
        try {
            in = url.openStream();
            Properties ret = new Properties();
            ret.load(in);
            return ret;
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    LOG.error("Error closing", e);
                }
            }
        }
    }
public I18N(JApplet applet) {
        if (prop != null) return;
        String lang = "en";
        try {
            Properties userProperties = new Properties();
            if (applet != null) {
                URL url = new URL(applet.getCodeBase() + "logicsim.cfg");
                userProperties.load(url.openStream());
            } else {
                userProperties.load(new FileInputStream("logicsim.cfg"));
            }
            if (userProperties.containsKey("language")) lang = userProperties.getProperty("language");
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        prop = new Properties();
        try {
            if (applet != null) {
                URL url = new URL(applet.getCodeBase() + "languages/" + lang + ".txt");
                prop.load(url.openStream());
            } else {
                prop.load(new FileInputStream("languages/" + lang + ".txt"));
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            try {
                if (applet != null) {
                    URL url = new URL(applet.getCodeBase() + "languages/en.txt");
                    prop.load(url.openStream());
                } else {
                    prop.load(new FileInputStream("languages/en.txt"));
                }
            } catch (Exception ex2) {
                JOptionPane.showMessageDialog(null, "Language file languages/en.txt not found.\nPlease run the program from its directory.");
                System.exit(5);
            }
        }
    }
public HttpClient(String urlString, String jsonMessage) throws Exception {
        this.jsonMessage = jsonMessage;
        connection = (HttpURLConnection) (new URL(urlString)).openConnection();
        connection.setDoOutput(true);
        connection.setDoInput(true);
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Content-type", "text/plain");
    }