semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private void connect(byte[] bData) {
        System.out.println("Connecting to: " + url.toString());
        String SOAPAction = "";
        URLConnection connection = null;
        try {
            connection = url.openConnection();
            httpConn = (HttpURLConnection) connection;
            httpConn.setRequestProperty("Content-Length", String.valueOf(bData.length));
            httpConn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
            httpConn.setRequestProperty("SOAPAction", SOAPAction);
            httpConn.setRequestMethod("POST");
            httpConn.setDoOutput(true);
            httpConn.setDoInput(true);
        } catch (IOException ioExp) {
            CommonLogger.error(this, "Error while connecting to  SOAP server !", ioExp);
        }
    }
public String elementsSearch() {
        int index = 0;
        for (int i1 = 0; i1 < 6; i1++) {
            for (int i2 = 0; i2 < 5; i2++) {
                if (index < 5) {
                    if (initialMatrix[i1][i2] > 0) {
                        finalMatrix[index] = initialMatrix[i1][i2];
                        index++;
                    }
                } else break;
            }
        }
        int temp;
        for (int i = 0; i < finalMatrix.length; i++) {
            for (int j = 0; j < finalMatrix.length - 1; j++) {
                if (finalMatrix[j] < finalMatrix[j + 1]) {
                    temp = finalMatrix[j];
                    finalMatrix[j] = finalMatrix[j + 1];
                    finalMatrix[j + 1] = temp;
                }
            }
        }
        String result = "";
        for (int k : finalMatrix) result += k + " ";
        return result;
    }
protected void createFile(File sourceActionDirectory, File destinationActionDirectory, LinkedList<String> segments) throws DuplicateActionFileException {
        File currentSrcDir = sourceActionDirectory;
        File currentDestDir = destinationActionDirectory;
        String segment = "";
        for (int i = 0; i < segments.size() - 1; i++) {
            segment = segments.get(i);
            currentSrcDir = new File(currentSrcDir, segment);
            currentDestDir = new File(currentDestDir, segment);
        }
        if (currentSrcDir != null && currentDestDir != null) {
            File srcFile = new File(currentSrcDir, segments.getLast());
            if (srcFile.exists()) {
                File destFile = new File(currentDestDir, segments.getLast());
                if (destFile.exists()) {
                    throw new DuplicateActionFileException(srcFile.toURI().toASCIIString());
                }
                try {
                    FileChannel srcChannel = new FileInputStream(srcFile).getChannel();
                    FileChannel destChannel = new FileOutputStream(destFile).getChannel();
                    ByteBuffer buffer = ByteBuffer.allocate((int) srcChannel.size());
                    while (srcChannel.position() < srcChannel.size()) {
                        srcChannel.read(buffer);
                    }
                    srcChannel.close();
                    buffer.rewind();
                    destChannel.write(buffer);
                    destChannel.close();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }
    }
@Override
    public JSONObject getJsonObj(Trip trip, List<Waypoint> stops) throws IOException {
        JSONObject jsonObject = null;
        try {
            List<String> filtered = new LinkedList<String>();
            filtered.add(trip.getWaypoint().getFromLocation().getCity().replaceAll("\\W+", "+"));
            filtered.add(trip.getWaypoint().getToLocation().getCity().replaceAll("\\W+", "+"));
            for (Waypoint w : stops) {
                String from = w.getFromLocation().getCity().replaceAll("\\W+", "+");
                if (!filtered.contains(from)) filtered.add(from);
                String to = w.getToLocation().getCity().replaceAll("\\W+", "+");
                if (!filtered.contains(to)) filtered.add(to);
            }
            StringBuilder urlBuilder = new StringBuilder();
            urlBuilder.append("http://maps.google.com/maps/api/directions/json");
            urlBuilder.append("?origin=").append(filtered.get(0));
            urlBuilder.append("&destination=").append(filtered.get(1));
            if (filtered.size() > 2) {
                urlBuilder.append("&waypoints=");
                for (int i = 2; i < filtered.size() - 1; i++) urlBuilder.append(filtered.get(i)).append("|");
                urlBuilder.append(filtered.get(filtered.size() - 1));
            }
            urlBuilder.append("&sensor=false");
            BufferedReader in = new BufferedReader(new InputStreamReader(new URL(urlBuilder.toString()).openStream()));
            StringBuilder answerBuilder = new StringBuilder();
            String inputLine;
            while ((inputLine = in.readLine()) != null) answerBuilder.append(inputLine);
            in.close();
            jsonObject = new JSONObject(answerBuilder.toString());
        } catch (JSONException e) {
            logger.error("Problem with initializing JSONObject", e);
        }
        return jsonObject;
    }
protected void fetchDicomSopInstance(File result) throws Exception {
        try {
            URL url = new URL(this.config.getUrl("wadoserver.url").toString() + "?requestType=WADO&contentType=text/xml" + "&studyUID=" + publicationProperties.getProperty("studyUID") + "&seriesUID=" + publicationProperties.getProperty("seriesUID") + "&objectUID=" + publicationProperties.getProperty("objectUID"));
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            OutputStream ostream;
            InputStream istream;
            connection.setUseCaches(false);
            connection.setRequestProperty("accept", "text/xml");
            connection.connect();
            if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
                throw new Exception("Error fetching DICOM SOP instance (" + connection.getResponseCode() + " " + connection.getResponseMessage() + ")");
            }
            ostream = new BufferedOutputStream(new FileOutputStream(result));
            try {
                istream = connection.getInputStream();
                Utilities.copyStream(istream, ostream);
            } finally {
                ostream.close();
            }
        } catch (Exception e) {
            throw new Exception("Error fetching DICOM SOP instance.", e);
        }
    }
public void conMail(MailObject mail) throws NetworkException, ContentException {
        HttpClient client = HttpConfig.newInstance();
        String url = HttpConfig.bbsURL() + HttpConfig.BBS_MAIL_CON + mail.getId() + "&" + HttpConfig.BBS_MAIL_N_PARAM_NAME + "=" + mail.getNumber();
        HttpGet get = new HttpGet(url);
        try {
            HttpResponse response = client.execute(get);
            HttpEntity entity = response.getEntity();
            if (HTTPUtil.isXmlContentType(response)) {
                Document doc = XmlOperator.readDocument(entity.getContent());
                BBSBodyParseHelper.parseMailContent(doc, mail);
            } else {
                String msg = BBSBodyParseHelper.parseFailMsg(entity);
                throw new ContentException(msg);
            }
        } catch (ClientProtocolException e) {
            e.printStackTrace();
            throw new NetworkException(e);
        } catch (IOException e) {
            e.printStackTrace();
            throw new NetworkException(e);
        }
    }
public void conReMail(MailObject mail) throws NetworkException, ContentException {
        HttpClient client = HttpConfig.newInstance();
        String url = HttpConfig.bbsURL() + HttpConfig.BBS_MAIL_RECON + mail.getNumber();
        HttpGet get = new HttpGet(url);
        try {
            HttpResponse response = client.execute(get);
            HttpEntity entity = response.getEntity();
            if (HTTPUtil.isXmlContentType(response)) {
                Document doc = XmlOperator.readDocument(entity.getContent());
                BBSBodyParseHelper.parseMailReContent(doc, mail);
            } else {
                String msg = BBSBodyParseHelper.parseFailMsg(entity);
                throw new ContentException(msg);
            }
        } catch (ClientProtocolException e) {
            e.printStackTrace();
            throw new NetworkException(e);
        } catch (IOException e) {
            e.printStackTrace();
            throw new NetworkException(e);
        }
    }
public boolean sendMail(MailObject mail, boolean backup) throws NetworkException, ContentException {
        HttpClient client = HttpConfig.newInstance();
        HttpPost post = new HttpPost(HttpConfig.bbsURL() + HttpConfig.BBS_MAIL_SEND);
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair(HttpConfig.BBS_MAIL_SEND_REF_PARAM_NAME, "pstmail"));
        nvps.add(new BasicNameValuePair(HttpConfig.BBS_MAIL_SEND_RECV_PARAM_NAME, mail.getSender()));
        nvps.add(new BasicNameValuePair(HttpConfig.BBS_MAIL_SEND_TITLE_PARAM_NAME, mail.getTitle()));
        nvps.add(new BasicNameValuePair(HttpConfig.BBS_MAIL_SEND_CONTENT_PARAM_NAME, mail.getContent()));
        if (backup) nvps.add(new BasicNameValuePair(HttpConfig.BBS_MAIL_SEND_BACKUP_PARAM_NAME, "backup"));
        try {
            post.setEntity(new UrlEncodedFormEntity(nvps, BBSBodyParseHelper.BBS_CHARSET));
            HttpResponse response = client.execute(post);
            HttpEntity entity = response.getEntity();
            if (HTTPUtil.isHttp200(response)) {
                HTTPUtil.consume(response.getEntity());
                return true;
            } else {
                String msg = BBSBodyParseHelper.parseFailMsg(entity);
                throw new ContentException(msg);
            }
        } catch (ClientProtocolException e) {
            e.printStackTrace();
            throw new NetworkException(e);
        } catch (IOException e) {
            e.printStackTrace();
            throw new NetworkException(e);
        }
    }
public boolean delMail(MailObject mail) throws NetworkException, ContentException {
        HttpClient client = HttpConfig.newInstance();
        HttpGet get = new HttpGet(HttpConfig.bbsURL() + HttpConfig.BBS_MAIL_DEL + mail.getId());
        try {
            HttpResponse response = client.execute(get);
            HttpEntity entity = response.getEntity();
            if (HTTPUtil.isXmlContentType(response)) {
                HTTPUtil.consume(response.getEntity());
                return true;
            } else {
                String msg = BBSBodyParseHelper.parseFailMsg(entity);
                throw new ContentException(msg);
            }
        } catch (ClientProtocolException e) {
            e.printStackTrace();
            throw new NetworkException(e);
        } catch (IOException e) {
            e.printStackTrace();
            throw new NetworkException(e);
        }
    }
public static final synchronized String hash(String data) {
        if (digest == null) {
            try {
                digest = MessageDigest.getInstance("MD5");
            } catch (NoSuchAlgorithmException nsae) {
                System.err.println("Failed to load the MD5 MessageDigest. " + "We will be unable to function normally.");
                nsae.printStackTrace();
            }
        }
        digest.update(data.getBytes());
        return encodeHex(digest.digest());
    }
public synchronized String encrypt(String plaintext) {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("SHA1");
        } catch (NoSuchAlgorithmException noSuchAlgorithmException) {
            noSuchAlgorithmException.printStackTrace();
        }
        try {
            md.update(plaintext.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException unsupportedEncodingException) {
            unsupportedEncodingException.printStackTrace();
        }
        byte raw[] = md.digest();
        String hash = (new BASE64Encoder()).encode(raw);
        return hash;
    }
public String httpRequestByPOST(String url, int timeout, List<NameValuePair> params) {
        String response = "";
        try {
            HttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(url);
            httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
            HttpResponse serverResponse = httpClient.execute(httpPost);
            StatusLine statusLine = serverResponse.getStatusLine();
            if (statusLine.getStatusCode() < 400) {
                InputStream inputStream = serverResponse.getEntity().getContent();
                InputStreamReader inputReader = new InputStreamReader(inputStream);
                BufferedReader bufferedReader = new BufferedReader(inputReader);
                StringBuffer buffer = new StringBuffer();
                String line;
                while ((line = bufferedReader.readLine()) != null) {
                    buffer.append(line);
                }
                response = buffer.toString();
                inputStream.close();
            } else {
                this.lastErrorCode = String.valueOf(statusLine.getStatusCode());
                this.lastErrorMessage = statusLine.getReasonPhrase();
                return null;
            }
        } catch (IOException e) {
            this.lastErrorCode = "-1";
            this.lastErrorMessage = e.getLocalizedMessage();
            return null;
        }
        return response;
    }
public static Bitmap loadBitmap(String token, String id, final String type) {
        String imageUrl = XMLfunctions.URL;
        imageUrl = imageUrl.replace("{0}", token);
        imageUrl = imageUrl.replace("{1}", id);
        InputStream imageStream = null;
        try {
            HttpGet httpRequest = new HttpGet(new URL(imageUrl).toURI());
            HttpResponse response = (HttpResponse) new DefaultHttpClient().execute(httpRequest);
            httpRequest = null;
            BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(response.getEntity());
            response = null;
            imageStream = bufHttpEntity.getContent();
            bufHttpEntity = null;
            if (imageStream != null) {
                final BitmapFactory.Options options = new BitmapFactory.Options();
                if (type.equals("image")) {
                    options.inSampleSize = 2;
                }
                return BitmapFactory.decodeStream(imageStream, null, options);
            } else {
            }
        } catch (IOException e) {
        } catch (URISyntaxException e) {
        } finally {
            if (imageStream != null) closeStream(imageStream);
        }
        return null;
    }
public static Bitmap loadPhotoBitmap(final String imageUrl, final String type) {
        InputStream imageStream = null;
        try {
            HttpGet httpRequest = new HttpGet(new URL(imageUrl).toURI());
            HttpResponse response = (HttpResponse) new DefaultHttpClient().execute(httpRequest);
            httpRequest = null;
            BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(response.getEntity());
            response = null;
            imageStream = bufHttpEntity.getContent();
            bufHttpEntity = null;
            if (imageStream != null) {
                final BitmapFactory.Options options = new BitmapFactory.Options();
                if (type.equals("image")) {
                    options.inSampleSize = 2;
                }
                return BitmapFactory.decodeStream(imageStream, null, options);
            } else {
            }
        } catch (IOException e) {
        } catch (URISyntaxException e) {
        } finally {
            if (imageStream != null) closeStream(imageStream);
        }
        return null;
    }
public static void translateTableMetaData(String baseDir, String tableName, NameSpaceDefinition nsDefinition) throws Exception {
        setVosiNS(baseDir, "table", nsDefinition);
        String filename = baseDir + "table.xsl";
        Scanner s = new Scanner(new File(filename));
        PrintWriter fw = new PrintWriter(new File(baseDir + tableName + ".xsl"));
        while (s.hasNextLine()) {
            fw.println(s.nextLine().replaceAll("TABLENAME", tableName));
        }
        s.close();
        fw.close();
        applyStyle(baseDir + "tables.xml", baseDir + tableName + ".json", baseDir + tableName + ".xsl");
    }
public static void translateTableAttributes(String baseDir, String tableName, NameSpaceDefinition nsDefinition) throws Exception {
        setVosiNS(baseDir, "table_att", nsDefinition);
        String filename = baseDir + "table_att.xsl";
        Scanner s = new Scanner(new File(filename));
        PrintWriter fw = new PrintWriter(new File(baseDir + tableName + "_att.xsl"));
        while (s.hasNextLine()) {
            fw.println(s.nextLine().replaceAll("TABLENAME", tableName));
        }
        s.close();
        fw.close();
        applyStyle(baseDir + "tables.xml", baseDir + tableName + "_att.json", baseDir + tableName + "_att.xsl");
    }
private static String myCrypt(String password, String seed) throws RuntimeException {
        String out = null;
        int count = 8;
        MessageDigest digester;
        if (!seed.substring(0, 3).equals("$H$")) {
            byte[] randomBytes = new byte[6];
            java.util.Random randomGenerator = new java.util.Random();
            randomGenerator.nextBytes(randomBytes);
            seed = genSalt(randomBytes);
        }
        String salt = seed.substring(4, 12);
        if (salt.length() != 8) {
            throw new RuntimeException("Error hashing password - Invalid seed.");
        }
        byte[] sha1Hash = new byte[40];
        try {
            digester = MessageDigest.getInstance("SHA-1");
            digester.update((salt + password).getBytes("iso-8859-1"), 0, (salt + password).length());
            sha1Hash = digester.digest();
            do {
                byte[] CombinedBytes = new byte[sha1Hash.length + password.length()];
                System.arraycopy(sha1Hash, 0, CombinedBytes, 0, sha1Hash.length);
                System.arraycopy(password.getBytes("iso-8859-1"), 0, CombinedBytes, sha1Hash.length, password.getBytes("iso-8859-1").length);
                digester.update(CombinedBytes, 0, CombinedBytes.length);
                sha1Hash = digester.digest();
            } while (--count > 0);
            out = seed.substring(0, 12);
            out += encode64(sha1Hash);
        } catch (NoSuchAlgorithmException Ex) {
            log.error("Error hashing password.", Ex);
        } catch (UnsupportedEncodingException Ex) {
            log.error("Error hashing password.", Ex);
        }
        if (out == null) {
            throw new RuntimeException("Error hashing password - out = null");
        }
        return out;
    }
protected void loadUrl(URL url) throws BuildException {
        Properties props = new Properties();
        log("Loading " + url, Project.MSG_VERBOSE);
        try {
            InputStream is = url.openStream();
            try {
                loadProperties(props, is, url.getFile().endsWith(".xml"));
            } finally {
                if (is != null) {
                    is.close();
                }
            }
            addProperties(props);
        } catch (IOException ex) {
            throw new BuildException(ex, getLocation());
        }
    }
private static void identify(ContentNetwork cn, String str) {
        try {
            URL url = new URL(str);
            HttpURLConnection con = (HttpURLConnection) url.openConnection();
            UrlUtils.setBrowserHeaders(con, null);
            String key = "cn." + cn.getID() + ".identify.cookie";
            String cookie = COConfigurationManager.getStringParameter(key, null);
            if (cookie != null) {
                con.setRequestProperty("Cookie", cookie + ";");
            }
            con.setRequestProperty("Connection", "close");
            con.getResponseCode();
            cookie = con.getHeaderField("Set-Cookie");
            if (cookie != null) {
                String[] bits = cookie.split(";");
                if (bits.length > 0 && bits[0].length() > 0) {
                    COConfigurationManager.setParameter(key, bits[0]);
                }
            }
        } catch (Throwable e) {
        }
    }
public void render(final HttpServletRequest request, final HttpServletResponse response, InputStream inputStream, final Throwable t, final String contentType, final String encoding) throws Exception {
        if (contentType != null) {
            response.setContentType(contentType);
        }
        if (encoding != null) {
            response.setCharacterEncoding(encoding);
        }
        IOUtils.copy(inputStream, response.getOutputStream());
    }
private void connectAndLogin() throws SocketException, IOException, ClassNotFoundException, SQLException, FileNotFoundException {
        lastOperationTime = System.currentTimeMillis();
        exit();
        ftp = new FTPClient();
        ftp.connect(SERVER);
        ftp.login(USERNAME, PASSWORD);
        ftp.enterLocalPassiveMode();
        ftp.setFileType(FTP.BINARY_FILE_TYPE);
        System.out.println("Connected to " + SERVER + ".");
        db = new DB(propertiesPath);
    }