semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public InstanceMonitor(String awsAccessId, String awsSecretKey, String bucketName, boolean first) throws IOException {
        this.awsAccessId = awsAccessId;
        this.awsSecretKey = awsSecretKey;
        props = new Properties();
        while (true) {
            try {
                s3 = new RestS3Service(new AWSCredentials(awsAccessId, awsSecretKey));
                bucket = new S3Bucket(bucketName);
                S3Object obj = s3.getObject(bucket, EW_PROPERTIES);
                props.load(obj.getDataInputStream());
                break;
            } catch (S3ServiceException ex) {
                logger.error("problem fetching props from bucket, retrying", ex);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException iex) {
                }
            }
        }
        URL url = new URL("http://169.254.169.254/latest/meta-data/hostname");
        hostname = new BufferedReader(new InputStreamReader(url.openStream())).readLine();
        url = new URL("http://169.254.169.254/latest/meta-data/instance-id");
        instanceId = new BufferedReader(new InputStreamReader(url.openStream())).readLine();
        url = new URL("http://169.254.169.254/latest/meta-data/public-ipv4");
        externalIP = new BufferedReader(new InputStreamReader(url.openStream())).readLine();
        this.dns = new NetticaAPI(props.getProperty(NETTICA_USER), props.getProperty(NETTICA_PASS));
        this.userData = awsAccessId + " " + awsSecretKey + " " + bucketName;
        this.first = first;
        logger.info("InstanceMonitor initialized, first=" + first);
    }
protected byte[] mdDecode(String s, int type, byte[] salt) {
        try {
            MessageDigest md;
            StringBuffer hexString = new StringBuffer();
            if ((type == 5) && (salt != null)) {
                md = MessageDigest.getInstance(SHA);
                hexString.append("{" + SSHA + "}");
            } else if (type == 4) {
                md = MessageDigest.getInstance(SHA);
                hexString.append("{" + SHA + "}");
            } else if ((type == 3) && (salt != null)) {
                md = MessageDigest.getInstance(MD5);
                hexString.append("{" + SMD5 + "}");
            } else if (type == 2) {
                md = MessageDigest.getInstance(MD5);
                hexString.append("{" + MD5 + "}");
            } else {
                return (null);
            }
            md.reset();
            md.update(s.getBytes("UTF-8"));
            if (salt != null) {
                md.update(salt);
                byte[] buff = md.digest();
                byte[] new_buf = new byte[buff.length + salt.length];
                for (int x = 0; x < buff.length; x++) new_buf[x] = buff[x];
                for (int x = buff.length; x < new_buf.length; x++) new_buf[x] = salt[x - buff.length];
                hexString.append(CBBase64.binaryToString(new_buf));
            } else {
                byte[] buff = md.digest();
                hexString.append(CBBase64.binaryToString(buff));
            }
            return hexString.toString().getBytes("UTF-8");
        } catch (UnsupportedEncodingException e) {
            log.log(Level.WARNING, "Unexpected error encoding password ", e);
            e.printStackTrace();
            return new byte[0];
        } catch (java.security.NoSuchAlgorithmException e) {
            log.log(Level.WARNING, "Unexpected error encoding password ", e);
            e.printStackTrace();
            return new byte[0];
        }
    }
protected void innerProcess(CrawlURI curi) throws InterruptedException {
        if (!curi.isHttpTransaction()) {
            return;
        }
        if (!TextUtils.matches("^text.*$", curi.getContentType())) {
            return;
        }
        long maxsize = DEFAULT_MAX_SIZE_BYTES.longValue();
        try {
            maxsize = ((Long) getAttribute(curi, ATTR_MAX_SIZE_BYTES)).longValue();
        } catch (AttributeNotFoundException e) {
            logger.severe("Missing max-size-bytes attribute when processing " + curi.getURIString());
        }
        if (maxsize < curi.getContentSize() && maxsize > -1) {
            return;
        }
        String regexpr = "";
        try {
            regexpr = (String) getAttribute(curi, ATTR_STRIP_REG_EXPR);
        } catch (AttributeNotFoundException e2) {
            logger.severe("Missing strip-reg-exp when processing " + curi.getURIString());
            return;
        }
        ReplayCharSequence cs = null;
        try {
            cs = curi.getHttpRecorder().getReplayCharSequence();
        } catch (Exception e) {
            curi.addLocalizedError(this.getName(), e, "Failed get of replay char sequence " + curi.toString() + " " + e.getMessage());
            logger.warning("Failed get of replay char sequence " + curi.toString() + " " + e.getMessage() + " " + Thread.currentThread().getName());
            return;
        }
        MessageDigest digest = null;
        try {
            digest = MessageDigest.getInstance("SHA1");
        } catch (NoSuchAlgorithmException e1) {
            e1.printStackTrace();
            return;
        }
        digest.reset();
        String s = null;
        if (regexpr.length() == 0) {
            s = cs.toString();
        } else {
            Matcher m = TextUtils.getMatcher(regexpr, cs);
            s = m.replaceAll(" ");
        }
        digest.update(s.getBytes());
        byte[] newDigestValue = digest.digest();
        if (logger.isLoggable(Level.FINEST)) {
            logger.finest("Recalculated content digest for " + curi.getURIString() + " old: " + Base32.encode((byte[]) curi.getContentDigest()) + ", new: " + Base32.encode(newDigestValue));
        }
        curi.setContentDigest(newDigestValue);
    }
public ServiceInfo[] findServices(String name) {
        Vector results = new Vector();
        String service_file = ServiceDiscovery.SERVICE_HOME + name;
        for (int loader_count = 0; loader_count < class_loaders_.size(); loader_count++) {
            ClassLoader loader = (ClassLoader) class_loaders_.elementAt(loader_count);
            Enumeration enumeration = null;
            try {
                enumeration = loader.getResources(service_file);
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            if (enumeration == null) continue;
            while (enumeration.hasMoreElements()) {
                try {
                    URL url = (URL) enumeration.nextElement();
                    InputStream is = url.openStream();
                    if (is != null) {
                        try {
                            BufferedReader rd;
                            try {
                                rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
                            } catch (java.io.UnsupportedEncodingException e) {
                                rd = new BufferedReader(new InputStreamReader(is));
                            }
                            try {
                                String service_class_name;
                                while ((service_class_name = rd.readLine()) != null) {
                                    service_class_name.trim();
                                    if ("".equals(service_class_name)) continue;
                                    if (service_class_name.startsWith("#")) continue;
                                    ServiceInfo sinfo = new ServiceInfo();
                                    sinfo.setClassName(service_class_name);
                                    sinfo.setLoader(loader);
                                    sinfo.setURL(url);
                                    results.add(sinfo);
                                }
                            } finally {
                                rd.close();
                            }
                        } finally {
                            is.close();
                        }
                    }
                } catch (MalformedURLException ex) {
                    ex.printStackTrace();
                } catch (IOException ioe) {
                    ;
                }
            }
        }
        ServiceInfo result_array[] = new ServiceInfo[results.size()];
        results.copyInto(result_array);
        return (result_array);
    }
public static byte[] encrypt(String x) throws Exception {
        java.security.MessageDigest d = null;
        d = java.security.MessageDigest.getInstance("SHA-1");
        d.reset();
        d.update(x.getBytes());
        return d.digest();
    }
private static String simpleCompute(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest md;
        md = MessageDigest.getInstance("SHA-1");
        byte[] sha1hash = new byte[40];
        md.update(text.getBytes("utf-8"), 0, text.length());
        sha1hash = md.digest();
        return convertToHex(sha1hash);
    }
public static void main(String[] args) throws Exception {
        ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext("camel/exec-context.xml");
        CamelContext context = appContext.getBean(CamelContext.class);
        Exchange exchange = new DefaultExchange(context);
        List<String> arg = new ArrayList<String>();
        arg.add("/home/sumit/derby.log");
        arg.add("helios:cameltesting/");
        exchange.getIn().setHeader(ExecBinding.EXEC_COMMAND_ARGS, arg);
        Exchange res = context.createProducerTemplate().send("direct:input", exchange);
        ExecResult result = (ExecResult) res.getIn().getBody();
        System.out.println(result.getExitValue());
        System.out.println(result.getCommand());
        if (result.getStderr() != null) {
            IOUtils.copy(result.getStderr(), new FileOutputStream(new File("/home/sumit/error.log")));
        }
        if (result.getStdout() != null) {
            IOUtils.copy(result.getStdout(), new FileOutputStream(new File("/home/sumit/out.log")));
        }
        appContext.close();
    }
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 = IOUtils.toString(httpConn.getInputStream());
        Map parsedTokens = StringUtils.string2Map(body, "\n", "=", true);
        parsedTokens = StringUtils.lowercaseKeys(parsedTokens);
        return (String) parsedTokens.get("token");
    }
private static void processFile(String file) throws IOException {
        FileInputStream in = new FileInputStream(file);
        int read = 0;
        byte[] buf = new byte[2048];
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        while ((read = in.read(buf)) > 0) bout.write(buf, 0, read);
        in.close();
        String converted = bout.toString().replaceAll("@project.name@", projectNameS).replaceAll("@base.package@", basePackageS).replaceAll("@base.dir@", baseDir).replaceAll("@webapp.dir@", webAppDir).replaceAll("path=\"target/classes\"", "path=\"src/main/webapp/WEB-INF/classes\"");
        FileOutputStream out = new FileOutputStream(file);
        out.write(converted.getBytes());
        out.close();
    }
private static void copyFile(String from, String to) throws IOException {
        FileReader in = new FileReader(from);
        FileWriter out = new FileWriter(to);
        int c;
        while ((c = in.read()) != -1) out.write(c);
        in.close();
        out.close();
    }
public void load(boolean isOrdered) throws ResourceInstantiationException {
        try {
            if (null == url) {
                throw new ResourceInstantiationException("URL not specified (null).");
            }
            BufferedReader listReader;
            listReader = new BomStrippingInputStreamReader((url).openStream(), encoding);
            String line;
            int linenr = 0;
            while (null != (line = listReader.readLine())) {
                linenr++;
                GazetteerNode node = null;
                try {
                    node = new GazetteerNode(line, separator, isOrdered);
                } catch (Exception ex) {
                    throw new GateRuntimeException("Could not read gazetteer entry " + linenr + " from URL " + getURL() + ": " + ex.getMessage(), ex);
                }
                entries.add(new GazetteerNode(line, separator, isOrdered));
            }
            listReader.close();
        } catch (Exception x) {
            throw new ResourceInstantiationException(x.getClass() + ":" + x.getMessage());
        }
        isModified = false;
    }
public int executeBatch(String[] commands, String applicationid) throws Exception {
        Statement statement = null;
        int errors = 0;
        int commandCount = 0;
        Connection conn = null;
        try {
            conn = getConnection(applicationid);
            conn.setAutoCommit(false);
            statement = conn.createStatement();
            for (int i = 0; i < commands.length; i++) {
                String command = commands[i];
                if (command.trim().length() == 0) {
                    continue;
                }
                commandCount++;
                try {
                    log.info("executing SQL: " + command);
                    int results = statement.executeUpdate(command);
                    log.info("After execution, " + results + " row(s) have been changed");
                } catch (SQLException ex) {
                    throw ex;
                }
            }
            conn.commit();
            log.info("Executed " + commandCount + " SQL command(s) with " + errors + " error(s)");
        } catch (SQLException ex) {
            if (conn != null) {
                conn.rollback();
            }
            throw ex;
        } catch (Exception e) {
            if (conn != null) {
                conn.rollback();
            }
            throw e;
        } finally {
            statement.close();
        }
        return errors;
    }
public static String encripty(String toEncripty) {
        if (toEncripty != null) {
            try {
                synchronized (toEncripty) {
                    java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
                    md.update(toEncripty.getBytes());
                    byte[] hash = md.digest();
                    StringBuffer hexString = new StringBuffer();
                    for (int i = 0; i < hash.length; i++) {
                        if ((0xff & hash[i]) < 0x10) hexString.append("0" + Integer.toHexString((0xFF & hash[i]))); else hexString.append(Integer.toHexString(0xFF & hash[i]));
                    }
                    toEncripty = hexString.toString();
                }
            } catch (Exception e) {
                e.getMessage();
            }
        }
        return toEncripty;
    }
private void getXMLData() {
        String result = null;
        URL url = null;
        URLConnection conn = null;
        BufferedReader rd = null;
        StringBuffer sb = new StringBuffer();
        String line;
        try {
            url = new URL(this.url);
            conn = url.openConnection();
            rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            while ((line = rd.readLine()) != null) {
                sb.append(line + "\n");
            }
            rd.close();
            result = sb.toString();
        } catch (MalformedURLException e) {
            log.error("URL was malformed: {}", url, e);
        } catch (IOException e) {
            log.error("IOException thrown: {}", url, e);
        }
        this.xmlString = result;
    }
public String getRandomGUID() {
        MessageDigest md5 = null;
        String valueBeforeMD5 = "";
        String retValue = "";
        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            System.out.println("Error: " + e);
        }
        StringBuffer sbValueBeforeMD5 = new StringBuffer();
        try {
            InetAddress id = InetAddress.getLocalHost();
            long time = System.currentTimeMillis();
            long rand = 0;
            rand = random.nextLong();
            sbValueBeforeMD5.append(id.toString());
            sbValueBeforeMD5.append(Long.toString(time));
            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));
            }
            retValue = sb.toString();
        } catch (UnknownHostException e) {
            System.out.println("Error:" + e);
        }
        return retValue;
    }
public static String encrypt(String password) {
        String sign = password;
        try {
            java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
            md.update(sign.getBytes());
            byte[] hash = md.digest();
            StringBuffer hexString = new StringBuffer();
            for (int i = 0; i < hash.length; i++) {
                if ((0xff & hash[i]) < 0x10) hexString.append("0" + Integer.toHexString((0xFF & hash[i]))); else hexString.append(Integer.toHexString(0xFF & hash[i]));
            }
            sign = hexString.toString();
        } catch (Exception nsae) {
            nsae.printStackTrace();
        }
        return sign;
    }
public static String encode(String username, String password) {
        try {
            MessageDigest digest = MessageDigest.getInstance("SHA-1");
            digest.update(username.getBytes());
            digest.update(password.getBytes());
            return new String(digest.digest());
        } catch (Exception e) {
            Log.error("Error encrypting credentials", e);
        }
        return null;
    }
public String process(URL url) throws IOException {
        String line, results = "";
        InputStream is = url.openStream();
        BufferedReader dis = new BufferedReader(new InputStreamReader(is));
        while ((line = dis.readLine()) != null) {
            results += line + "\n";
        }
        System.out.println(results);
        return results;
    }
public String readTemplateToString(String fileName) {
        URL url = null;
        url = classLoader.getResource(fileName);
        StringBuffer content = new StringBuffer();
        if (url == null) {
            String error = "Template file could not be found: " + fileName;
            throw new RuntimeException(error);
        }
        try {
            BufferedReader breader = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"));
            String strLine = "";
            while ((strLine = breader.readLine()) != null) {
                content.append(strLine).append("\n");
            }
            breader.close();
        } catch (Exception e) {
            throw new RuntimeException("Problem while loading file: " + fileName);
        }
        return content.toString();
    }
public synchronized String encrypt(String plaintext) throws SystemUnavailableException {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("SHA");
        } catch (NoSuchAlgorithmException e) {
            throw new SystemUnavailableException(e.getMessage());
        }
        try {
            md.update(plaintext.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            throw new SystemUnavailableException(e.getMessage());
        }
        byte raw[] = md.digest();
        String hash = (new BASE64Encoder()).encode(raw);
        return hash;
    }
private DialogHelper(String title, final URL imageURL) {
        jd = new JDialog();
        jd.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        jd.setAlwaysOnTop(true);
        jd.setLayout(new BoxLayout(jd.getContentPane(), BoxLayout.Y_AXIS));
        jd.setTitle(title);
        JLabel jl = new JLabel();
        ImageIcon icon = new ImageIcon(imageURL);
        jl.setIcon(icon);
        jd.add(new JScrollPane(jl));
        final JFileChooser chooser = getSaveImageChooser();
        JPanel jp = new JPanel();
        JButton jb = new JButton(getMessage("btn_save_as"));
        jb.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                int returnVal = chooser.showSaveDialog(jd);
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    File file = chooser.getSelectedFile();
                    String fileName = file.getPath();
                    String ext = StringUtil.getLowerExtension(fileName);
                    if (!"png".equals(ext)) {
                        fileName += ".png";
                        file = new File(fileName);
                    }
                    boolean doIt = true;
                    if (file.exists()) {
                        int i = JOptionPane.showConfirmDialog(jd, getMessage("warn_file_exist"));
                        if (i != JOptionPane.YES_OPTION) doIt = false;
                    } else if (!file.getParentFile().exists()) {
                        doIt = file.getParentFile().mkdirs();
                    }
                    if (doIt) {
                        FileChannel src = null;
                        FileChannel dest = null;
                        try {
                            src = new FileInputStream(imageURL.getPath()).getChannel();
                            dest = new FileOutputStream(fileName).getChannel();
                            src.transferTo(0, src.size(), dest);
                        } catch (FileNotFoundException e1) {
                            warn(jd, getMessage("err_no_source_file"));
                        } catch (IOException e2) {
                            warn(jd, getMessage("err_output_target"));
                        } finally {
                            try {
                                if (src != null) src.close();
                            } catch (IOException e1) {
                            }
                            try {
                                if (dest != null) dest.close();
                            } catch (IOException e1) {
                            }
                            src = null;
                            dest = null;
                        }
                    }
                }
            }
        });
        jp.add(jb);
        jb = new JButton(getMessage("btn_close"));
        jb.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                jd.dispose();
            }
        });
        jp.add(jb);
        jd.add(jp);
        jd.pack();
        setCentral(jd);
    }