semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public GGLicenses getLicensesInfo() throws IllegalStateException, GGException, Exception {
        List<NameValuePair> qparams = new ArrayList<NameValuePair>();
        qparams.add(new BasicNameValuePair("method", "gg.photos.licenses.getInfo"));
        qparams.add(new BasicNameValuePair("key", this.key));
        String url = REST_URL + "?" + URLEncodedUtils.format(qparams, "UTF-8");
        URI uri = new URI(url);
        HttpGet httpget = new HttpGet(uri);
        HttpResponse response = httpClient.execute(httpget);
        int status = response.getStatusLine().getStatusCode();
        errorCheck(response, status);
        InputStream content = response.getEntity().getContent();
        GGLicenses licenses = JAXB.unmarshal(content, GGLicenses.class);
        return licenses;
    }
public GGMunicipalities getListMunicipalities() throws IllegalStateException, GGException, Exception {
        List<NameValuePair> qparams = new ArrayList<NameValuePair>();
        qparams.add(new BasicNameValuePair("method", "gg.photos.geo.getListMunicipality"));
        qparams.add(new BasicNameValuePair("key", this.key));
        String url = REST_URL + "?" + URLEncodedUtils.format(qparams, "UTF-8");
        URI uri = new URI(url);
        HttpGet httpget = new HttpGet(uri);
        HttpResponse response = httpClient.execute(httpget);
        int status = response.getStatusLine().getStatusCode();
        errorCheck(response, status);
        InputStream content = response.getEntity().getContent();
        GGMunicipalities municipalities = JAXB.unmarshal(content, GGMunicipalities.class);
        return municipalities;
    }
public GGProvinces getListProvinces() throws IllegalStateException, GGException, Exception {
        List<NameValuePair> qparams = new ArrayList<NameValuePair>();
        qparams.add(new BasicNameValuePair("method", "gg.photos.geo.getListProvinces"));
        qparams.add(new BasicNameValuePair("key", this.key));
        String url = REST_URL + "?" + URLEncodedUtils.format(qparams, "UTF-8");
        URI uri = new URI(url);
        HttpGet httpget = new HttpGet(uri);
        HttpResponse response = httpClient.execute(httpget);
        int status = response.getStatusLine().getStatusCode();
        errorCheck(response, status);
        InputStream content = response.getEntity().getContent();
        GGProvinces provinces = JAXB.unmarshal(content, GGProvinces.class);
        return provinces;
    }
public GGPhotoInfo getPhotoInfo(String photoId, String language) throws IllegalStateException, GGException, Exception {
        List<NameValuePair> qparams = new ArrayList<NameValuePair>();
        qparams.add(new BasicNameValuePair("method", "gg.photos.getInfo"));
        qparams.add(new BasicNameValuePair("key", this.key));
        qparams.add(new BasicNameValuePair("photo_id", photoId));
        if (null != language) {
            qparams.add(new BasicNameValuePair("language", language));
        }
        String url = REST_URL + "?" + URLEncodedUtils.format(qparams, "UTF-8");
        URI uri = new URI(url);
        HttpGet httpget = new HttpGet(uri);
        HttpResponse response = httpClient.execute(httpget);
        int status = response.getStatusLine().getStatusCode();
        errorCheck(response, status);
        InputStream content = response.getEntity().getContent();
        GGPhotoInfo photo = JAXB.unmarshal(content, GGPhotoInfo.class);
        return photo;
    }
private void copyFileToPhotoFolder(File photo, String personId) {
        try {
            FileChannel in = new FileInputStream(photo).getChannel();
            File dirServer = new File(Constants.PHOTO_DIR);
            if (!dirServer.exists()) {
                dirServer.mkdirs();
            }
            File fileServer = new File(Constants.PHOTO_DIR + personId + ".jpg");
            if (!fileServer.exists()) {
                fileServer.createNewFile();
            }
            in.transferTo(0, in.size(), new FileOutputStream(fileServer).getChannel());
            in.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
public static String encryptPasswd(String pass) {
        try {
            if (pass == null || pass.length() == 0) return pass;
            MessageDigest sha = MessageDigest.getInstance("SHA-1");
            sha.reset();
            sha.update(pass.getBytes("UTF-8"));
            return Base64OutputStream.encode(sha.digest());
        } catch (Throwable t) {
            throw new SystemException(t);
        }
    }
public static void main(String[] args) throws Exception {
        FileChannel fc = new FileOutputStream("data2.txt").getChannel();
        fc.write(ByteBuffer.wrap("Some text".getBytes()));
        fc.close();
        fc = new FileInputStream("data2.txt").getChannel();
        ByteBuffer buff = ByteBuffer.allocate(BSIZE);
        fc.read(buff);
        buff.flip();
        System.out.println(buff.asCharBuffer());
        buff.rewind();
        String encoding = System.getProperty("file.encoding");
        System.out.println("Decoded using " + encoding + ": " + Charset.forName(encoding).decode(buff));
        fc = new FileOutputStream("data2.txt").getChannel();
        fc.write(ByteBuffer.wrap("Some text".getBytes("UTF-16BE")));
        fc.close();
        fc = new FileInputStream("data2.txt").getChannel();
        buff.clear();
        fc.read(buff);
        buff.flip();
        System.out.println(buff.asCharBuffer());
        fc = new FileOutputStream("data2.txt").getChannel();
        buff = ByteBuffer.allocate(24);
        buff.asCharBuffer().put("Some text");
        fc.write(buff);
        fc.close();
        fc = new FileInputStream("data2.txt").getChannel();
        buff.clear();
        fc.read(buff);
        buff.flip();
        System.out.println(buff.asCharBuffer());
    }
public static void encryptFile(String input, String output, String pwd) throws Exception {
        CipherOutputStream out;
        InputStream in;
        Cipher cipher;
        SecretKey key;
        byte[] byteBuffer;
        cipher = Cipher.getInstance("DES");
        key = new SecretKeySpec(pwd.getBytes(), "DES");
        cipher.init(Cipher.ENCRYPT_MODE, key);
        in = new FileInputStream(input);
        out = new CipherOutputStream(new FileOutputStream(output), cipher);
        byteBuffer = new byte[1024];
        for (int n; (n = in.read(byteBuffer)) != -1; out.write(byteBuffer, 0, n)) ;
        in.close();
        out.close();
    }
public static void decryptFile(String input, String output, String pwd) throws Exception {
        CipherInputStream in;
        OutputStream out;
        Cipher cipher;
        SecretKey key;
        byte[] byteBuffer;
        cipher = Cipher.getInstance("DES");
        key = new SecretKeySpec(pwd.getBytes(), "DES");
        cipher.init(Cipher.DECRYPT_MODE, key);
        in = new CipherInputStream(new FileInputStream(input), cipher);
        out = new FileOutputStream(output);
        byteBuffer = new byte[1024];
        for (int n; (n = in.read(byteBuffer)) != -1; out.write(byteBuffer, 0, n)) ;
        in.close();
        out.close();
    }
public CacheServiceFactoryImpl() {
        @SuppressWarnings("static-access") URL url = this.getClass().getClassLoader().getResource("mwt/xml/xdbforms/configuration/ehcache.xml");
        InputStream is;
        try {
            is = url.openStream();
            cacheManager = CacheManager.create(is);
        } catch (IOException ex) {
            System.err.println("NOn riesco ad aprire il file di configurazione ehcache.xml");
        }
    }
private String hashMD5(String strToHash) throws Exception {
        try {
            byte[] bHash = new byte[strToHash.length() * 2];
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(strToHash.getBytes("UTF-16LE"));
            bHash = md.digest();
            StringBuffer hexString = new StringBuffer();
            for (byte element : bHash) {
                String strTemp = Integer.toHexString(element);
                hexString.append(strTemp.replaceAll("f", ""));
            }
            return hexString.toString();
        } catch (NoSuchAlgorithmException duu) {
            throw new Exception("NoSuchAlgorithmException: " + duu.getMessage());
        }
    }
public void lookupAllFactories() throws IOException {
        Enumeration setOfFactories = null;
        ClassLoader classLoader = null;
        InputStream inputStream = null;
        classLoader = (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() {

            public Object run() {
                ClassLoader cl = Thread.currentThread().getContextClassLoader();
                if (cl == null) {
                    cl = ClassLoader.getSystemClassLoader();
                }
                return cl;
            }
        });
        if (classLoader == null) {
            return;
        }
        try {
            setOfFactories = classLoader.getResources("META-INF/services/javax.print.StreamPrintServiceFactory");
        } catch (IOException e) {
            e.printStackTrace();
            throw new IOException("IOException during resource finding");
        }
        try {
            while (setOfFactories.hasMoreElements()) {
                URL url = (URL) setOfFactories.nextElement();
                inputStream = url.openStream();
                getFactoryClasses(inputStream);
            }
        } catch (IOException e1) {
            e1.printStackTrace();
            throw new IOException("IOException during resource reading");
        }
    }
protected Icon newIcon(String iconName) {
        URL url = Utils.getResource(getFullPath(iconName, "/"), getClass());
        if (url == null) {
            if (getParent() != null) return getParent().getIcon(iconName);
            return null;
        }
        try {
            MethodCall getImage = new MethodCaller("org.apache.sanselan.Sanselan", null, "getBufferedImage", new Object[] { InputStream.class }).getMethodCall();
            getImage.setArgumentValue(0, url.openStream());
            return new ImageIcon((BufferedImage) getImage.call());
        } catch (Throwable e) {
            return new ImageIcon(url);
        }
    }
public static String toPWD(String pwd) {
        MessageDigest messageDigest = null;
        try {
            messageDigest = MessageDigest.getInstance("MD5");
            messageDigest.reset();
            messageDigest.update(pwd.getBytes("UTF-8"));
        } catch (NoSuchAlgorithmException e) {
            System.out.println("NoSuchAlgorithmException caught!");
            System.exit(-1);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        byte[] byteArray = messageDigest.digest();
        StringBuffer md5StrBuff = new StringBuffer();
        for (int i = 0; i < byteArray.length; i++) {
            if (Integer.toHexString(0xFF & byteArray[i]).length() == 1) md5StrBuff.append("0").append(Integer.toHexString(0xFF & byteArray[i])); else md5StrBuff.append(Integer.toHexString(0xFF & byteArray[i]));
        }
        return md5StrBuff.toString();
    }
public static void perform(ChangeSet changes, ArchiveInputStream in, ArchiveOutputStream out) throws IOException {
        ArchiveEntry entry = null;
        while ((entry = in.getNextEntry()) != null) {
            System.out.println(entry.getName());
            boolean copy = true;
            for (Iterator it = changes.asSet().iterator(); it.hasNext(); ) {
                Change change = (Change) it.next();
                if (change.type() == ChangeSet.CHANGE_TYPE_DELETE) {
                    DeleteChange delete = ((DeleteChange) change);
                    if (entry.getName() != null && entry.getName().equals(delete.targetFile())) {
                        copy = false;
                    }
                }
            }
            if (copy) {
                System.out.println("Copy: " + entry.getName());
                long size = entry.getSize();
                out.putArchiveEntry(entry);
                IOUtils.copy((InputStream) in, out, (int) size);
                out.closeArchiveEntry();
            }
            System.out.println("---");
        }
        out.close();
    }
private static void fileUpload() throws Exception {
        DefaultHttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(postURL);
        file = new File("h:/Sakura haruno.jpg");
        MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
        ContentBody cbFile = new FileBody(file);
        mpEntity.addPart("Filename", new StringBody(file.getName()));
        mpEntity.addPart("Filedata", cbFile);
        httppost.setEntity(mpEntity);
        System.out.println("executing request " + httppost.getRequestLine());
        System.out.println("Now uploading your file into ugotfile.com");
        HttpResponse response = httpclient.execute(httppost);
        System.out.println(response.getStatusLine());
        if (response != null) {
            uploadresponse = EntityUtils.toString(response.getEntity());
        }
        System.out.println("Upload Response : " + uploadresponse);
        downloadlink = parseResponse(uploadresponse, "[\"", "\"");
        downloadlink = downloadlink.replaceAll("\\\\/", "/");
        deletelink = parseResponse(uploadresponse, "\",\"", "\"");
        deletelink = deletelink.replaceAll("\\\\/", "/");
        System.out.println("Download Link : " + downloadlink);
        System.out.println("Delete Link : " + deletelink);
    }
public Object resolveEntity(String publicID, String systemID, String baseURI, String namespace) throws XMLStreamException {
        URL url = configuration.get(publicID);
        try {
            if (url != null) return url.openStream();
        } catch (IOException ex) {
            throw new XMLStreamException(String.format("Unable to open stream for resource %s: %s", url, InternalUtils.toMessage(ex)), ex);
        }
        return null;
    }
@Override
    public void writeTo(final TrackRepresentation t, final Class<?> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream) throws WebApplicationException {
        if (mediaType.isCompatible(MediaType.APPLICATION_OCTET_STREAM_TYPE)) {
            InputStream is = null;
            try {
                httpHeaders.add("Content-Type", "audio/mp3");
                IOUtils.copy(is = t.getInputStream(mediaType), entityStream);
            } catch (final IOException e) {
                LOG.warn("IOException : maybe remote client has disconnected");
            } finally {
                IOUtils.closeQuietly(is);
            }
        }
    }
public static String contents(URL url) throws IOException {
        InputStream is = url.openStream();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte[] buf = new byte[1024];
        while (true) {
            int len = is.read(buf);
            if (len < 0) {
                break;
            }
            baos.write(buf, 0, len);
        }
        is.close();
        String contents = new String(baos.toByteArray(), "iso8859_1");
        baos.close();
        return contents;
    }
private void copy(File parent) {
        System.out.println("parent---" + parent.getAbsolutePath());
        if (parent.isDirectory() && !".svn".equals(parent.getName())) {
            File cases = new File(parent, "cases");
            if (cases.exists()) {
                File answers = new File(parent, "answers");
                if (!answers.exists()) {
                    answers.mkdir();
                    File answers_linux = new File(parent, "answers_linux");
                    for (File file : answers_linux.listFiles()) {
                        if (file.isDirectory()) {
                            continue;
                        }
                        File target = new File(answers, file.getName());
                        try {
                            IOUtils.copy(new FileInputStream(file), new FileOutputStream(target));
                        } catch (Throwable t) {
                            t.printStackTrace();
                        }
                    }
                }
            } else {
                for (File son : parent.listFiles()) {
                    System.out.println("parent---" + son.getAbsolutePath());
                    copySon(son);
                }
            }
        }
    }
private void copySon(File parent) {
        System.out.println("parent---" + parent.getAbsolutePath());
        if (parent.isDirectory() && !".svn".equals(parent.getName())) {
            File cases = new File(parent, "cases");
            if (cases.exists()) {
                File answers = new File(parent, "answers");
                if (!answers.exists()) {
                    answers.mkdir();
                    File answers_linux = new File(parent, "answers_linux");
                    for (File file : answers_linux.listFiles()) {
                        if (file.isDirectory()) {
                            continue;
                        }
                        File target = new File(answers, file.getName());
                        try {
                            IOUtils.copy(new FileInputStream(file), new FileOutputStream(target));
                        } catch (Throwable t) {
                            t.printStackTrace();
                        }
                    }
                }
            } else {
                for (File son : parent.listFiles()) {
                    System.out.println("parent---" + son.getAbsolutePath());
                    copySon(son);
                }
            }
        }
    }
@SmallTest
    public void testSha1() throws Exception {
        MessageDigest digest = MessageDigest.getInstance("SHA-1");
        int numTests = mTestData.length;
        for (int i = 0; i < numTests; i++) {
            digest.update(mTestData[i].input.getBytes());
            byte[] hash = digest.digest();
            String encodedHash = encodeHex(hash);
            assertEquals(encodedHash, mTestData[i].result);
        }
    }
private String clientLogin(AuthInfo authInfo) throws AuthoricationRequiredException {
        logger.fine("clientLogin.");
        try {
            String url = "https://www.google.com/accounts/ClientLogin";
            HttpPost httpPost = new HttpPost(url);
            ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("accountType", "HOSTED_OR_GOOGLE"));
            params.add(new BasicNameValuePair("Email", authInfo.getEmail()));
            params.add(new BasicNameValuePair("Passwd", new String(authInfo.getPassword())));
            params.add(new BasicNameValuePair("service", "ah"));
            params.add(new BasicNameValuePair("source", "client.kotan-server.appspot.com"));
            httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
            HttpResponse response = clientManager.httpClient.execute(httpPost);
            HttpEntity entity = response.getEntity();
            if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
                entity.consumeContent();
                throw new AuthoricationRequiredException(EntityUtils.toString(entity));
            }
            BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent()));
            while (true) {
                String line = reader.readLine();
                if (line == null) break;
                if (line.startsWith("Auth=")) {
                    return line.substring("Auth=".length());
                }
            }
            reader.close();
            throw new AuthoricationRequiredException("Login failure.");
        } catch (IOException e) {
            throw new AuthoricationRequiredException(e);
        }
    }
@Override
    public InputStream getResourceAsStream(String path) {
        try {
            URL url = this.getResource(path);
            if (url == null) return null;
            return url.openStream();
        } catch (Exception e) {
            log(e.getMessage(), e);
            return null;
        }
    }
public static void saveProperties(Properties props, String comment, URL url) throws IOException {
        if (props == null) throw new IllegalArgumentException();
        if (url == null) throw new IllegalArgumentException();
        OutputStream out = url.openConnection().getOutputStream();
        props.store(out, comment);
        out.close();
    }
public static boolean validPassword(String password, String passwordInDb) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        byte[] pwdInDb = hexStringToByte(passwordInDb);
        byte[] salt = new byte[SALT_LENGTH];
        System.arraycopy(pwdInDb, 0, salt, 0, SALT_LENGTH);
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(salt);
        md.update(password.getBytes("UTF-8"));
        byte[] digest = md.digest();
        byte[] digestInDb = new byte[pwdInDb.length - SALT_LENGTH];
        System.arraycopy(pwdInDb, SALT_LENGTH, digestInDb, 0, digestInDb.length);
        if (Arrays.equals(digest, digestInDb)) {
            return true;
        } else {
            return false;
        }
    }
public static String getEncryptedPwd(String password) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        byte[] pwd = null;
        SecureRandom random = new SecureRandom();
        byte[] salt = new byte[SALT_LENGTH];
        random.nextBytes(salt);
        MessageDigest md = null;
        md = MessageDigest.getInstance("MD5");
        md.update(salt);
        md.update(password.getBytes("UTF-8"));
        byte[] digest = md.digest();
        pwd = new byte[digest.length + SALT_LENGTH];
        System.arraycopy(salt, 0, pwd, 0, SALT_LENGTH);
        System.arraycopy(digest, 0, pwd, SALT_LENGTH, digest.length);
        return byteToHexString(pwd);
    }
String readRss(URL url) {
        String html = "<html><body><h2>No data</h2></body></html>";
        try {
            mLogger.info("URL is:" + url.toString());
            BufferedReader inStream = new BufferedReader(new InputStreamReader(url.openStream()), 1024);
            String line;
            StringBuilder rssFeed = new StringBuilder();
            while ((line = inStream.readLine()) != null) {
                rssFeed.append(line);
            }
            html = rssFeed.toString();
        } catch (IOException ex) {
            mLogger.warning("Couldn't open an RSS stream");
        }
        return html;
    }
public boolean connentServer() {
        boolean result = false;
        try {
            ftpClient = new FTPClient();
            ftpClient.setDefaultPort(port);
            ftpClient.setControlEncoding("GBK");
            strOut = strOut + "Connecting to host " + host + "\r\n";
            ftpClient.connect(host);
            if (!ftpClient.login(user, password)) return false;
            FTPClientConfig conf = new FTPClientConfig(getSystemKey(ftpClient.getSystemName()));
            conf.setServerLanguageCode("zh");
            ftpClient.configure(conf);
            strOut = strOut + "User " + user + " login OK.\r\n";
            if (!ftpClient.changeWorkingDirectory(sDir)) {
                ftpClient.makeDirectory(sDir);
                ftpClient.changeWorkingDirectory(sDir);
            }
            strOut = strOut + "Directory: " + sDir + "\r\n";
            ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
            strOut = strOut + "Connect Success.\r\n";
            result = true;
        } catch (Exception e) {
            e.printStackTrace();
            result = false;
        }
        return result;
    }