semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private String getRandomGUID(final boolean secure) {
        MessageDigest md5 = null;
        final StringBuffer sbValueBeforeMD5 = new StringBuffer();
        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
        try {
            final long time = System.currentTimeMillis();
            final long rand;
            if (secure) {
                rand = mySecureRand.nextLong();
            } else {
                rand = myRand.nextLong();
            }
            sbValueBeforeMD5.append(id);
            sbValueBeforeMD5.append(SEMI_COLON);
            sbValueBeforeMD5.append(Long.toString(time));
            sbValueBeforeMD5.append(SEMI_COLON);
            sbValueBeforeMD5.append(Long.toString(rand));
            valueBeforeMD5 = sbValueBeforeMD5.toString();
            md5.update(valueBeforeMD5.getBytes());
            final byte[] array = md5.digest();
            final StringBuffer sb = new StringBuffer();
            for (int j = 0; j < array.length; ++j) {
                final int bufferIndex = array[j] & SHIFT_SPACE;
                if (ZERO_TEST > bufferIndex) sb.append(CHAR_ZERO);
                sb.append(Integer.toHexString(bufferIndex));
            }
            return sb.toString();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
private void copyFile(File src, File dst) throws IOException {
        InputStream in = new FileInputStream(src);
        OutputStream out = new FileOutputStream(dst);
        byte[] buf = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0) out.write(buf, 0, len);
        in.close();
        out.close();
    }
public boolean clonarFichero(String rutaFicheroOrigen, String rutaFicheroDestino) {
        System.out.println("");
        System.out.println("*********** DENTRO DE 'clonarFichero' ***********");
        boolean estado = false;
        try {
            FileInputStream entrada = new FileInputStream(rutaFicheroOrigen);
            FileOutputStream salida = new FileOutputStream(rutaFicheroDestino);
            FileChannel canalOrigen = entrada.getChannel();
            FileChannel canalDestino = salida.getChannel();
            canalOrigen.transferTo(0, canalOrigen.size(), canalDestino);
            entrada.close();
            salida.close();
            estado = true;
        } catch (IOException e) {
            System.out.println("No se encontro el archivo");
            e.printStackTrace();
            estado = false;
        }
        return estado;
    }
public boolean clonarFichero(FileInputStream rutaFicheroOrigen, String rutaFicheroDestino) {
        System.out.println("");
        boolean estado = false;
        try {
            FileOutputStream salida = new FileOutputStream(rutaFicheroDestino);
            FileChannel canalOrigen = rutaFicheroOrigen.getChannel();
            FileChannel canalDestino = salida.getChannel();
            canalOrigen.transferTo(0, canalOrigen.size(), canalDestino);
            rutaFicheroOrigen.close();
            salida.close();
            estado = true;
        } catch (IOException e) {
            System.out.println("No se encontro el archivo");
            e.printStackTrace();
            estado = false;
        }
        return estado;
    }
private HttpURLConnection getRecognizedUrl(SpantusAudioCtx ctx) throws URISyntaxException {
        try {
            URL url = ctx.getRecognizedUrl();
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestProperty("Content-Type", "application/json");
            conn.setDoInput(true);
            conn.setDoOutput(true);
            conn.setRequestMethod("PUT");
            return conn;
        } catch (MalformedURLException e) {
            LOG.error(e);
        } catch (IOException e) {
            LOG.error(e);
        }
        return null;
    }
public synchronized DASMetaData fillInDASMetaData(URL url) throws DASException {
        try {
            con = (HttpURLConnection) url.openConnection();
            dasRespVersion = con.getHeaderField("X-DAS-Version");
            dasSchema = con.getHeaderField("X-DAS-SchemaName");
            dasSchemaVersion = con.getHeaderField("X-DAS-SchemaVersion");
            String dasStatusString = con.getHeaderField("X-DAS-Status");
            if (dasStatusString == null) {
                throw new DASException("Temporary DAS Error");
            }
            if (dasStatusString.indexOf(" ") != -1) {
                dasStatusString = dasStatusString.substring(0, dasStatusString.indexOf(" "));
            }
            dasStatus = Integer.parseInt(dasStatusString);
            if (dasStatus != 200) {
                throw new DASException("Command cannot be executed: Error was " + Integer.toString(dasStatus));
            }
        } catch (IOException e) {
            throw new DASException("Cannot connect to data source");
        }
        if (dasSchema != null && dasSchemaVersion != null) {
            headers.put("X-DAS-Version", dasRespVersion);
            headers.put("X-DAS-SchemaName", dasSchema);
            headers.put("X-DAS-SchemaVersion", dasSchemaVersion);
            dasVersion = Float.parseFloat(dasRespVersion.substring(dasRespVersion.indexOf("/") + 1, dasRespVersion.length()));
            theMetaData = new DASMetaDataImpl(dasVersion, Float.parseFloat(dasSchemaVersion), dasSchema);
        } else {
            dasVersion = Float.parseFloat(dasRespVersion.substring(dasRespVersion.indexOf("/") + 1, dasRespVersion.length()));
            headers.put("X-DAS-Version", dasRespVersion);
            theMetaData = new DASMetaDataImpl(dasVersion);
        }
        String lengthStr = con.getHeaderField("content-length");
        if (lengthStr != null) headers.put("content-length", lengthStr);
        theMetaData.setDASHeaders(headers);
        return theMetaData;
    }
public synchronized void readModels(URL url, XmiExtensionParser xmiExtensionParser) throws OpenException {
        LOG.info("=======================================");
        LOG.info("== READING MODEL " + url);
        try {
            InputSource source = new InputSource(new XmiInputStream(url.openStream(), xmiExtensionParser, 100000, null));
            source.setSystemId(url.toString());
            readModels(source);
        } catch (IOException ex) {
            throw new OpenException(ex);
        }
    }
@Override
    public void run() {
        HttpGet httpGet = null;
        try {
            DefaultHttpClient httpClient = new DefaultHttpClient();
            DataModel model = DataModel.getInstance();
            for (City city : citiesToBeUpdated) {
                String preferredUnitType = PreferenceManager.getDefaultSharedPreferences(context).getString(context.getString(R.string.settings_units_key), context.getString(R.string.settings_units_default_value));
                String codePrefix = city.getCountryName().startsWith("United States") ? GET_PARAM_ZIP_PREFIX : GET_PARAM_CITY_CODE_PREFIX;
                String requestUri = new String(GET_URL + "?" + GET_PARAM_ACODE_PREFIX + "=" + GET_PARAM_ACODE + "&" + codePrefix + "=" + city.getId() + "&" + GET_PARAM_UNIT_PREFIX + "=" + preferredUnitType);
                httpGet = new HttpGet(requestUri);
                HttpResponse response = httpClient.execute(httpGet);
                if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                    processXML(response.getEntity().getContent());
                    for (ForecastedDay day : forecast) {
                        int pos = day.getImageURL().lastIndexOf('/');
                        if (pos < 0 || pos + 1 == day.getImageURL().length()) throw new Exception("Invalid image URL");
                        final String imageFilename = day.getImageURL().substring(pos + 1);
                        File downloadDir = context.getDir(ForecastedDay.DOWNLOAD_DIR, Context.MODE_PRIVATE);
                        File[] imagesFilteredByName = downloadDir.listFiles(new FilenameFilter() {

                            @Override
                            public boolean accept(File dir, String filename) {
                                if (filename.equals(imageFilename)) return true; else return false;
                            }
                        });
                        if (imagesFilteredByName.length == 0) {
                            httpGet = new HttpGet(day.getImageURL());
                            response = httpClient.execute(httpGet);
                            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                                BufferedOutputStream bus = null;
                                try {
                                    bus = new BufferedOutputStream(new FileOutputStream(downloadDir.getAbsolutePath() + "/" + imageFilename));
                                    response.getEntity().writeTo(bus);
                                } finally {
                                    bus.close();
                                }
                            }
                        }
                    }
                    city.setDays(forecast);
                    city.setLastUpdated(Calendar.getInstance().getTime());
                    model.saveCity(city);
                }
            }
        } catch (Exception e) {
            httpGet.abort();
            e.printStackTrace();
        } finally {
            handler.sendEmptyMessage(1);
        }
    }
private void sendActionPerformed(java.awt.event.ActionEvent evt) {
        if (name.getText().length() < 3) {
            JOptionPane.showMessageDialog(comment, "Too short name (at least 3)");
            return;
        }
        if (comment.getText().length() < 10) {
            JOptionPane.showMessageDialog(comment, "Too short comment (at least 10)");
            return;
        }
        Thread t = new Thread(new Runnable() {

            public void run() {
                try {
                    String data = URLEncoder.encode("send_id", "UTF-8") + "=" + URLEncoder.encode("1", "UTF-8");
                    data += "&" + URLEncoder.encode("author", "UTF-8") + "=" + URLEncoder.encode(name.getText(), "UTF-8");
                    data += "&" + URLEncoder.encode("location", "UTF-8") + "=" + URLEncoder.encode(System.getProperty("user.language"), "UTF-8");
                    data += "&" + URLEncoder.encode("contact", "UTF-8") + "=" + URLEncoder.encode(email.getText(), "UTF-8");
                    data += "&" + URLEncoder.encode("content", "UTF-8") + "=" + URLEncoder.encode(comment.getText(), "UTF-8");
                    data += "&" + URLEncoder.encode("rate", "UTF-8") + "=" + URLEncoder.encode(rate.getSelectedItem().toString(), "UTF-8");
                    System.out.println(data);
                    URL url = new URL("http://javablock.sourceforge.net/book/index.php");
                    URLConnection conn = url.openConnection();
                    conn.setDoOutput(true);
                    OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
                    wr.write(data);
                    wr.flush();
                    BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                    String address = rd.readLine();
                    JPanel panel = new JPanel();
                    panel.add(new JLabel("Comment added"));
                    panel.add(new JTextArea("visit: http://javablock.sourceforge.net/"));
                    JOptionPane.showMessageDialog(null, new JLabel("Comment sended correctly!"));
                    wr.close();
                    rd.close();
                    hide();
                } catch (IOException ex) {
                    Logger.getLogger(guestBook.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
        t.start();
    }
public void run() {
                try {
                    String data = URLEncoder.encode("send_id", "UTF-8") + "=" + URLEncoder.encode("1", "UTF-8");
                    data += "&" + URLEncoder.encode("author", "UTF-8") + "=" + URLEncoder.encode(name.getText(), "UTF-8");
                    data += "&" + URLEncoder.encode("location", "UTF-8") + "=" + URLEncoder.encode(System.getProperty("user.language"), "UTF-8");
                    data += "&" + URLEncoder.encode("contact", "UTF-8") + "=" + URLEncoder.encode(email.getText(), "UTF-8");
                    data += "&" + URLEncoder.encode("content", "UTF-8") + "=" + URLEncoder.encode(comment.getText(), "UTF-8");
                    data += "&" + URLEncoder.encode("rate", "UTF-8") + "=" + URLEncoder.encode(rate.getSelectedItem().toString(), "UTF-8");
                    System.out.println(data);
                    URL url = new URL("http://javablock.sourceforge.net/book/index.php");
                    URLConnection conn = url.openConnection();
                    conn.setDoOutput(true);
                    OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
                    wr.write(data);
                    wr.flush();
                    BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                    String address = rd.readLine();
                    JPanel panel = new JPanel();
                    panel.add(new JLabel("Comment added"));
                    panel.add(new JTextArea("visit: http://javablock.sourceforge.net/"));
                    JOptionPane.showMessageDialog(null, new JLabel("Comment sended correctly!"));
                    wr.close();
                    rd.close();
                    hide();
                } catch (IOException ex) {
                    Logger.getLogger(guestBook.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
public void validateClassPath() {
        try {
            URL[] urls = ((URLClassLoader) classLoader).getURLs();
            for (int i = 0; i < urls.length; i++) {
                try {
                    urls[i].openStream();
                    new DebugWriter().writeMessage(urls[i].getFile() + "\n");
                } catch (IllegalArgumentException iae) {
                    throw new LinkageError("malformed class path url:\n " + urls[i]);
                } catch (IOException ioe) {
                    throw new LinkageError("invalid class path url:\n " + urls[i]);
                }
            }
        } catch (ClassCastException e) {
            throw new IllegalArgumentException("The current VM's System classloader is not a " + "subclass of java.net.URLClassLoader");
        }
    }
private static BufferedInputStream getHTTPConnection(String sUrl) {
        URL url = null;
        BufferedInputStream bis = null;
        try {
            url = new URL(sUrl);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("GET");
            connection.setDoOutput(true);
            connection.setConnectTimeout(30000);
            connection.setReadTimeout(60000);
            connection.setRequestProperty("Accept-Encoding", "gzip, deflate");
            connection.connect();
            String encoding = connection.getContentEncoding();
            if (!Utilities.isEmpty(encoding) && "gzip".equalsIgnoreCase(encoding)) {
                bis = new BufferedInputStream(new GZIPInputStream(connection.getInputStream()), IO_BUFFER_SIZE);
            } else if (!Utilities.isEmpty(encoding) && "deflate".equalsIgnoreCase(encoding)) {
                bis = new BufferedInputStream(new InflaterInputStream(connection.getInputStream(), new Inflater(true)), IO_BUFFER_SIZE);
            } else {
                bis = new BufferedInputStream(connection.getInputStream(), IO_BUFFER_SIZE);
            }
        } catch (Exception e) {
            LogUtil.e(Constants.TAG, e.getMessage());
        }
        return bis;
    }
public void handler(List<GoldenBoot> gbs, TargetPage target) {
        try {
            URL url = new URL(target.getUrl());
            BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
            String line = null;
            String include = "Top Scorers";
            while ((line = reader.readLine()) != null) {
                if (line.indexOf(include) != -1) {
                    buildGildenBoot(line, gbs);
                    break;
                }
            }
            reader.close();
        } catch (MalformedURLException e) {
        } catch (IOException e) {
        }
    }
private void downloadFile(final String downloadUrl, final String destinationFile) throws IOException {
            HttpClient client = new DefaultHttpClient();
            HttpGet httpGet = new HttpGet(downloadUrl);
            final File outputFile = new File(destinationFile);
            createParentDirectories(outputFile);
            FileOutputStream outputStream;
            outputStream = new FileOutputStream(outputFile);
            final HttpResponse response = client.execute(httpGet);
            if (isInterrupted()) {
                outputStream.close();
                return;
            }
            final HttpEntity entity = response.getEntity();
            InputStream inputStream = null;
            try {
                if (entity != null) {
                    inputStream = entity.getContent();
                    CopyStreamStatusCallback callback = new CopyStreamStatusCallback() {

                        @Override
                        public long getSkipBetweenUpdates() {
                            return entity.getContentLength() * 2 / PERCENTAGE_BASE;
                        }

                        @Override
                        public void onUpdate(final long copiedLength) {
                            int percentage = (int) (copiedLength * PERCENTAGE_BASE / entity.getContentLength());
                            handleUpdate(STATUS_DOWNLOADING, percentage);
                        }
                    };
                    copyStreams(inputStream, outputStream, callback);
                }
            } finally {
                try {
                    outputStream.close();
                    if (inputStream != null) {
                        inputStream.close();
                    }
                } catch (IOException e) {
                    Log.v(DictionaryForMIDs.LOG_TAG, "Exception while closing stream: " + e);
                }
            }
        }
public static synchronized String hash(String data) {
        if (digest == null) {
            try {
                digest = MessageDigest.getInstance("MD5");
            } catch (NoSuchAlgorithmException nsae) {
            }
        }
        try {
            digest.update(data.getBytes("utf-8"));
        } catch (UnsupportedEncodingException e) {
        }
        return encodeHex(digest.digest());
    }
private void getRandomGUID(boolean secure) {
        MessageDigest md5 = null;
        StringBuffer sbValueBeforeMD5 = new StringBuffer();
        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            logger.debug("Random GUID error: " + e.getMessage());
        }
        try {
            long time = System.currentTimeMillis();
            long rand = 0;
            if (secure) {
                rand = mySecureRand.nextLong();
            } else {
                rand = myRand.nextLong();
            }
            sbValueBeforeMD5.append(s_id);
            sbValueBeforeMD5.append(":");
            sbValueBeforeMD5.append(Long.toString(time));
            sbValueBeforeMD5.append(":");
            sbValueBeforeMD5.append(Long.toString(rand));
            valueBeforeMD5 = sbValueBeforeMD5.toString();
            md5.update(valueBeforeMD5.getBytes());
            byte[] array = md5.digest();
            StringBuffer sb = new StringBuffer();
            for (int j = 0; j < array.length; ++j) {
                int b = array[j] & 0xFF;
                if (b < 0x10) sb.append('0');
                sb.append(Integer.toHexString(b));
            }
            valueAfterMD5 = sb.toString();
        } catch (Exception e) {
            System.out.println("Error:" + e);
        }
    }
private static synchronized boolean doCopyFile(File srcFile, File destFile, boolean preserveFileDate) throws IOException {
        if (destFile.exists() && destFile.isDirectory()) {
            destFile = new File(destFile + FILE_SEPARATOR + srcFile.getName());
        }
        FileInputStream input = new FileInputStream(srcFile);
        try {
            FileOutputStream output = new FileOutputStream(destFile);
            try {
                IOUtils.copy(input, output);
            } finally {
                IOUtils.closeQuietly(output);
            }
        } finally {
            IOUtils.closeQuietly(input);
        }
        if (srcFile.length() != destFile.length()) {
            throw new IOException("Failed to copy full contents from '" + srcFile + "' to '" + destFile + "'");
        }
        if (preserveFileDate) {
            destFile.setLastModified(srcFile.lastModified());
        }
        return destFile.exists();
    }
private void createButtonCopyToClipboard() {
        buttonCopyToClipboard = new Button(shell, SWT.PUSH);
        buttonCopyToClipboard.setText("Co&py to Clipboard");
        buttonCopyToClipboard.setLayoutData(SharedStyle.relativeToBottomRight(buttonClose));
        buttonCopyToClipboard.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(final SelectionEvent event) {
                IOUtils.copyToClipboard(Version.getEnvironmentReport());
            }
        });
    }
public SequenceIterator call(SequenceIterator[] arguments, XPathContext context) throws XPathException {
            try {
                String encodedString = ((StringValue) arguments[0].next()).getStringValue();
                byte[] decodedBytes = Base64.decode(encodedString);
                if (arguments.length > 1 && ((BooleanValue) arguments[1].next()).getBooleanValue()) {
                    ByteArrayInputStream bis = new ByteArrayInputStream(decodedBytes);
                    GZIPInputStream zis = new GZIPInputStream(bis);
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    IOUtils.copy(zis, baos);
                    decodedBytes = baos.toByteArray();
                }
                Document doc = XmlUtils.stringToDocument(new String(decodedBytes, "UTF-8"));
                Source source = new DOMSource(doc.getDocumentElement());
                XPathEvaluator evaluator = new XPathEvaluator(context.getConfiguration());
                NodeInfo[] infos = new NodeInfo[] { evaluator.setSource(source) };
                return new ArrayIterator(infos);
            } catch (Exception e) {
                throw new XPathException("Could not base64 decode string", e);
            }
        }
public void refreshStatus() {
        if (!enabledDisplay) return;
        try {
            String url = getServerFortURL();
            BufferedReader reader = new BufferedReader(new InputStreamReader(new URL(url).openStream()));
            String data = null;
            int counter = 0;
            while ((data = reader.readLine()) != null && counter < 9) {
                status[counter] = UNKNOWN;
                if (data.matches(".*_alsius.gif.*")) {
                    status[counter] = ALSIUS;
                    counter++;
                }
                if (data.matches(".*_syrtis.gif.*")) {
                    status[counter] = SYRTIS;
                    counter++;
                }
                if (data.matches(".*_ignis.gif.*")) {
                    status[counter] = IGNIS;
                    counter++;
                }
            }
        } catch (Exception exc) {
            for (int i = 0; i < status.length; i++) status[i] = UNKNOWN;
        }
    }