semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public HttpResponse executeWithoutRewriting(HttpUriRequest request, HttpContext context) throws IOException {
        int code = -1;
        long start = SystemClock.elapsedRealtime();
        try {
            HttpResponse response;
            mConnectionAllocated.set(null);
            if (NetworkStatsEntity.shouldLogNetworkStats()) {
                int uid = android.os.Process.myUid();
                long startTx = NetStat.getUidTxBytes(uid);
                long startRx = NetStat.getUidRxBytes(uid);
                response = mClient.execute(request, context);
                HttpEntity origEntity = response == null ? null : response.getEntity();
                if (origEntity != null) {
                    long now = SystemClock.elapsedRealtime();
                    long elapsed = now - start;
                    NetworkStatsEntity entity = new NetworkStatsEntity(origEntity, mAppName, uid, startTx, startRx, elapsed, now);
                    response.setEntity(entity);
                }
            } else {
                response = mClient.execute(request, context);
            }
            code = response.getStatusLine().getStatusCode();
            return response;
        } finally {
            try {
                long elapsed = SystemClock.elapsedRealtime() - start;
                ContentValues values = new ContentValues();
                values.put(Checkin.Stats.COUNT, 1);
                values.put(Checkin.Stats.SUM, elapsed / 1000.0);
                values.put(Checkin.Stats.TAG, Checkin.Stats.Tag.HTTP_REQUEST + ":" + mAppName);
                mResolver.insert(Checkin.Stats.CONTENT_URI, values);
                if (mConnectionAllocated.get() == null && code >= 0) {
                    values.put(Checkin.Stats.TAG, Checkin.Stats.Tag.HTTP_REUSED + ":" + mAppName);
                    mResolver.insert(Checkin.Stats.CONTENT_URI, values);
                }
                String status = code < 0 ? "IOException" : Integer.toString(code);
                values.put(Checkin.Stats.TAG, Checkin.Stats.Tag.HTTP_STATUS + ":" + mAppName + ":" + status);
                mResolver.insert(Checkin.Stats.CONTENT_URI, values);
            } catch (Exception e) {
                Log.e(TAG, "Error recording stats", e);
            }
        }
    }
public HttpResponse execute(HttpUriRequest request, HttpContext context) throws IOException {
        URI uri = request.getURI();
        String original = uri.toString();
        UrlRules rules = UrlRules.getRules(mResolver);
        UrlRules.Rule rule = rules.matchRule(original);
        String rewritten = rule.apply(original);
        if (rewritten == null) {
            Log.w(TAG, "Blocked by " + rule.mName + ": " + original);
            throw new BlockedRequestException(rule);
        } else if (rewritten == original) {
            return executeWithoutRewriting(request, context);
        }
        try {
            uri = new URI(rewritten);
        } catch (URISyntaxException e) {
            throw new RuntimeException("Bad URL from rule: " + rule.mName, e);
        }
        RequestWrapper wrapper = wrapRequest(request);
        wrapper.setURI(uri);
        request = wrapper;
        if (LOCAL_LOGV) Log.v(TAG, "Rule " + rule.mName + ": " + original + " -> " + rewritten);
        return executeWithoutRewriting(request, context);
    }
private void weightAndPlaceClasses() {
        int rows = getRows();
        for (int curRow = _maxPackageRank; curRow < rows; curRow++) {
            xPos = getHGap() / 2;
            BOTLObjectSourceDiagramNode[] rowObject = getObjectsInRow(curRow);
            for (int i = 0; i < rowObject.length; i++) {
                if (curRow == _maxPackageRank) {
                    int nDownlinks = rowObject[i].getDownlinks().size();
                    rowObject[i].setWeight((nDownlinks > 0) ? (1 / nDownlinks) : 2);
                } else {
                    Vector uplinks = rowObject[i].getUplinks();
                    int nUplinks = uplinks.size();
                    if (nUplinks > 0) {
                        float average_col = 0;
                        for (int j = 0; j < uplinks.size(); j++) {
                            average_col += ((BOTLObjectSourceDiagramNode) (uplinks.elementAt(j))).getColumn();
                        }
                        average_col /= nUplinks;
                        rowObject[i].setWeight(average_col);
                    } else {
                        rowObject[i].setWeight(1000);
                    }
                }
            }
            int[] pos = new int[rowObject.length];
            for (int i = 0; i < pos.length; i++) {
                pos[i] = i;
            }
            boolean swapped = true;
            while (swapped) {
                swapped = false;
                for (int i = 0; i < pos.length - 1; i++) {
                    if (rowObject[pos[i]].getWeight() > rowObject[pos[i + 1]].getWeight()) {
                        int temp = pos[i];
                        pos[i] = pos[i + 1];
                        pos[i + 1] = temp;
                        swapped = true;
                    }
                }
            }
            for (int i = 0; i < pos.length; i++) {
                rowObject[pos[i]].setColumn(i);
                if ((i > _vMax) && (rowObject[pos[i]].getUplinks().size() == 0) && (rowObject[pos[i]].getDownlinks().size() == 0)) {
                    if (getColumns(rows - 1) > _vMax) {
                        rows++;
                    }
                    rowObject[pos[i]].setRank(rows - 1);
                } else {
                    rowObject[pos[i]].setLocation(new Point(xPos, yPos));
                    xPos += rowObject[pos[i]].getSize().getWidth() + getHGap();
                }
            }
            yPos += getRowHeight(curRow) + getVGap();
        }
    }
public void loginMD5() throws Exception {
        GetMethod get = new GetMethod("http://login.yahoo.com/config/login?.src=www&.done=http://www.yahoo.com");
        get.setRequestHeader("user-agent", "Mozilla/5.0 (Macintosh; U; PPC MacOS X; en-us) AppleWebKit/124 (KHTML, like Gecko) Safari/125.1");
        client.executeMethod(get);
        parseResponse(get.getResponseBodyAsStream());
        MessageDigest digest = MessageDigest.getInstance("MD5");
        digest.update(password.getBytes("US-ASCII"));
        String hash1 = new String(digest.digest(), "US-ASCII");
        String hash2 = hash1 + challenge;
        digest.update(hash2.getBytes("US-ASCII"));
        String hash = new String(digest.digest(), "US-ASCII");
        NameValuePair[] pairs = { new NameValuePair("login", login), new NameValuePair("password", hash), new NameValuePair(".save", "1"), new NameValuePair(".tries", "1"), new NameValuePair(".src", "www"), new NameValuePair(".md5", "1"), new NameValuePair(".hash", "1"), new NameValuePair(".js", "1"), new NameValuePair(".last", ""), new NameValuePair(".promo", ""), new NameValuePair(".intl", "us"), new NameValuePair(".bypass", ""), new NameValuePair(".u", u), new NameValuePair(".v", "0"), new NameValuePair(".challenge", challenge), new NameValuePair(".yplus", ""), new NameValuePair(".emailCode", ""), new NameValuePair("pkg", ""), new NameValuePair("stepid", ""), new NameValuePair(".ev", ""), new NameValuePair("hasMsgr", "0"), new NameValuePair(".chkP", "Y"), new NameValuePair(".done", "http://www.yahoo.com"), new NameValuePair(".persistent", "y") };
        get = new GetMethod("http://login.yahoo.com/config/login");
        get.setRequestHeader("user-agent", "Mozilla/5.0 (Macintosh; U; PPC MacOS X; en-us) AppleWebKit/124 (KHTML, like Gecko) Safari/125.1");
        get.addRequestHeader("Accept", "*/*");
        get.addRequestHeader("Accept-Language", "en-us, ja;q=0.21, de-de;q=0.86, de;q=0.79, fr-fr;q=0.71, fr;q=0.64, nl-nl;q=0.57, nl;q=0.50, it-it;q=0.43, it;q=0.36, ja-jp;q=0.29, en;q=0.93, es-es;q=0.14, es;q=0.07");
        get.setQueryString(pairs);
        client.executeMethod(get);
        get.getResponseBodyAsString();
    }
public static String hashPassword(String plaintext) {
        if (plaintext == null) {
            return "";
        }
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("SHA1");
            md.update(plaintext.getBytes("UTF-8"));
        } catch (Exception e) {
            logger.log(Level.SEVERE, "Problem hashing password.", e);
        }
        return new String(Base64.encodeBase64(md.digest()));
    }
public File copyLocalFileAsTempFileInExternallyAccessableDir(String localFileRef) throws IOException {
        log.debug("copyLocalFileAsTempFileInExternallyAccessableDir");
        File f = this.createTempFileInExternallyAccessableDir();
        FileChannel srcChannel = new FileInputStream(localFileRef).getChannel();
        FileChannel dstChannel = new FileOutputStream(f).getChannel();
        log.debug("before transferring via FileChannel from src-inputStream: " + localFileRef + " to dest-outputStream: " + f.getAbsolutePath());
        dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
        srcChannel.close();
        dstChannel.close();
        log.debug("copyLocalFileAsTempFileInExternallyAccessableDir returning: " + f.getAbsolutePath());
        return f;
    }
private InputStream fetch(String urlString) throws MalformedURLException, IOException {
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpGet request = new HttpGet(urlString);
        HttpResponse response = httpClient.execute(request);
        return response.getEntity().getContent();
    }
static String getMD5Hash(String str) throws NoSuchAlgorithmException {
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(str.getBytes());
        byte[] b = md.digest();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < b.length; i++) {
            int v = (int) b[i];
            v = v < 0 ? 0x100 + v : v;
            String cc = Integer.toHexString(v);
            if (cc.length() == 1) sb.append('0');
            sb.append(cc);
        }
        return sb.toString();
    }
@Override
    public void process(HttpServletRequest request, HttpServletResponse response) throws Exception {
        String userAgentGroup = processUserAgent(request);
        final LiwenxRequest lRequest = new LiwenxRequestImpl(request, response, messageSource, userAgentGroup);
        Locator loc = router.route(lRequest);
        if (loc instanceof RedirectLocator) {
            response.sendRedirect(((RedirectLocator) loc).getPage());
        } else {
            ((AbstractLiwenxRequest) lRequest).setRequestedLocator(loc);
            try {
                LiwenxResponse resp = processPage(lRequest, lRequest.getRequestedLocator(), maxRedirections);
                processHeaders(resp, response);
                processCookies(resp, response);
                if (resp instanceof ExternalRedirectionResponse) {
                    response.sendRedirect(((ExternalRedirectionResponse) resp).getRedirectTo());
                } else if (resp instanceof BinaryResponse) {
                    BinaryResponse bResp = (BinaryResponse) resp;
                    response.setContentType(bResp.getMimeType().toString());
                    IOUtils.copy(bResp.getInputStream(), response.getOutputStream());
                } else if (resp instanceof XmlResponse) {
                    final Element root = ((XmlResponse) resp).getXml();
                    Document doc = root.getDocument();
                    if (doc == null) {
                        doc = new Document(root);
                    }
                    final Locator l = lRequest.getCurrentLocator();
                    final Device device = l.getDevice();
                    response.setContentType(calculateContentType(device));
                    response.setCharacterEncoding(encoding);
                    if (device == Device.HTML) {
                        view.processView(doc, l.getLocale(), userAgentGroup, response.getWriter());
                    } else {
                        Serializer s = new Serializer(response.getOutputStream(), encoding);
                        s.write(doc);
                    }
                }
            } catch (PageNotFoundException e) {
                response.sendError(HttpServletResponse.SC_NOT_FOUND);
            } catch (TooManyRedirectionsException e) {
                throw e;
            } catch (Exception e) {
                throw e;
            }
        }
    }
public static Image getImage(URL url) throws IOException {
        InputStream is = null;
        try {
            is = url.openStream();
            Image img = getImage(is);
            img.setUrl(url);
            return img;
        } finally {
            if (is != null) {
                is.close();
            }
        }
    }
public void render(ServiceContext serviceContext) throws Exception {
        if (serviceContext.getTemplateName() == null) throw new Exception("no Template defined for service: " + serviceContext.getServiceInfo().getRefName());
        File f = new File(serviceContext.getTemplateName());
        serviceContext.getResponse().setContentLength((int) f.length());
        InputStream in = new FileInputStream(f);
        IOUtils.copy(in, serviceContext.getResponse().getOutputStream(), 0, (int) f.length());
        in.close();
    }
public void actionPerformed(ActionEvent e) {
                final File inputFile = KeyboardHero.midiFile();
                try {
                    if (inputFile == null) return;
                    final File dir = (new File(Util.DATA_FOLDER + MidiSong.MIDI_FILES_DIR));
                    if (dir.exists()) {
                        if (!dir.isDirectory()) {
                            Util.error(Util.getMsg("Err_MidiFilesDirNotDirectory"), dir.getParent());
                            return;
                        }
                    } else if (!dir.mkdirs()) {
                        Util.error(Util.getMsg("Err_CouldntMkDir"), dir.getParent());
                        return;
                    }
                    File outputFile = new File(dir.getPath() + File.separator + inputFile.getName());
                    if (!outputFile.exists() || KeyboardHero.confirm("Que_FileExistsOverwrite")) {
                        final FileChannel inChannel = new FileInputStream(inputFile).getChannel();
                        inChannel.transferTo(0, inChannel.size(), new FileOutputStream(outputFile).getChannel());
                    }
                } catch (Exception ex) {
                    Util.getMsg(Util.getMsg("Err_CouldntImportSong"), ex.toString());
                }
                SongSelector.refresh();
            }
public static void copyFile(File in, File outDir) throws IOException {
        FileChannel sourceChannel = null;
        FileChannel destinationChannel = null;
        try {
            sourceChannel = new FileInputStream(in).getChannel();
            File out = new File(outDir, in.getName());
            destinationChannel = new FileOutputStream(out).getChannel();
            sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
        } finally {
            try {
                if (sourceChannel != null) {
                    sourceChannel.close();
                }
            } finally {
                if (destinationChannel != null) {
                    destinationChannel.close();
                }
            }
        }
    }
public static void main(String[] args) throws Exception {
        SocketConnector socketConnector = new SocketConnector();
        socketConnector.setPort(6080);
        SslSocketConnector sslSocketConnector = new SslSocketConnector();
        sslSocketConnector.setPort(6443);
        String serverKeystore = MockHttpListenerWithAuthentication.class.getClassLoader().getResource("cert/serverkeystore.jks").getPath();
        sslSocketConnector.setKeystore(serverKeystore);
        sslSocketConnector.setKeyPassword("serverpass");
        String serverTruststore = MockHttpListenerWithAuthentication.class.getClassLoader().getResource("cert/servertruststore.jks").getPath();
        sslSocketConnector.setTruststore(serverTruststore);
        sslSocketConnector.setTrustPassword("serverpass");
        server.addConnector(socketConnector);
        server.addConnector(sslSocketConnector);
        SecurityHandler securityHandler = createBasicAuthenticationSecurityHandler();
        HandlerList handlerList = new HandlerList();
        handlerList.addHandler(securityHandler);
        handlerList.addHandler(new AbstractHandler() {

            @Override
            public void handle(String s, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, int i) throws IOException, ServletException {
                System.out.println("uri: " + httpServletRequest.getRequestURI());
                System.out.println("queryString: " + httpServletRequest.getQueryString());
                System.out.println("method: " + httpServletRequest.getMethod());
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                IOUtils.copy(httpServletRequest.getInputStream(), baos);
                System.out.println("body: " + baos.toString());
                PrintWriter writer = httpServletResponse.getWriter();
                writer.append("testsvar");
                Random r = new Random();
                for (int j = 0; j < 10; j++) {
                    int value = r.nextInt(Integer.MAX_VALUE);
                    writer.append(value + "");
                }
                System.out.println();
                writer.close();
                httpServletResponse.setStatus(HttpServletResponse.SC_OK);
            }
        });
        server.addHandler(handlerList);
        server.start();
    }
@Override
            public void handle(String s, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, int i) throws IOException, ServletException {
                System.out.println("uri: " + httpServletRequest.getRequestURI());
                System.out.println("queryString: " + httpServletRequest.getQueryString());
                System.out.println("method: " + httpServletRequest.getMethod());
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                IOUtils.copy(httpServletRequest.getInputStream(), baos);
                System.out.println("body: " + baos.toString());
                PrintWriter writer = httpServletResponse.getWriter();
                writer.append("testsvar");
                Random r = new Random();
                for (int j = 0; j < 10; j++) {
                    int value = r.nextInt(Integer.MAX_VALUE);
                    writer.append(value + "");
                }
                System.out.println();
                writer.close();
                httpServletResponse.setStatus(HttpServletResponse.SC_OK);
            }
private int mergeFiles(Merge merge) throws MojoExecutionException {
        String encoding = DEFAULT_ENCODING;
        if (merge.getEncoding() != null && merge.getEncoding().length() > 0) {
            encoding = merge.getEncoding();
        }
        int numMergedFiles = 0;
        Writer ostream = null;
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(merge.getTargetFile(), true);
            ostream = new OutputStreamWriter(fos, encoding);
            BufferedWriter output = new BufferedWriter(ostream);
            for (String orderingName : this.orderingNames) {
                List<File> files = this.orderedFiles.get(orderingName);
                if (files != null) {
                    getLog().info("Appending: " + files.size() + " files that matched the name: " + orderingName + " to the target file: " + merge.getTargetFile().getAbsolutePath() + "...");
                    for (File file : files) {
                        String fileName = file.getName();
                        getLog().info("Appending file: " + fileName + " to the target file: " + merge.getTargetFile().getAbsolutePath() + "...");
                        InputStream input = null;
                        try {
                            input = new FileInputStream(file);
                            if (merge.getSeparator() != null && merge.getSeparator().trim().length() > 0) {
                                String replaced = merge.getSeparator().trim();
                                replaced = replaced.replace("\n", "");
                                replaced = replaced.replace("\t", "");
                                replaced = replaced.replace("#{file.name}", fileName);
                                replaced = replaced.replace("#{parent.name}", file.getParentFile() != null ? file.getParentFile().getName() : "");
                                replaced = replaced.replace("\\n", "\n");
                                replaced = replaced.replace("\\t", "\t");
                                getLog().debug("Appending separator: " + replaced);
                                IOUtils.copy(new StringReader(replaced), output);
                            }
                            IOUtils.copy(input, output, encoding);
                        } catch (IOException ioe) {
                            throw new MojoExecutionException("Failed to append file: " + fileName + " to output file", ioe);
                        } finally {
                            IOUtils.closeQuietly(input);
                        }
                        numMergedFiles++;
                    }
                }
            }
            output.flush();
        } catch (IOException ioe) {
            throw new MojoExecutionException("Failed to open stream file to output file: " + merge.getTargetFile().getAbsolutePath(), ioe);
        } finally {
            if (fos != null) {
                IOUtils.closeQuietly(fos);
            }
            if (ostream != null) {
                IOUtils.closeQuietly(ostream);
            }
        }
        return numMergedFiles;
    }