semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static String encryptPassword(String username, String realm, String password) throws GeneralSecurityException {
        MessageDigest md = null;
        md = MessageDigest.getInstance("MD5");
        md.update(username.getBytes());
        md.update(":".getBytes());
        md.update(realm.getBytes());
        md.update(":".getBytes());
        md.update(password.getBytes());
        byte[] hash = md.digest();
        return toHex(hash, hash.length);
    }
public static boolean doTest(Getter<?> context, Document node) {
        try {
            URL url = new URL(StringUtil.evaluateEL(Documents.getDocumentValue(node, "url"), context));
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            Assert.isTrue(conn.getResponseCode() < 400);
            conn.disconnect();
            return true;
        } catch (Exception e) {
            return false;
        }
    }
protected void xInitGUI() {
        this.jlHead.setText(formater.getText("select_marc21_title"));
        this.jlResId.setText(formater.getText("select_marc21_label_text"));
        this.jlResId.setToolTipText(formater.getText("select_marc21_label_description"));
        ElvisListModel model = new ElvisListModel();
        this.jlResourceList.setModel(model);
        try {
            URL urlListResources = new URL(ElvisRegistry.getInstance().getProperty("elvis.server") + "/servlet/listResources?xpath=document()//Book");
            InputStream streamResources = urlListResources.openStream();
            XmlPullParser xpp = XmlPullParserFactory.newInstance().newPullParser();
            xpp.setInput(new InputStreamReader(streamResources));
            int type = xpp.getEventType();
            while (type != XmlPullParser.END_DOCUMENT) {
                if (type == XmlPullParser.START_TAG && "Resource".equals(xpp.getName())) {
                    model.add(xpp.getAttributeValue("", "resId"), xpp.getAttributeValue("", "author"), xpp.getAttributeValue("", "title"));
                }
                type = xpp.next();
            }
            streamResources.close();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        } catch (XmlPullParserException xppe) {
            xppe.printStackTrace();
        }
        ListSelectionModel selectionModel = this.jlResourceList.getSelectionModel();
        selectionModel.addListSelectionListener(new ListSelectionListener() {

            /**
				 * @param  e  Description of the Parameter
				 * @see       javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
				 */
            public void valueChanged(ListSelectionEvent e) {
                int index = e.getFirstIndex();
                boolean isAdjusting = e.getValueIsAdjusting();
                if (!isAdjusting) {
                    ElvisListModel _model = (ElvisListModel) jlResourceList.getModel();
                    jtfResId.setText(_model.get(index).getId());
                }
            }
        });
    }
private static void getFileFtp(String user, String password, String host, int port, String fileName, String location) throws Exception {
        Log.info("\nretrieve " + fileName + NEW_LINE);
        FTPClient client = new FTPClient();
        client.connect(host, port);
        int reply = client.getReplyCode();
        if (!FTPReply.isPositiveCompletion(reply)) {
            throw new Exception("FTP fail to connect");
        }
        if (!client.login(user, password)) {
            throw new Exception("FTP fail to login");
        }
        try {
            File locationFile = new File(location);
            File dest = new File(locationFile, fileName);
            if (dest.exists()) {
                dest.delete();
            } else {
                locationFile.mkdirs();
            }
            boolean status = client.changeWorkingDirectory("/");
            Log.info("chdir-status:" + status + NEW_LINE);
            client.setFileTransferMode(FTPClient.BINARY_FILE_TYPE);
            client.setFileType(FTPClient.BINARY_FILE_TYPE);
            client.enterLocalActiveMode();
            InputStream in = client.retrieveFileStream(fileName);
            if (in == null) {
                Log.error("Input stream is null\n");
                throw new Exception("Fail to retrieve file " + fileName);
            }
            Thread.sleep(3000);
            saveInputStreamToFile(in, new File(location, fileName));
        } finally {
            client.disconnect();
        }
    }
public static void copyFile(String src, String target) throws IOException {
        FileChannel ic = new FileInputStream(src).getChannel();
        FileChannel oc = new FileOutputStream(target).getChannel();
        ic.transferTo(0, ic.size(), oc);
        ic.close();
        oc.close();
    }
public static String digest(String text, String algorithm, String charsetName) {
        try {
            MessageDigest md = MessageDigest.getInstance(algorithm);
            md.update(text.getBytes(charsetName), 0, text.length());
            return convertToHex(md.digest());
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException("unexpected exception: " + e, e);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("unexpected exception: " + e, e);
        }
    }
private String callPage(String urlStr) throws IOException {
        URL url = new URL(urlStr);
        BufferedReader reader = null;
        StringBuilder result = new StringBuilder();
        try {
            reader = new BufferedReader(new InputStreamReader(url.openStream()));
            String line;
            while ((line = reader.readLine()) != null) {
                result.append(line);
            }
        } finally {
            if (reader != null) reader.close();
        }
        return result.toString();
    }
public static Image getPluginImage(Object plugin, String name) {
        try {
            try {
                URL url = getPluginImageURL(plugin, name);
                if (mURLImageMap.containsKey(url)) {
                    return mURLImageMap.get(url);
                }
                InputStream is = url.openStream();
                Image image;
                try {
                    image = getImage(is);
                    mURLImageMap.put(url, image);
                } finally {
                    is.close();
                }
                return image;
            } catch (Throwable e) {
                LOG.debug("Ignore any exceptions");
            }
        } catch (Throwable e) {
            LOG.debug("Ignore any exceptions");
        }
        return null;
    }
public static void processString(String text) throws Exception {
        MessageDigest md5 = MessageDigest.getInstance(MD5_DIGEST);
        md5.reset();
        md5.update(text.getBytes());
        displayResult(null, md5.digest());
    }
public void process(String t) {
        try {
            MessageDigest md5 = MessageDigest.getInstance(MD5_DIGEST);
            md5.reset();
            md5.update(t.getBytes());
            callback.display(null, digestToHexString(md5.digest()));
        } catch (Exception ex) {
            callback.display(null, "[failed]");
        }
    }
private void save() {
        int[] selection = list.getSelectionIndices();
        String dir = System.getProperty("user.dir");
        for (int i = 0; i < selection.length; i++) {
            File src = files[selection[i]];
            FileDialog dialog = new FileDialog(shell, SWT.SAVE);
            dialog.setFilterPath(dir);
            dialog.setFileName(src.getName());
            String destination = dialog.open();
            if (destination != null) {
                File dest = new File(destination);
                try {
                    dest.createNewFile();
                    FileChannel srcC = new FileInputStream(src).getChannel();
                    FileChannel destC = new FileOutputStream(dest).getChannel();
                    destC.transferFrom(srcC, 0, srcC.size());
                    destC.close();
                    srcC.close();
                    updateSaved(selection[i], true);
                    files[selection[i]] = dest;
                } catch (FileNotFoundException e) {
                    IVC.showError("Error!", "" + e.getMessage(), "");
                } catch (IOException e) {
                    IVC.showError("Error!", "" + e.getMessage(), "");
                }
            }
        }
    }
public static void main(String[] args) {
        if (args.length == 0) {
            System.out.println("Usage: java xyzImpl inputfile");
            System.exit(0);
        }
        XYZ xyz = null;
        try {
            URL url = new URL(Util.makeAbsoluteURL(args[0]));
            BufferedReader bReader = new BufferedReader(new InputStreamReader(url.openStream()));
            int idx = args[0].indexOf(".");
            String id = (idx == -1) ? args[0] : args[0].substring(0, idx);
            idx = id.lastIndexOf("\\");
            if (idx != -1) id = id.substring(idx + 1);
            xyz = new XYZImpl(bReader, id);
            CMLMolecule mol = xyz.getMolecule();
            StringWriter sw = new StringWriter();
            mol.debug(sw);
            System.out.println(sw.toString());
            SpanningTree sTree = new SpanningTreeImpl(mol);
            System.out.println(sTree.toSMILES());
            Writer w = new OutputStreamWriter(new FileOutputStream(id + ".xml"));
            PMRDelegate.outputEventStream(mol, w, PMRNode.PRETTY, 0);
            w.close();
            w = new OutputStreamWriter(new FileOutputStream(id + "-new.mol"));
            xyz.setOutputCMLMolecule(mol);
            xyz.output(w);
            w.close();
        } catch (Exception e) {
            System.out.println("xyz failed: " + e);
            e.printStackTrace();
            System.exit(0);
        }
    }
public static void bubbleSort(Drawable[] list) {
        boolean swapped;
        do {
            swapped = false;
            for (int i = 0; i < list.length - 1; ++i) {
                if (list[i].getSortValue() > list[i + 1].getSortValue()) {
                    Drawable temp = list[i];
                    list[i] = list[i + 1];
                    list[i + 1] = temp;
                    swapped = true;
                }
            }
        } while (swapped);
    }
private List<String> readUrl(URL url) throws IOException {
        List<String> lines = new ArrayList<String>();
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        String str;
        while ((str = in.readLine()) != null) {
            lines.add(str);
        }
        in.close();
        return lines;
    }
public static boolean copyFile(File sourceFile, File destinationFile) {
        boolean copySuccessfull = false;
        FileChannel source = null;
        FileChannel destination = null;
        try {
            source = new FileInputStream(sourceFile).getChannel();
            destination = new FileOutputStream(destinationFile).getChannel();
            long transferedBytes = destination.transferFrom(source, 0, source.size());
            copySuccessfull = transferedBytes == source.size() ? true : false;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (source != null) {
                try {
                    source.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (destination != null) {
                try {
                    destination.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return copySuccessfull;
    }
private static final void copyFile(File srcFile, File destDir, byte[] buffer) {
        try {
            File destFile = new File(destDir, srcFile.getName());
            InputStream in = new FileInputStream(srcFile);
            OutputStream out = new FileOutputStream(destFile);
            int bytesRead;
            while ((bytesRead = in.read(buffer)) != -1) out.write(buffer, 0, bytesRead);
            in.close();
            out.close();
        } catch (IOException ioe) {
            System.err.println("Couldn't copy file '" + srcFile + "' to directory '" + destDir + "'");
        }
    }
public void run() throws Exception {
        logger.debug("#run enter");
        PreparedStatement psNextId = null;
        ResultSet rsNextId = null;
        PreparedStatement ps = null;
        try {
            PreparedStatement psCount = connection.prepareStatement(COUNT_ACTIVE_ORDERS);
            psCount.setString(1, login);
            ResultSet rsCount = psCount.executeQuery();
            if (rsCount.next()) {
                Integer count = rsCount.getInt(1);
                if (count > 0) {
                    DBHelper.closeAll(null, rsCount, psCount);
                    throw new RuntimeException("У вас уже есть один активный заказ. Вы не можете создать второй.");
                }
            }
            connection.setAutoCommit(false);
            psNextId = connection.prepareStatement(NEXT_ORDER);
            rsNextId = psNextId.executeQuery();
            if (rsNextId.next()) {
                orderId = rsNextId.getInt(1);
            }
            rsNextId.close();
            psNextId.close();
            logger.info("#run orderId  = " + orderId);
            ps = connection.prepareStatement(INSERT_ORDER);
            ps.setInt(1, orderId);
            if (order.getCustomerId() != null) {
                ps.setInt(2, order.getCustomerId());
            } else {
                ps.setNull(2, Types.INTEGER);
            }
            ps.setString(3, order.getSellerLogin());
            ps.executeUpdate();
            ps.close();
            logger.info("#run order insert OK");
            Iterator<OrderLine> lines = order.getLines().iterator();
            while (lines.hasNext()) {
                OrderLine line = lines.next();
                CreateOrderLineAction action = new CreateOrderLineAction();
                action.execute(connection, orderId, line);
            }
            connection.commit();
        } catch (SQLException ex) {
            logger.error("SQLException", ex);
            connection.rollback();
            throw new Exception("Не удалось создать заказ. Ошибка : " + ex.getMessage());
        } finally {
            connection.setAutoCommit(true);
        }
        logger.debug("#run exit");
    }
public ImageData getJPEGDiagram() {
        Shell shell = new Shell();
        GraphicalViewer viewer = new ScrollingGraphicalViewer();
        viewer.createControl(shell);
        viewer.setEditDomain(new DefaultEditDomain(null));
        viewer.setRootEditPart(new ScalableFreeformRootEditPart());
        viewer.setEditPartFactory(new CsdeEditPartFactory());
        viewer.setContents(getDiagram());
        viewer.flush();
        LayerManager lm = (LayerManager) viewer.getEditPartRegistry().get(LayerManager.ID);
        IFigure fig = lm.getLayer(LayerConstants.PRINTABLE_LAYERS);
        Dimension d = fig.getSize();
        Image image = new Image(null, d.width, d.height);
        GC tmpGC = new GC(image);
        SWTGraphics graphics = new SWTGraphics(tmpGC);
        fig.paint(graphics);
        shell.dispose();
        return image.getImageData();
    }
public void run(Preprocessor pp) throws SijappException {
        for (int i = 0; i < this.filenames.length; i++) {
            File srcFile = new File(this.srcDir, this.filenames[i]);
            BufferedReader reader;
            try {
                InputStreamReader isr = new InputStreamReader(new FileInputStream(srcFile), "CP1251");
                reader = new BufferedReader(isr);
            } catch (Exception e) {
                throw (new SijappException("File " + srcFile.getPath() + " could not be read"));
            }
            File destFile = new File(this.destDir, this.filenames[i]);
            BufferedWriter writer;
            try {
                (new File(destFile.getParent())).mkdirs();
                OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(destFile), "CP1251");
                writer = new BufferedWriter(osw);
            } catch (Exception e) {
                throw (new SijappException("File " + destFile.getPath() + " could not be written"));
            }
            try {
                pp.run(reader, writer);
            } catch (SijappException e) {
                try {
                    reader.close();
                } catch (IOException f) {
                }
                try {
                    writer.close();
                } catch (IOException f) {
                }
                try {
                    destFile.delete();
                } catch (SecurityException f) {
                }
                throw (new SijappException(srcFile.getPath() + ":" + e.getMessage()));
            }
            try {
                reader.close();
            } catch (IOException e) {
            }
            try {
                writer.close();
            } catch (IOException e) {
            }
        }
    }
public static String getHashedPassword(String password) {
        try {
            MessageDigest digest = MessageDigest.getInstance("MD5");
            digest.update(password.getBytes());
            BigInteger hashedInt = new BigInteger(1, digest.digest());
            return String.format("%1$032X", hashedInt);
        } catch (NoSuchAlgorithmException nsae) {
            System.err.println(nsae.getMessage());
        }
        return "";
    }
private synchronized void resetUserDictionary() {
        if (this.fChecker == null) return;
        if (this.fUserDictionary != null) {
            this.fChecker.removeDictionary(this.fUserDictionary);
            this.fUserDictionary.unload();
            this.fUserDictionary = null;
        }
        IPreferenceStore store = SpellActivator.getDefault().getPreferenceStore();
        String filePath = store.getString(PreferenceConstants.SPELLING_USER_DICTIONARY);
        IStringVariableManager variableManager = VariablesPlugin.getDefault().getStringVariableManager();
        try {
            filePath = variableManager.performStringSubstitution(filePath);
        } catch (CoreException e) {
            SpellActivator.log(e);
            return;
        }
        if (filePath.length() > 0) {
            try {
                File file = new File(filePath);
                if (!file.exists() && !file.createNewFile()) return;
                final URL url = new URL("file", null, filePath);
                InputStream stream = url.openStream();
                if (stream != null) {
                    try {
                        this.fUserDictionary = new PersistentSpellDictionary(url);
                        this.fChecker.addDictionary(this.fUserDictionary);
                    } finally {
                        stream.close();
                    }
                }
            } catch (MalformedURLException exception) {
            } catch (IOException exception) {
            }
        }
    }
public void transform(File inputMatrixFile, MatrixIO.Format inputFormat, File outputMatrixFile) throws IOException {
        FileChannel original = new FileInputStream(inputMatrixFile).getChannel();
        FileChannel copy = new FileOutputStream(outputMatrixFile).getChannel();
        copy.transferFrom(original, 0, original.size());
        original.close();
        copy.close();
    }
public long getMD5Hash(String str) {
        MessageDigest m = null;
        try {
            m = MessageDigest.getInstance("SHA-256");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        m.update(str.getBytes(), 0, str.length());
        return new BigInteger(1, m.digest()).longValue();
    }
public Void doInBackground() {
        Transferable clipData = clipboard.getContents(this);
        File file = new File("Videos/" + (mp3.getArtist() + " - " + mp3.getTitle() + ".jpg").replace("/", "").replace("\\", ""));
        try {
            String test = (String) (clipData.getTransferData(DataFlavor.stringFlavor));
            String testje = test.toLowerCase();
            if (testje.indexOf(".flv") > 0 || testje.indexOf(".wmv") > 0 || testje.indexOf(".mpg") > 0 || testje.indexOf(".mpeg") > 0 || testje.indexOf(".avi") > 0 || testje.indexOf(".avi") > 0 || testje.indexOf(".divx") > 0 || testje.indexOf(".avi") > 0) {
                URL url = new URL(test);
                (new File("Videos/")).mkdirs();
                System.out.println("Saving video to " + file);
                try {
                    URLConnection urlC = url.openConnection();
                    InputStream is = url.openStream();
                    System.out.flush();
                    FileOutputStream fos = null;
                    fos = new FileOutputStream(file);
                    byte[] buf = new byte[32768];
                    int len;
                    while ((len = is.read(buf)) > 0) {
                        fos.write(buf, 0, len);
                    }
                    is.close();
                    fos.close();
                } catch (Exception e) {
                    System.out.println("Error saving video from url: " + url);
                    mp3.setVideo(file.getAbsolutePath());
                }
            }
        } catch (Exception ex) {
            System.out.println("not a valid video file");
            ex.printStackTrace();
        }
        return null;
    }
protected void createDb() {
        File rootFolder = new File(dbFolderPath);
        if (!rootFolder.exists()) {
            rootFolder.mkdirs();
        }
        openConnection();
        try {
            Statement stat = connection.createStatement();
            ResourceBundle bundle = ResourceBundle.getBundle("uTaggerDb");
            for (String key : bundle.keySet()) {
                stat.executeUpdate(bundle.getString(key));
            }
            commit();
        } catch (SQLException e) {
            LOG.warn(e);
            rollback();
        }
    }
public static String exchangeForSessionToken(String protocol, String domain, String onetimeUseToken, PrivateKey key) throws IOException, GeneralSecurityException, AuthenticationException {
        String sessionUrl = getSessionTokenUrl(protocol, domain);
        URL url = new URL(sessionUrl);
        HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
        String header = formAuthorizationHeader(onetimeUseToken, key, url, "GET");
        httpConn.setRequestProperty("Authorization", header);
        if (httpConn.getResponseCode() != HttpURLConnection.HTTP_OK) {
            throw new AuthenticationException(httpConn.getResponseCode() + ": " + httpConn.getResponseMessage());
        }
        String body = CharStreams.toString(new InputStreamReader(httpConn.getInputStream(), Charsets.ISO_8859_1));
        Map<String, String> parsedTokens = StringUtil.string2Map(body, "\n", "=", true);
        parsedTokens = StringUtil.lowercaseKeys(parsedTokens);
        return parsedTokens.get("token");
    }
public static Version getWebRelease(String url) {
        InputStream is = null;
        try {
            is = new URL(url).openStream();
            Reader reader = new InputStreamReader(new BufferedInputStream(is), "UTF-8");
            String word = findWord(reader, "<description>Release:", "</description>").trim();
            if (!isValid(word)) {
                word = "0";
            }
            return new Version(word);
        } catch (Throwable ex) {
            LOGGER.log(Level.WARNING, null, ex);
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException ex) {
                    LOGGER.log(Level.SEVERE, null, ex);
                }
            }
        }
        return null;
    }