semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private static void sendExceptionToServer(String server, Throwable ex, String config, String prob) {
        try {
            StringBuilder dataSB = new StringBuilder();
            dataSB.append(URLEncoder.encode("secret", "UTF-8"));
            dataSB.append('=');
            dataSB.append(URLEncoder.encode("badsecurity", "UTF-8"));
            dataSB.append('&');
            dataSB.append(URLEncoder.encode("version", "UTF-8"));
            dataSB.append('=');
            dataSB.append(URLEncoder.encode(BuildInfo.revisionNumber, "UTF-8"));
            dataSB.append('&');
            dataSB.append(URLEncoder.encode("os", "UTF-8"));
            dataSB.append('=');
            dataSB.append(URLEncoder.encode(System.getProperty("os.name") + " " + System.getProperty("os.version"), "UTF-8"));
            dataSB.append('&');
            dataSB.append(URLEncoder.encode("user", "UTF-8"));
            dataSB.append('=');
            dataSB.append(URLEncoder.encode(System.getProperty("user.name"), "UTF-8"));
            dataSB.append('&');
            dataSB.append(URLEncoder.encode("msg", "UTF-8"));
            dataSB.append('=');
            dataSB.append(URLEncoder.encode(ex.getMessage(), "UTF-8"));
            ByteArrayOutputStream trace = new ByteArrayOutputStream();
            ex.printStackTrace(new PrintStream(trace));
            dataSB.append('&');
            dataSB.append(URLEncoder.encode("trace", "UTF-8"));
            dataSB.append('=');
            dataSB.append(URLEncoder.encode(trace.toString(), "UTF-8"));
            if (config != null) {
                dataSB.append('&');
                dataSB.append(URLEncoder.encode("config", "UTF-8"));
                dataSB.append('=');
                dataSB.append(URLEncoder.encode(config, "UTF-8"));
            }
            if (prob != null) {
                dataSB.append('&');
                dataSB.append(URLEncoder.encode("problem", "UTF-8"));
                dataSB.append('=');
                dataSB.append(URLEncoder.encode(prob, "UTF-8"));
            }
            URL url = new URL(errorServerURL);
            URLConnection conn = url.openConnection();
            conn.setDoOutput(true);
            OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
            wr.write(dataSB.toString());
            wr.flush();
            BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String response = null;
            String line = null;
            while ((line = rd.readLine()) != null) {
                if (response == null) response = line; else System.out.println(line);
            }
            wr.close();
            rd.close();
            if (response.equals("success")) System.out.println("Exception sent to maRla development team"); else System.out.println("Unable to send exception to development team: " + response);
        } catch (IOException ex2) {
            System.out.println("Unable to send exception to development team: " + ex2.getMessage());
        }
    }
public static User authenticate(final String username, final String password) throws LoginException {
        Object result = doPriviledgedAction(new PrivilegedAction() {

            public Object run() {
                List correctUsers = (List) JsonPath.query("select * from ? where name=?", usersTable(), username);
                if (correctUsers.size() == 0) {
                    return new LoginException("user " + username + " not found");
                }
                Persistable userObject = (Persistable) correctUsers.get(0);
                boolean alreadyHashed = false;
                boolean passwordMatch = password.equals(userObject.get(PASSWORD_FIELD));
                if (!passwordMatch) {
                    try {
                        MessageDigest md = MessageDigest.getInstance("SHA");
                        md.update(((String) userObject.get(PASSWORD_FIELD)).getBytes());
                        passwordMatch = password.equals(new String(new Base64().encode(md.digest())));
                    } catch (NoSuchAlgorithmException e) {
                        throw new RuntimeException(e);
                    }
                    alreadyHashed = true;
                }
                if (passwordMatch) {
                    Logger.getLogger(User.class.toString()).info("User " + username + " has been authenticated");
                    User user = (User) userObject;
                    try {
                        if (alreadyHashed) user.currentTicket = password; else {
                            MessageDigest md = MessageDigest.getInstance("SHA");
                            md.update(password.getBytes());
                            user.currentTicket = new String(new Base64().encode(md.digest()));
                        }
                    } catch (NoSuchAlgorithmException e) {
                        throw new RuntimeException(e);
                    }
                    return user;
                } else {
                    Logger.getLogger(User.class.toString()).info("The password was incorrect for " + username);
                    return new LoginException("The password was incorrect for user " + username + ". ");
                }
            }
        });
        if (result instanceof LoginException) throw (LoginException) result;
        return (User) result;
    }
public Object run() {
                List correctUsers = (List) JsonPath.query("select * from ? where name=?", usersTable(), username);
                if (correctUsers.size() == 0) {
                    return new LoginException("user " + username + " not found");
                }
                Persistable userObject = (Persistable) correctUsers.get(0);
                boolean alreadyHashed = false;
                boolean passwordMatch = password.equals(userObject.get(PASSWORD_FIELD));
                if (!passwordMatch) {
                    try {
                        MessageDigest md = MessageDigest.getInstance("SHA");
                        md.update(((String) userObject.get(PASSWORD_FIELD)).getBytes());
                        passwordMatch = password.equals(new String(new Base64().encode(md.digest())));
                    } catch (NoSuchAlgorithmException e) {
                        throw new RuntimeException(e);
                    }
                    alreadyHashed = true;
                }
                if (passwordMatch) {
                    Logger.getLogger(User.class.toString()).info("User " + username + " has been authenticated");
                    User user = (User) userObject;
                    try {
                        if (alreadyHashed) user.currentTicket = password; else {
                            MessageDigest md = MessageDigest.getInstance("SHA");
                            md.update(password.getBytes());
                            user.currentTicket = new String(new Base64().encode(md.digest()));
                        }
                    } catch (NoSuchAlgorithmException e) {
                        throw new RuntimeException(e);
                    }
                    return user;
                } else {
                    Logger.getLogger(User.class.toString()).info("The password was incorrect for " + username);
                    return new LoginException("The password was incorrect for user " + username + ". ");
                }
            }
static String encrypt(String plaintext) {
        MessageDigest d = null;
        try {
            d = MessageDigest.getInstance("SHA-1");
            d.update(plaintext.getBytes("UTF-8"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new String(Base64.encodeBase64(d.digest()));
    }
public InlineImageChunk(URL url) {
        super();
        this.url = url;
        try {
            URLConnection urlConn = url.openConnection();
            urlConn.setReadTimeout(15000);
            ImageInputStream iis = ImageIO.createImageInputStream(urlConn.getInputStream());
            Iterator<ImageReader> readers = ImageIO.getImageReaders(iis);
            if (readers.hasNext()) {
                ImageReader reader = readers.next();
                reader.setInput(iis, true);
                this.width = reader.getWidth(0);
                this.ascent = reader.getHeight(0);
                this.descent = 0;
                reader.dispose();
            } else System.err.println("cannot read width and height of image " + url + " - no suitable reader!");
        } catch (Exception exc) {
            System.err.println("cannot read width and height of image " + url + " due to exception:");
            System.err.println(exc);
            exc.printStackTrace(System.err);
        }
    }
public URL grabCover(String artist, String title) {
        if (idf.jCheckBox3.isSelected()) {
            println("Searching cover for: " + artist);
            artist = artist.trim();
            URL url = null;
            int searchnumber = 0;
            try {
                URL yahoo = new URL("http://www.gracenote.com/search/?query=" + artist.toLowerCase().replaceAll(" ", "+") + "&search_type=artist");
                BufferedReader in = new BufferedReader(new InputStreamReader(yahoo.openStream()));
                println("" + yahoo);
                String inputLine;
                String line = "";
                while ((inputLine = in.readLine()) != null) line += inputLine;
                boolean notfound = true;
                String cut = line;
                while (notfound) {
                    String search = "<div class=\"album-name large\"><strong>Album:</strong> <a href=\"";
                    if (line.indexOf(search) <= 0) {
                        println("Artist was not found!");
                        in.close();
                        return null;
                    }
                    cut = cut.substring(cut.indexOf(search) + search.length());
                    String test = cut.substring(0, cut.indexOf("\""));
                    URL secondurl = new URL("http://www.gracenote.com" + test);
                    println("" + secondurl);
                    BufferedReader secin = new BufferedReader(new InputStreamReader(secondurl.openStream()));
                    String secinputLine;
                    String secline = "";
                    while ((secinputLine = secin.readLine()) != null) secline += secinputLine;
                    if (!(secline.toUpperCase().indexOf(title.toUpperCase()) < 0 && idf.jCheckBox2.isSelected())) {
                        String secsearch = "<div class=\"album-image\"><img src=\"";
                        String seccut = secline.substring(secline.indexOf(secsearch) + secsearch.length());
                        seccut = seccut.substring(0, seccut.indexOf("\""));
                        url = new URL("http://www.gracenote.com" + seccut);
                        if (url.toString().indexOf("covers/default") <= 0 && url.toString().indexOf("covers/") > 0) {
                            notfound = false;
                        }
                    }
                    secin.close();
                }
                in.close();
                println(url.toString());
            } catch (Exception e) {
                println("error " + e + "\n");
                e.printStackTrace();
            }
            return url;
        } else {
            return null;
        }
    }
private void copyFile(String inputPath, String basis, String filename) throws GLMRessourceFileException {
        try {
            FileChannel inChannel = new FileInputStream(new File(inputPath)).getChannel();
            File target = new File(basis, filename);
            FileChannel outChannel = new FileOutputStream(target).getChannel();
            inChannel.transferTo(0, inChannel.size(), outChannel);
            inChannel.close();
            outChannel.close();
        } catch (Exception e) {
            throw new GLMRessourceFileException(7);
        }
    }
public ReqJsonContent(String useragent, String urlstr, String domain, String pathinfo, String alarmMessage) throws IOException {
        URL url = new URL(urlstr);
        URLConnection conn = url.openConnection();
        conn.setRequestProperty("user-agent", useragent);
        conn.setRequestProperty("pathinfo", pathinfo);
        conn.setRequestProperty("domain", domain);
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF8"));
            response = new StringBuffer();
            String line = "";
            while ((line = reader.readLine()) != null) {
                response.append(line);
            }
            reader.close();
            jsonContectResult = response.toString();
        } catch (SocketTimeoutException e) {
            log.severe(alarmMessage + "-> " + e.getMessage());
            jsonContectResult = null;
        } catch (Exception e) {
            log.severe(alarmMessage + "-> " + e.getMessage());
            jsonContectResult = null;
        }
    }
public JarClassLoader(ClassLoader parent) {
        super(parent);
        initLogger();
        hmClass = new HashMap<String, Class<?>>();
        lstJarFile = new ArrayList<JarFileInfo>();
        hsDeleteOnExit = new HashSet<File>();
        String sUrlTopJar = null;
        pd = getClass().getProtectionDomain();
        CodeSource cs = pd.getCodeSource();
        URL urlTopJar = cs.getLocation();
        String protocol = urlTopJar.getProtocol();
        JarFileInfo jarFileInfo = null;
        if ("http".equals(protocol) || "https".equals(protocol)) {
            try {
                urlTopJar = new URL("jar:" + urlTopJar + "!/");
                JarURLConnection jarCon = (JarURLConnection) urlTopJar.openConnection();
                JarFile jarFile = jarCon.getJarFile();
                jarFileInfo = new JarFileInfo(jarFile, jarFile.getName(), null, null);
                logInfo(LogArea.JAR, "Loading from top JAR: '%s' PROTOCOL: '%s'", urlTopJar, protocol);
            } catch (Exception e) {
                logError(LogArea.JAR, "Failure to load HTTP JAR: %s %s", urlTopJar, e.toString());
                return;
            }
        }
        if ("file".equals(protocol)) {
            try {
                sUrlTopJar = URLDecoder.decode(urlTopJar.getFile(), "UTF-8");
            } catch (UnsupportedEncodingException e) {
                logError(LogArea.JAR, "Failure to decode URL: %s %s", urlTopJar, e.toString());
                return;
            }
            File fileJar = new File(sUrlTopJar);
            if (fileJar.isDirectory()) {
                logInfo(LogArea.JAR, "Loading from exploded directory: %s", sUrlTopJar);
                return;
            }
            try {
                jarFileInfo = new JarFileInfo(new JarFile(fileJar), fileJar.getName(), null, null);
                logInfo(LogArea.JAR, "Loading from top JAR: '%s' PROTOCOL: '%s'", sUrlTopJar, protocol);
            } catch (IOException e) {
                logError(LogArea.JAR, "Not a JAR: %s %s", sUrlTopJar, e.toString());
                return;
            }
        }
        try {
            if (jarFileInfo == null) {
                throw new IOException(String.format("Unknown protocol %s", protocol));
            }
            loadJar(jarFileInfo);
        } catch (IOException e) {
            logError(LogArea.JAR, "Not valid URL: %s %s", urlTopJar, e.toString());
            return;
        }
        checkShading();
        Runtime.getRuntime().addShutdownHook(new Thread() {

            public void run() {
                shutdown();
            }
        });
    }
protected List<Datastream> getDatastreams(final DepositCollection pDeposit) throws IOException, SWORDException {
        List<Datastream> tDatastreams = new ArrayList<Datastream>();
        LOG.debug("copying file");
        String tZipTempFileName = super.getTempDir() + "uploaded-file.tmp";
        IOUtils.copy(pDeposit.getFile(), new FileOutputStream(tZipTempFileName));
        Datastream tDatastream = new LocalDatastream(super.getGenericFileName(pDeposit), this.getContentType(), tZipTempFileName);
        tDatastreams.add(tDatastream);
        tDatastreams.addAll(_zipFile.getFiles(tZipTempFileName));
        return tDatastreams;
    }
private String generateFilename() {
        byte[] hash = null;
        try {
            MessageDigest digest = MessageDigest.getInstance("MD5");
            try {
                digest.update(InetAddress.getLocalHost().toString().getBytes());
            } catch (UnknownHostException e) {
            }
            digest.update(String.valueOf(System.currentTimeMillis()).getBytes());
            digest.update(String.valueOf(Runtime.getRuntime().freeMemory()).getBytes());
            byte[] foo = new byte[128];
            new SecureRandom().nextBytes(foo);
            digest.update(foo);
            hash = digest.digest();
        } catch (NoSuchAlgorithmException e) {
            Debug.assrt(false);
        }
        return hexEncode(hash);
    }
public static void main(String argv[]) {
        try {
            if (argv.length != 1 && argv.length != 3) {
                usage();
                System.exit(1);
            }
            URL url = new URL(argv[0]);
            URLConnection conn;
            conn = url.openConnection();
            if (conn.getHeaderField("WWW-Authenticate") != null) {
                auth(conn, argv[1], argv[2]);
            } else {
                BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                String line;
                while ((line = reader.readLine()) != null) System.out.println(line);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
public StringBuffer get(URL url) throws IOException {
        StringBuffer pageContents = new StringBuffer();
        PDFReader reader = new PDFReader(url.openStream());
        reader.open();
        int pageCount = reader.getNumberOfPages();
        for (int i = 0; i < pageCount; i++) pageContents.append(new String(reader.extractTextFromPage(i).getBytes(), "UTF-8"));
        reader.close();
        return pageContents;
    }
public static void main(String args[]) {
        try {
            URL url = new URL("http://www.hungry.com/");
            InputStream stream = url.openStream();
            int size = 0;
            while (-1 != stream.read()) {
                size++;
            }
            stream.close();
            System.out.println("PASSED: new URL() size=" + size);
        } catch (Exception e) {
            System.out.println("FAILED: " + e);
        }
    }
public byte[] computeMD5(String plainText) throws GException {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException ex) {
            throw new GException("The MD5 hash algorithm is not available.", ex);
        }
        try {
            md.update(plainText.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException ex) {
            throw new GException("The UTF-8 encoding is not supported.", ex);
        }
        return md.digest();
    }
@Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String path = request.getPathTranslated().substring(0, request.getPathTranslated().length() - request.getPathInfo().length()) + request.getServletPath() + request.getPathInfo();
        File file = new File(path);
        if (file.exists()) {
            FileInputStream in = new FileInputStream(file);
            IOUtils.copyLarge(in, response.getOutputStream());
            in.close();
        }
    }
public static void copyFiles(String strPath, String trgPath) {
        File src = new File(strPath);
        File trg = new File(trgPath);
        if (src.isDirectory()) {
            if (trg.exists() != true) trg.mkdirs();
            String list[] = src.list();
            for (int i = 0; i < list.length; i++) {
                String strPath_1 = src.getAbsolutePath() + SEPARATOR + list[i];
                String trgPath_1 = trg.getAbsolutePath() + SEPARATOR + list[i];
                copyFiles(strPath_1, trgPath_1);
            }
        } else {
            try {
                FileChannel srcChannel = new FileInputStream(strPath).getChannel();
                FileChannel dstChannel = new FileOutputStream(trgPath).getChannel();
                dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
                srcChannel.close();
                dstChannel.close();
            } catch (FileNotFoundException e) {
                System.out.println("[Error] File not found: " + e.getMessage());
            } catch (IOException e) {
                System.out.println("[Error] " + e.getMessage());
            }
        }
    }
private void modifyEntry(ModifyInterceptorChain chain, DistinguishedName dn, ArrayList<LDAPModification> mods, Connection con) throws LDAPException {
        try {
            con.setAutoCommit(false);
            HashMap<String, String> ldap2db = (HashMap<String, String>) chain.getRequest().get(JdbcInsert.MYVD_DB_LDAP2DB + this.dbInsertName);
            Iterator<LDAPModification> it = mods.iterator();
            String sql = "UPDATE " + this.tableName + " SET ";
            while (it.hasNext()) {
                LDAPModification mod = it.next();
                if (mod.getOp() != LDAPModification.REPLACE) {
                    throw new LDAPException("Only modify replace allowed", LDAPException.OBJECT_CLASS_VIOLATION, "");
                }
                sql += ldap2db.get(mod.getAttribute().getName()) + "=? ";
            }
            sql += " WHERE " + this.rdnField + "=?";
            PreparedStatement ps = con.prepareStatement(sql);
            it = mods.iterator();
            int i = 1;
            while (it.hasNext()) {
                LDAPModification mod = it.next();
                ps.setString(i, mod.getAttribute().getStringValue());
                i++;
            }
            String uid = ((RDN) dn.getDN().getRDNs().get(0)).getValue();
            ps.setString(i, uid);
            ps.executeUpdate();
            con.commit();
        } catch (SQLException e) {
            try {
                con.rollback();
            } catch (SQLException e1) {
                throw new LDAPException("Could not delete entry or rollback transaction", LDAPException.OPERATIONS_ERROR, e.toString(), e);
            }
            throw new LDAPException("Could not delete entry", LDAPException.OPERATIONS_ERROR, e.toString(), e);
        }
    }
@Override
    public Directory directory() {
        HttpURLConnection urlConnection = null;
        InputStream in = null;
        try {
            URL url = new URL(DIRECTORY_URL);
            urlConnection = (HttpURLConnection) url.openConnection();
            urlConnection.setRequestProperty("Accept-Encoding", "gzip, deflate");
            String encoding = urlConnection.getContentEncoding();
            if ("gzip".equalsIgnoreCase(encoding)) {
                in = new GZIPInputStream(urlConnection.getInputStream());
            } else if ("deflate".equalsIgnoreCase(encoding)) {
                in = new InflaterInputStream(urlConnection.getInputStream(), new Inflater(true));
            } else {
                in = urlConnection.getInputStream();
            }
            return persister.read(IcecastDirectory.class, in);
        } catch (Exception e) {
            throw new RuntimeException("Failed to get directory", e);
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                }
            }
            if (urlConnection != null) {
                urlConnection.disconnect();
            }
        }
    }
public static InputStream getRequest(String path) throws Exception {
		HttpGet httpGet = new HttpGet(path);
		HttpResponse httpResponse = sClient.execute(httpGet);
		if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
			BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(httpResponse.getEntity());
			return bufHttpEntity.getContent();
		} else {
			return null;
		}
	}