semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private boolean passwordMatches(String user, String plainPassword, String scrambledPassword) {
        MessageDigest md;
        byte[] temp_digest, pass_digest;
        byte[] hex_digest = new byte[35];
        byte[] scrambled = scrambledPassword.getBytes();
        try {
            md = MessageDigest.getInstance("MD5");
            md.update(plainPassword.getBytes("US-ASCII"));
            md.update(user.getBytes("US-ASCII"));
            temp_digest = md.digest();
            Utils.bytesToHex(temp_digest, hex_digest, 0);
            md.update(hex_digest, 0, 32);
            md.update(salt.getBytes());
            pass_digest = md.digest();
            Utils.bytesToHex(pass_digest, hex_digest, 3);
            hex_digest[0] = (byte) 'm';
            hex_digest[1] = (byte) 'd';
            hex_digest[2] = (byte) '5';
            for (int i = 0; i < hex_digest.length; i++) {
                if (scrambled[i] != hex_digest[i]) {
                    return false;
                }
            }
        } catch (Exception e) {
            logger.error(e);
        }
        return true;
    }
public void upgradeSingleFileModelToDirectory(File modelFile) throws IOException {
        byte[] buf = new byte[8192];
        int bytesRead = 0;
        File backupModelFile = new File(modelFile.getPath() + ".bak");
        FileInputStream oldModelIn = new FileInputStream(modelFile);
        FileOutputStream backupModelOut = new FileOutputStream(backupModelFile);
        while ((bytesRead = oldModelIn.read(buf)) >= 0) {
            backupModelOut.write(buf, 0, bytesRead);
        }
        backupModelOut.close();
        oldModelIn.close();
        buf = null;
        modelFile.delete();
        modelFile.mkdir();
        BufferedReader oldModelsBuff = new BomStrippingInputStreamReader(new FileInputStream(backupModelFile), "UTF-8");
        File metaDataFile = new File(modelFile, ConstantParameters.FILENAMEOFModelMetaData);
        BufferedWriter metaDataBuff = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(metaDataFile), "UTF-8"));
        for (int i = 0; i < 8; i++) {
            metaDataBuff.write(oldModelsBuff.readLine());
            metaDataBuff.write('\n');
        }
        metaDataBuff.close();
        int classIndex = 1;
        BufferedWriter modelWriter = null;
        String line = null;
        while ((line = oldModelsBuff.readLine()) != null) {
            if (line.startsWith("Class=") && line.contains("numTraining=") && line.contains("numPos=")) {
                if (modelWriter != null) {
                    modelWriter.close();
                }
                File nextModel = new File(modelFile, String.format(ConstantParameters.FILENAMEOFPerClassModel, Integer.valueOf(classIndex++)));
                modelWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(nextModel), "UTF-8"));
            }
            modelWriter.write(line);
            modelWriter.write('\n');
        }
        if (modelWriter != null) {
            modelWriter.close();
        }
    }
public static String md5(String str) {
        StringBuffer buf = new StringBuffer();
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] data = new byte[32];
            md.update(str.getBytes(md5Encoding), 0, str.length());
            data = md.digest();
            for (int i = 0; i < data.length; i++) {
                int halfbyte = (data[i] >>> 4) & 0x0F;
                int two_halfs = 0;
                do {
                    if ((0 <= halfbyte) && (halfbyte <= 9)) buf.append((char) ('0' + halfbyte)); else buf.append((char) ('a' + (halfbyte - 10)));
                    halfbyte = data[i] & 0x0F;
                } while (two_halfs++ < 1);
            }
        } catch (Exception e) {
            errorLog("{Malgn.md5} " + e.getMessage());
        }
        return buf.toString();
    }
public static String sha1(String str) {
        StringBuffer buf = new StringBuffer();
        try {
            MessageDigest md = MessageDigest.getInstance("SHA-1");
            byte[] data = new byte[40];
            md.update(str.getBytes("iso-8859-1"), 0, str.length());
            data = md.digest();
            for (int i = 0; i < data.length; i++) {
                int halfbyte = (data[i] >>> 4) & 0x0F;
                int two_halfs = 0;
                do {
                    if ((0 <= halfbyte) && (halfbyte <= 9)) buf.append((char) ('0' + halfbyte)); else buf.append((char) ('a' + (halfbyte - 10)));
                    halfbyte = data[i] & 0x0F;
                } while (two_halfs++ < 1);
            }
        } catch (Exception e) {
            errorLog("{Malgn.sha1} " + e.getMessage());
        }
        return buf.toString();
    }
public static String sha256(String str) {
        StringBuffer buf = new StringBuffer();
        try {
            MessageDigest md = MessageDigest.getInstance("SHA-256");
            byte[] data = new byte[64];
            md.update(str.getBytes("iso-8859-1"), 0, str.length());
            data = md.digest();
            for (int i = 0; i < data.length; i++) {
                int halfbyte = (data[i] >>> 4) & 0x0F;
                int two_halfs = 0;
                do {
                    if ((0 <= halfbyte) && (halfbyte <= 9)) buf.append((char) ('0' + halfbyte)); else buf.append((char) ('a' + (halfbyte - 10)));
                    halfbyte = data[i] & 0x0F;
                } while (two_halfs++ < 1);
            }
        } catch (Exception e) {
            errorLog("{Malgn.sha256} " + e.getMessage());
        }
        return buf.toString();
    }
public static void copyFile(File source, File target) throws Exception {
        if (source.isDirectory()) {
            if (!target.isDirectory()) {
                target.mkdirs();
            }
            String[] children = source.list();
            for (int i = 0; i < children.length; i++) {
                copyFile(new File(source, children[i]), new File(target, children[i]));
            }
        } else {
            FileChannel inChannel = new FileInputStream(source).getChannel();
            FileChannel outChannel = new FileOutputStream(target).getChannel();
            try {
                int maxCount = (64 * 1024 * 1024) - (32 * 1024);
                long size = inChannel.size();
                long position = 0;
                while (position < size) {
                    position += inChannel.transferTo(position, maxCount, outChannel);
                }
            } catch (IOException e) {
                errorLog("{Malgn.copyFile} " + e.getMessage());
                throw e;
            } finally {
                if (inChannel != null) inChannel.close();
                if (outChannel != null) outChannel.close();
            }
        }
    }
public static String md5(String text) {
        String encrypted = "";
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(text.getBytes());
            encrypted = hex(md.digest());
        } catch (NoSuchAlgorithmException nsaEx) {
        }
        return encrypted;
    }
public static boolean copyFile(final File src, final File dst) {
        boolean result = false;
        FileChannel inChannel = null;
        FileChannel outChannel = null;
        synchronized (FileUtil.DATA_LOCK) {
            try {
                inChannel = new FileInputStream(src).getChannel();
                outChannel = new FileOutputStream(dst).getChannel();
                inChannel.transferTo(0, inChannel.size(), outChannel);
                result = true;
            } catch (IOException e) {
            } finally {
                if (inChannel != null && inChannel.isOpen()) {
                    try {
                        inChannel.close();
                    } catch (IOException e) {
                    }
                }
                if (outChannel != null && outChannel.isOpen()) {
                    try {
                        outChannel.close();
                    } catch (IOException e) {
                    }
                }
            }
        }
        return result;
    }
public void actionPerformed(ActionEvent e) {
        Object src = e.getSource();
        if (src == submitButton) {
            SubmissionProfile profile = (SubmissionProfile) destinationCombo.getSelectedItem();
            String uri = profile.endpoint;
            String authPoint = profile.authenticationPoint;
            String user = userIDField.getText();
            String passwd = new String(passwordField.getPassword());
            try {
                URL url = new URL(authPoint + "?username=" + user + "&password=" + passwd);
                BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
                String line = "";
                String text = "";
                while ((line = reader.readLine()) != null) {
                    text = text + line;
                }
                reader.close();
                submit(uri, user);
                JOptionPane.showMessageDialog(null, "Submission accepted", "Success", JOptionPane.INFORMATION_MESSAGE);
                this.setVisible(false);
                this.dispose();
            } catch (Exception ex) {
                ex.printStackTrace();
                if (ex instanceof java.io.IOException) {
                    String msg = ex.getMessage();
                    if (msg.indexOf("HTTP response code: 401") != -1) JOptionPane.showMessageDialog(null, "Invalid Username/Password", "Invalid Username/Password", JOptionPane.ERROR_MESSAGE); else if (msg.indexOf("HTTP response code: 404") != -1) {
                        try {
                            submit(uri, user);
                            JOptionPane.showMessageDialog(null, "Submission accepted", "Success", JOptionPane.INFORMATION_MESSAGE);
                        } catch (Exception exc) {
                            exc.printStackTrace();
                        }
                    }
                }
            }
        } else if (src == cancelButton) {
            this.setVisible(false);
            this.dispose();
        }
    }
public Document parse(Document document) {
        CSSCompilerBuilder compilerBuilder = new CSSCompilerBuilder();
        StyleSheetCompilerFactory compilerFactory = getStyleSheetCompilerFactory();
        compilerBuilder.setStyleSheetCompilerFactory(compilerFactory);
        CSSCompiler cssCompiler = compilerBuilder.getCSSCompiler();
        CompiledStyleSheet defaultCompiledStyleSheet;
        try {
            URL url = getClass().getResource("/com/volantis/mcs/runtime/default.css");
            InputStream stream = url.openStream();
            defaultCompiledStyleSheet = cssCompiler.compile(new InputStreamReader(stream), null);
        } catch (IOException e) {
            throw new ExtendedRuntimeException(e);
        }
        StylingFactory stylingFactory = StylingFactory.getDefaultInstance();
        StylingEngine stylingEngine = stylingFactory.createStylingEngine(new InlineStyleSheetCompilerFactory(StylingFunctions.getResolver()));
        stylingEngine.pushStyleSheet(defaultCompiledStyleSheet);
        DocumentStyler styler = new DocumentStyler(stylingEngine, XDIMESchemata.CDM_NAMESPACE);
        styler.style(document);
        DOMWalker walker = new DOMWalker(new WalkingDOMVisitorStub() {

            public void visit(Element element) {
                if (element.getStyles() == null) {
                    throw new IllegalArgumentException("element " + element.getName() + " has no styles");
                }
            }
        });
        walker.walk(document);
        DOMTransformer transformer = new DeferredInheritTransformer();
        document = transformer.transform(null, document);
        return document;
    }
private int connect() {
        if (ftp.isConnected()) {
            log.debug("Already connected to: " + getConnectionString());
            return RET_OK;
        }
        try {
            ftp.connect(server, port);
            ftp.login(username, password);
            ftp.setFileType(FTP.BINARY_FILE_TYPE);
        } catch (SocketException e) {
            log.error(e.toString());
            return RET_ERR_SOCKET;
        } catch (UnknownHostException e) {
            log.error(e.toString());
            return RET_ERR_UNKNOWN_HOST;
        } catch (FTPConnectionClosedException e) {
            log.error(e.toString());
            return RET_ERR_FTP_CONN_CLOSED;
        } catch (IOException e) {
            log.error(e.toString());
            return RET_ERR_IO;
        }
        if (ftp.isConnected()) {
            log.debug("Connected to " + getConnectionString());
            return RET_OK;
        }
        log.debug("Could not connect to " + getConnectionString());
        return RET_ERR_NOT_CONNECTED;
    }
public static String md5(String string) throws NoSuchAlgorithmException {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        md5.reset();
        md5.update(string.getBytes());
        byte[] result = md5.digest();
        StringBuffer hexString = new StringBuffer();
        for (int i = 0; i < result.length; i++) {
            hexString.append(Integer.toHexString((result[i] & 0xFF) | 0x100).toLowerCase().substring(1, 3));
        }
        return hexString.toString();
    }
private BingResponse queryBing(BingRequest request) throws BingException {
        try {
            if (logger.isDebugEnabled()) {
                logger.debug("Searching through bing...");
            }
            String query = request.getQuery();
            query = URLEncoder.encode(query, "UTF-8");
            URL url = new URL("http://api.bing.net/json.aspx?" + "AppId=" + request.getAppId() + "&Query=" + query + "&Sources=" + request.getType().toString());
            URLConnection connection = null;
            if (useProxy) {
                if (proxyType == null) {
                    throw new BingException("Please set a proxy first before trying to connect through a proxy", new Throwable());
                }
                connection = ProxyWrapper.getURLConnection(url.toString(), proxyType.toString(), proxyHost, proxyPort);
            } else {
                connection = new URL(url.toString()).openConnection();
            }
            String line;
            StringBuilder builder = new StringBuilder();
            BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            while ((line = reader.readLine()) != null) {
                builder.append(line);
            }
            String response = builder.toString();
            ResponseParser parser = new ResponseParser();
            parser.getError(response);
            return parser.getResults(response);
        } catch (MalformedURLException e) {
            logger.error(e);
            throw new ConnectionException("Could not connect to host", e);
        } catch (IOException e) {
            logger.error(e);
            throw new ConnectionException("Could not connect to host", e);
        }
    }
public static void main(String[] args) {
        URL url = null;
        EventHeap eh = new EventHeap("iw-room2");
        Event newEvent;
        float chan1 = -1, chan2 = -1;
        try {
            url = new URL("http://iw--bluetooth-ap/cgi-bin/sens.cgi");
        } catch (MalformedURLException e) {
        }
        byte buf[] = new byte[1000];
        while (true) {
            try {
                InputStream in = url.openStream();
                int length = in.read(buf);
                String page = new String(buf);
                String data = page.substring(290);
                if (data.startsWith("No Sensors Found")) {
                    Thread.sleep(1000);
                } else {
                    String sensorID = data.substring(15, 32);
                    String channel1 = data.substring(163, 167);
                    String channel2 = data.substring(266, 270);
                    if (Float.parseFloat(channel1) != chan1) {
                        System.out.println(sensorID);
                        System.out.println("Channel 1:" + channel1);
                        newEvent = new Event("iStuffInputEvent");
                        newEvent.addField("Device", "Slider");
                        newEvent.addField("ID", sensorID + ":channel1");
                        newEvent.addField("Value", channel1);
                        newEvent.addField("Max", String.valueOf(5));
                        newEvent.addField("Min", String.valueOf(0));
                        eh.putEvent(newEvent);
                        chan1 = Float.parseFloat(channel1);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
@Test
    public void testGrantLicense() throws Exception {
        context.turnOffAuthorisationSystem();
        Item item = Item.create(context);
        String defaultLicense = ConfigurationManager.getDefaultSubmissionLicense();
        LicenseUtils.grantLicense(context, item, defaultLicense);
        StringWriter writer = new StringWriter();
        IOUtils.copy(item.getBundles("LICENSE")[0].getBitstreams()[0].retrieve(), writer);
        String license = writer.toString();
        assertThat("testGrantLicense 0", license, equalTo(defaultLicense));
        context.restoreAuthSystemState();
    }
public static void copy(File fromFile, File toFile) throws IOException {
        if (!fromFile.exists()) throw new IOException("FileCopy: " + "no such source file: " + fromFile.getAbsolutePath());
        if (!fromFile.isFile()) throw new IOException("FileCopy: " + "can't copy directory: " + fromFile.getAbsolutePath());
        if (!fromFile.canRead()) throw new IOException("FileCopy: " + "source file is unreadable: " + fromFile.getAbsolutePath());
        if (toFile.isDirectory()) toFile = new File(toFile, fromFile.getName());
        String parent = toFile.getParent();
        if (parent == null) parent = System.getProperty("user.dir");
        File dir = new File(parent);
        if (!dir.exists()) throw new IOException("FileCopy: " + "destination directory doesn't exist: " + parent);
        if (dir.isFile()) throw new IOException("FileCopy: " + "destination is not a directory: " + parent);
        if (!dir.canWrite()) throw new IOException("FileCopy: " + "destination directory is unwriteable: " + parent);
        FileInputStream from = null;
        FileOutputStream to = null;
        try {
            from = new FileInputStream(fromFile);
            to = new FileOutputStream(toFile);
            byte[] buffer = new byte[4096];
            int bytesRead;
            while ((bytesRead = from.read(buffer)) != -1) to.write(buffer, 0, bytesRead);
        } finally {
            if (from != null) try {
                from.close();
            } catch (IOException e) {
            }
            if (to != null) try {
                to.close();
            } catch (IOException e) {
            }
        }
    }
protected void createSettingsIfNecessary() throws IOException {
        OutputStream out = null;
        try {
            final File fSettings = SettingsUtils.getSettingsFile();
            if (!fSettings.exists()) {
                fSettings.createNewFile();
                final Path src = new Path("mvn/settings.xml");
                final InputStream in = FileLocator.openStream(getBundle(), src, false);
                out = new FileOutputStream(SettingsUtils.getSettings(), true);
                IOUtils.copy(in, out);
            } else {
                Logger.getLog().info("File settings.xml already exists at " + fSettings);
            }
        } finally {
            if (out != null) {
                out.flush();
                out.close();
            }
        }
    }
public ISOMsg filter(ISOChannel channel, ISOMsg m, LogEvent evt) throws VetoException {
        if (key == null || fields == null) throw new VetoException("MD5Filter not configured");
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(getKey());
            int[] f = getFields(m);
            for (int i = 0; i < f.length; i++) {
                int fld = f[i];
                if (m.hasField(fld)) {
                    ISOComponent c = m.getComponent(fld);
                    if (c instanceof ISOBinaryField) md.update((byte[]) c.getValue()); else md.update(((String) c.getValue()).getBytes());
                }
            }
            byte[] digest = md.digest();
            if (m.getDirection() == ISOMsg.OUTGOING) {
                m.set(new ISOBinaryField(64, digest, 0, 8));
                m.set(new ISOBinaryField(128, digest, 8, 8));
            } else {
                byte[] rxDigest = new byte[16];
                if (m.hasField(64)) System.arraycopy((byte[]) m.getValue(64), 0, rxDigest, 0, 8);
                if (m.hasField(128)) System.arraycopy((byte[]) m.getValue(128), 0, rxDigest, 8, 8);
                if (!Arrays.equals(digest, rxDigest)) {
                    evt.addMessage(m);
                    evt.addMessage("MAC expected: " + ISOUtil.hexString(digest));
                    evt.addMessage("MAC received: " + ISOUtil.hexString(rxDigest));
                    throw new VetoException("invalid MAC");
                }
                m.unset(64);
                m.unset(128);
            }
        } catch (NoSuchAlgorithmException e) {
            throw new VetoException(e);
        } catch (ISOException e) {
            throw new VetoException(e);
        }
        return m;
    }
private static HttpURLConnection getDefaultConnection(URL url) throws Exception {
        HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
        httpConn.setDoInput(true);
        httpConn.setDoOutput(true);
        httpConn.setUseCaches(false);
        httpConn.setDefaultUseCaches(false);
        httpConn.setAllowUserInteraction(true);
        httpConn.setRequestMethod("POST");
        return httpConn;
    }
public static URL getAuthenticationURL(String apiKey, String permission, String sharedSecret) throws Exception {
        String apiSig = sharedSecret + "api_key" + apiKey + "perms" + permission;
        MessageDigest m = MessageDigest.getInstance("MD5");
        m.update(apiSig.getBytes(), 0, apiSig.length());
        apiSig = new BigInteger(1, m.digest()).toString(16);
        StringBuffer buffer = new StringBuffer();
        buffer.append("http://flickr.com/services/auth/?");
        buffer.append("api_key=" + apiKey);
        buffer.append("&").append("perms=").append(permission);
        buffer.append("&").append("api_sig=").append(apiSig);
        return new URL(buffer.toString());
    }