semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void _getPlotTypes() {
        boolean gotPlots = false;
        while (!gotPlots) {
            try {
                _myPlotTypes = new Vector[2];
                _myPlotTypes[0] = new Vector();
                _myPlotTypes[1] = new Vector();
                URL dataurl = new URL(getDocumentBase(), plotTypeFile);
                BufferedReader readme = new BufferedReader(new InputStreamReader(new GZIPInputStream(dataurl.openStream())));
                while (true) {
                    String S = readme.readLine();
                    if (S == null) break;
                    StringTokenizer st = new StringTokenizer(S);
                    _myPlotTypes[0].addElement(st.nextToken());
                    if (st.hasMoreTokens()) {
                        _myPlotTypes[1].addElement(st.nextToken());
                    } else {
                        _myPlotTypes[1].addElement((String) _myPlotTypes[0].lastElement());
                    }
                }
                gotPlots = true;
            } catch (IOException e) {
                _myPlotTypes[0].removeAllElements();
                _myPlotTypes[1].removeAllElements();
                gotPlots = false;
            }
        }
    }
public static String getHash(String input) {
        MessageDigest m;
        try {
            m = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return null;
        }
        m.update(input.getBytes(), 0, input.length());
        return new BigInteger(1, m.digest()).toString(16);
    }
private static boolean genCustRatingFileAndMovieIndexFile(String completePath, String masterFile, String CustRatingFileName, String MovieIndexFileName) {
        try {
            File inFile = new File(completePath + fSep + "SmartGRAPE" + fSep + masterFile);
            FileChannel inC = new FileInputStream(inFile).getChannel();
            File outFile1 = new File(completePath + fSep + "SmartGRAPE" + fSep + MovieIndexFileName);
            FileChannel outC1 = new FileOutputStream(outFile1, true).getChannel();
            File outFile2 = new File(completePath + fSep + "SmartGRAPE" + fSep + CustRatingFileName);
            FileChannel outC2 = new FileOutputStream(outFile2, true).getChannel();
            int fileSize = (int) inC.size();
            int totalNoDataRows = fileSize / 7;
            ByteBuffer mappedBuffer = inC.map(FileChannel.MapMode.READ_ONLY, 0, fileSize);
            int startIndex = 1, count = 0;
            short currentMovie = 1;
            while (mappedBuffer.hasRemaining()) {
                count++;
                short movieName = mappedBuffer.getShort();
                int customer = mappedBuffer.getInt();
                byte rating = mappedBuffer.get();
                if (movieName != currentMovie) {
                    ByteBuffer outBuf1 = ByteBuffer.allocate(10);
                    outBuf1.putShort(currentMovie);
                    outBuf1.putInt(startIndex);
                    outBuf1.putInt(count - 1);
                    outBuf1.flip();
                    outC1.write(outBuf1);
                    currentMovie = movieName;
                    startIndex = count;
                }
                ByteBuffer outBuf2 = ByteBuffer.allocate(5);
                outBuf2.putInt(customer);
                outBuf2.put(rating);
                outBuf2.flip();
                outC2.write(outBuf2);
            }
            ByteBuffer endOfIndexFile = ByteBuffer.allocate(10);
            endOfIndexFile.putShort(currentMovie);
            endOfIndexFile.putInt(startIndex);
            endOfIndexFile.putInt(100480506);
            endOfIndexFile.flip();
            outC1.write(endOfIndexFile);
            outC1.close();
            outC2.close();
            return true;
        } catch (IOException e) {
            System.err.println(e);
            return false;
        }
    }
private static boolean genCustomerLocationsFileAndCustomerIndexFile(String completePath, String masterFile, String CustLocationsFileName, String CustIndexFileName) {
        try {
            TIntObjectHashMap CustInfoHash = new TIntObjectHashMap(480189, 1);
            File inFile = new File(completePath + fSep + "SmartGRAPE" + fSep + masterFile);
            FileChannel inC = new FileInputStream(inFile).getChannel();
            File outFile1 = new File(completePath + fSep + "SmartGRAPE" + fSep + CustIndexFileName);
            FileChannel outC1 = new FileOutputStream(outFile1, true).getChannel();
            File outFile2 = new File(completePath + fSep + "SmartGRAPE" + fSep + CustLocationsFileName);
            FileChannel outC2 = new FileOutputStream(outFile2, true).getChannel();
            int fileSize = (int) inC.size();
            int totalNoDataRows = fileSize / 7;
            for (int i = 1; i <= totalNoDataRows; i++) {
                ByteBuffer mappedBuffer = ByteBuffer.allocate(7);
                inC.read(mappedBuffer);
                mappedBuffer.position(0);
                short movieName = mappedBuffer.getShort();
                int customer = mappedBuffer.getInt();
                byte rating = mappedBuffer.get();
                mappedBuffer.clear();
                if (CustInfoHash.containsKey(customer)) {
                    TIntArrayList locations = (TIntArrayList) CustInfoHash.get(customer);
                    locations.add(i);
                    CustInfoHash.put(customer, locations);
                } else {
                    TIntArrayList locations = new TIntArrayList();
                    locations.add(i);
                    CustInfoHash.put(customer, locations);
                }
            }
            int[] customers = CustInfoHash.keys();
            Arrays.sort(customers);
            int count = 1;
            for (int i = 0; i < customers.length; i++) {
                int customer = customers[i];
                TIntArrayList locations = (TIntArrayList) CustInfoHash.get(customer);
                int noRatingsForCust = locations.size();
                ByteBuffer outBuf1 = ByteBuffer.allocate(12);
                outBuf1.putInt(customer);
                outBuf1.putInt(count);
                outBuf1.putInt(count + noRatingsForCust - 1);
                outBuf1.flip();
                outC1.write(outBuf1);
                count += noRatingsForCust;
                for (int j = 0; j < locations.size(); j++) {
                    ByteBuffer outBuf2 = ByteBuffer.allocate(4);
                    outBuf2.putInt(locations.get(j));
                    outBuf2.flip();
                    outC2.write(outBuf2);
                }
            }
            inC.close();
            outC1.close();
            outC2.close();
            return true;
        } catch (IOException e) {
            System.err.println(e);
            return false;
        }
    }
private static boolean genMovieRatingFile(String completePath, String masterFile, String CustLocationsFileName, String MovieRatingFileName) {
        try {
            File inFile1 = new File(completePath + fSep + "SmartGRAPE" + fSep + masterFile);
            FileChannel inC1 = new FileInputStream(inFile1).getChannel();
            int fileSize1 = (int) inC1.size();
            int totalNoDataRows = fileSize1 / 7;
            ByteBuffer mappedBuffer = inC1.map(FileChannel.MapMode.READ_ONLY, 0, fileSize1);
            System.out.println("Loaded master binary file");
            File inFile2 = new File(completePath + fSep + "SmartGRAPE" + fSep + CustLocationsFileName);
            FileChannel inC2 = new FileInputStream(inFile2).getChannel();
            int fileSize2 = (int) inC2.size();
            System.out.println(fileSize2);
            File outFile = new File(completePath + fSep + "SmartGRAPE" + fSep + MovieRatingFileName);
            FileChannel outC = new FileOutputStream(outFile, true).getChannel();
            for (int i = 0; i < 1; i++) {
                ByteBuffer locBuffer = inC2.map(FileChannel.MapMode.READ_ONLY, i * fileSize2, fileSize2);
                System.out.println("Loaded cust location file chunk: " + i);
                while (locBuffer.hasRemaining()) {
                    int locationToRead = locBuffer.getInt();
                    mappedBuffer.position((locationToRead - 1) * 7);
                    short movieName = mappedBuffer.getShort();
                    int customer = mappedBuffer.getInt();
                    byte rating = mappedBuffer.get();
                    ByteBuffer outBuf = ByteBuffer.allocate(3);
                    outBuf.putShort(movieName);
                    outBuf.put(rating);
                    outBuf.flip();
                    outC.write(outBuf);
                }
            }
            mappedBuffer.clear();
            inC1.close();
            inC2.close();
            outC.close();
            return true;
        } catch (IOException e) {
            System.err.println(e);
            return false;
        }
    }
private static boolean prepareProbeFile(String completePath, String outputFile) {
        try {
            File inFile = new File(completePath + fSep + "probe.txt");
            FileChannel inC = new FileInputStream(inFile).getChannel();
            BufferedReader br = new BufferedReader(new FileReader(inFile));
            File outFile = new File(completePath + fSep + "SmartGRAPE" + fSep + outputFile);
            FileChannel outC = new FileOutputStream(outFile, true).getChannel();
            boolean endOfFile = true;
            short movieName = 0;
            int customer = 0;
            while (endOfFile) {
                String line = br.readLine();
                if (line != null) {
                    if (line.indexOf(":") >= 0) {
                        movieName = new Short(line.substring(0, line.length() - 1)).shortValue();
                    } else {
                        customer = new Integer(line).intValue();
                        ByteBuffer outBuf = ByteBuffer.allocate(6);
                        outBuf.putShort(movieName);
                        outBuf.putInt(customer);
                        outBuf.flip();
                        outC.write(outBuf);
                    }
                } else endOfFile = false;
            }
            br.close();
            outC.close();
            return true;
        } catch (IOException e) {
            System.err.println(e);
            return false;
        }
    }
private static boolean prepareQualifyingFile(String completePath, String outputFile) {
        try {
            File inFile = new File(completePath + fSep + "qualifying.txt");
            FileChannel inC = new FileInputStream(inFile).getChannel();
            BufferedReader br = new BufferedReader(new FileReader(inFile));
            File outFile = new File(completePath + fSep + "SmartGRAPE" + fSep + outputFile);
            FileChannel outC = new FileOutputStream(outFile, true).getChannel();
            boolean endOfFile = true;
            short movieName = 0;
            int customer = 0;
            while (endOfFile) {
                String line = br.readLine();
                if (line != null) {
                    if (line.indexOf(":") >= 0) {
                        movieName = new Short(line.substring(0, line.length() - 1)).shortValue();
                    } else {
                        customer = new Integer(line.substring(0, line.indexOf(","))).intValue();
                        ByteBuffer outBuf = ByteBuffer.allocate(6);
                        outBuf.putShort(movieName);
                        outBuf.putInt(customer);
                        outBuf.flip();
                        outC.write(outBuf);
                    }
                } else endOfFile = false;
            }
            br.close();
            outC.close();
            return true;
        } catch (IOException e) {
            System.err.println(e);
            return false;
        }
    }
private static boolean computeMovieAverages(String completePath, String MovieAveragesOutputFileName, String MovieIndexFileName) {
        try {
            File inputFile = new File(completePath + fSep + "SmartGRAPE" + fSep + MovieIndexFileName);
            FileChannel inC = new FileInputStream(inputFile).getChannel();
            int filesize = (int) inC.size();
            ByteBuffer mappedfile = inC.map(FileChannel.MapMode.READ_ONLY, 0, filesize);
            TShortObjectHashMap MovieLimitsTHash = new TShortObjectHashMap(17770, 1);
            int i = 0, totalcount = 0;
            short movie;
            int startIndex, endIndex;
            TIntArrayList a;
            while (mappedfile.hasRemaining()) {
                movie = mappedfile.getShort();
                startIndex = mappedfile.getInt();
                endIndex = mappedfile.getInt();
                a = new TIntArrayList(2);
                a.add(startIndex);
                a.add(endIndex);
                MovieLimitsTHash.put(movie, a);
            }
            inC.close();
            mappedfile = null;
            System.out.println("Loaded movie index hash");
            File outFile = new File(completePath + fSep + "SmartGRAPE" + fSep + MovieAveragesOutputFileName);
            FileChannel outC = new FileOutputStream(outFile, true).getChannel();
            int totalMovies = MovieLimitsTHash.size();
            File movieMMAPDATAFile = new File(completePath + fSep + "SmartGRAPE" + fSep + "CustomerRatingBinaryFile.txt");
            inC = new FileInputStream(movieMMAPDATAFile).getChannel();
            short[] itr = MovieLimitsTHash.keys();
            Arrays.sort(itr);
            ByteBuffer buf;
            for (i = 0; i < totalMovies; i++) {
                short currentMovie = itr[i];
                a = (TIntArrayList) MovieLimitsTHash.get(currentMovie);
                startIndex = a.get(0);
                endIndex = a.get(1);
                if (endIndex > startIndex) {
                    buf = ByteBuffer.allocate((endIndex - startIndex + 1) * 5);
                    inC.read(buf, (startIndex - 1) * 5);
                } else {
                    buf = ByteBuffer.allocate(5);
                    inC.read(buf, (startIndex - 1) * 5);
                }
                buf.flip();
                int bufsize = buf.capacity() / 5;
                float sum = 0;
                for (int q = 0; q < bufsize; q++) {
                    buf.getInt();
                    sum += buf.get();
                }
                ByteBuffer outbuf = ByteBuffer.allocate(6);
                outbuf.putShort(currentMovie);
                outbuf.putFloat(sum / bufsize);
                outbuf.flip();
                outC.write(outbuf);
                buf.clear();
                buf = null;
                a.clear();
                a = null;
            }
            inC.close();
            outC.close();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
private static boolean computeCustomerAverages(String completePath, String CustomerAveragesOutputFileName, String CustIndexFileName) {
        try {
            File inputFile = new File(completePath + fSep + "SmartGRAPE" + fSep + CustIndexFileName);
            FileChannel inC = new FileInputStream(inputFile).getChannel();
            int filesize = (int) inC.size();
            ByteBuffer mappedfile = inC.map(FileChannel.MapMode.READ_ONLY, 0, filesize);
            TIntObjectHashMap CustomerLimitsTHash = new TIntObjectHashMap(480189, 1);
            int startIndex, endIndex;
            TIntArrayList a;
            int custid;
            while (mappedfile.hasRemaining()) {
                custid = mappedfile.getInt();
                startIndex = mappedfile.getInt();
                endIndex = mappedfile.getInt();
                a = new TIntArrayList(2);
                a.add(startIndex);
                a.add(endIndex);
                CustomerLimitsTHash.put(custid, a);
            }
            inC.close();
            mappedfile = null;
            System.out.println("Loaded customer index hash");
            File outFile = new File(completePath + fSep + "SmartGRAPE" + fSep + CustomerAveragesOutputFileName);
            FileChannel outC = new FileOutputStream(outFile, true).getChannel();
            int totalCusts = CustomerLimitsTHash.size();
            File movieMMAPDATAFile = new File(completePath + fSep + "SmartGRAPE" + fSep + "MovieRatingBinaryFile.txt");
            inC = new FileInputStream(movieMMAPDATAFile).getChannel();
            int[] itr = CustomerLimitsTHash.keys();
            startIndex = 0;
            endIndex = 0;
            a = null;
            ByteBuffer buf;
            for (int i = 0; i < totalCusts; i++) {
                int currentCust = itr[i];
                a = (TIntArrayList) CustomerLimitsTHash.get(currentCust);
                startIndex = a.get(0);
                endIndex = a.get(1);
                if (endIndex > startIndex) {
                    buf = ByteBuffer.allocate((endIndex - startIndex + 1) * 3);
                    inC.read(buf, (startIndex - 1) * 3);
                } else {
                    buf = ByteBuffer.allocate(3);
                    inC.read(buf, (startIndex - 1) * 3);
                }
                buf.flip();
                int bufsize = buf.capacity() / 3;
                float sum = 0;
                for (int q = 0; q < bufsize; q++) {
                    buf.getShort();
                    sum += buf.get();
                }
                ByteBuffer outbuf = ByteBuffer.allocate(8);
                outbuf.putInt(currentCust);
                outbuf.putFloat(sum / bufsize);
                outbuf.flip();
                outC.write(outbuf);
                buf.clear();
                buf = null;
                a.clear();
                a = null;
            }
            inC.close();
            outC.close();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
@SuppressWarnings("unchecked")
    protected void handleRequest(HttpServletRequest req, HttpServletResponse resp, boolean isPost) throws ServletException, IOException {
        HttpClient httpclient = WebReader.getHttpClient();
        try {
            StringBuffer sb = new StringBuffer();
            sb.append(targetServer);
            sb.append(req.getRequestURI());
            if (req.getQueryString() != null) {
                sb.append("?" + req.getQueryString());
            }
            HttpRequestBase targetRequest = null;
            if (isPost) {
                HttpPost post = new HttpPost(sb.toString());
                Enumeration<String> paramNames = req.getParameterNames();
                String paramName = null;
                List<NameValuePair> params = new ArrayList<NameValuePair>();
                while (paramNames.hasMoreElements()) {
                    paramName = paramNames.nextElement();
                    params.add(new BasicNameValuePair(paramName, req.getParameterValues(paramName)[0]));
                }
                post.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
                targetRequest = post;
            } else {
                System.out.println("GET");
                HttpGet get = new HttpGet(sb.toString());
                targetRequest = get;
            }
            HttpResponse targetResponse = httpclient.execute(targetRequest);
            HttpEntity entity = targetResponse.getEntity();
            InputStream input = entity.getContent();
            OutputStream output = resp.getOutputStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(input));
            BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(output));
            String line = reader.readLine();
            while (line != null) {
                writer.write(line + "\n");
                line = reader.readLine();
            }
            reader.close();
            writer.close();
        } finally {
            WebReader.returnHttpClient(httpclient);
        }
    }
public static String CreateZip(String[] filesToZip, String zipFileName) {
        byte[] buffer = new byte[18024];
        try {
            ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFileName));
            out.setLevel(Deflater.BEST_COMPRESSION);
            for (int i = 0; i < filesToZip.length; i++) {
                FileInputStream in = new FileInputStream(filesToZip[i]);
                String fileName = null;
                for (int X = filesToZip[i].length() - 1; X >= 0; X--) {
                    if (filesToZip[i].charAt(X) == '\\' || filesToZip[i].charAt(X) == '/') {
                        fileName = filesToZip[i].substring(X + 1);
                        break;
                    } else if (X == 0) fileName = filesToZip[i];
                }
                out.putNextEntry(new ZipEntry(fileName));
                int len;
                while ((len = in.read(buffer)) > 0) out.write(buffer, 0, len);
                out.closeEntry();
                in.close();
            }
            out.close();
        } catch (IllegalArgumentException e) {
            return "Failed to create zip: " + e.toString();
        } catch (FileNotFoundException e) {
            return "Failed to create zip: " + e.toString();
        } catch (IOException e) {
            return "Failed to create zip: " + e.toString();
        }
        return "Success";
    }
public PageLoader(String pageAddress) throws Exception {
        URL url = new URL(pageAddress);
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        inputLine = "";
        while (in.ready()) {
            inputLine = inputLine + in.readLine();
        }
        in.close();
    }
public void writeConfiguration(Writer out) throws IOException {
        if (myUrl == null) {
            out.append("# Unable to print configuration resource\n");
        } else {
            InputStream in = myUrl.openStream();
            if (in != null) {
                try {
                    IOUtils.copy(in, out);
                } finally {
                    IOUtils.closeQuietly(in);
                }
            } else {
                out.append("# Unable to print configuration resource\n");
            }
        }
    }
public static String md5EncodeString(String s) throws UnsupportedEncodingException, NoSuchAlgorithmException {
        if (s == null) return null;
        if (StringUtils.isBlank(s)) return "";
        MessageDigest algorithm = MessageDigest.getInstance("MD5");
        algorithm.reset();
        algorithm.update(s.getBytes("UTF-8"));
        byte messageDigest[] = algorithm.digest();
        StringBuffer hexString = new StringBuffer();
        for (int i = 0; i < messageDigest.length; i++) {
            String hex = Integer.toHexString(0xFF & messageDigest[i]);
            if (hex.length() == 1) {
                hexString.append('0');
            }
            hexString.append(hex);
        }
        return hexString.toString();
    }