semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
@Override
    protected byte[] fetch0() throws IOException {
        if (sourceFile.getProtocol().equalsIgnoreCase("jar")) {
            throw new IOException("Jar protocol unsupported!");
        } else {
            URL url;
            if (sourceFile.getFile().endsWith(CLASS_FILE_EXTENSION)) {
                url = sourceFile;
            } else {
                url = new URL(sourceFile, className.replace(PACKAGE_SEPARATOR, URL_DIRECTORY_SEPARATOR) + CLASS_FILE_EXTENSION);
            }
            InputStream stream = url.openStream();
            try {
                ByteArrayOutputStream output = new ByteArrayOutputStream();
                byte[] buffer = new byte[PACKET_SIZE];
                int bytesRead;
                while ((bytesRead = stream.read(buffer, 0, buffer.length)) != -1) {
                    output.write(buffer, 0, bytesRead);
                }
                return output.toByteArray();
            } finally {
                stream.close();
            }
        }
    }
public static String generateMD5(final String data) {
        final StringBuilder hash = new StringBuilder(64);
        try {
            final MessageDigest sha1 = MessageDigest.getInstance("MD5");
            sha1.update(data.getBytes());
            final byte[] digest = sha1.digest();
            for (byte aDigest : digest) {
                String hex = Integer.toHexString(aDigest);
                if (hex.length() == 1) {
                    hex = "0" + hex;
                }
                hex = hex.substring(hex.length() - 2);
                hash.append(hex);
            }
        } catch (NoSuchAlgorithmException e) {
        }
        return hash.toString();
    }
public static String generateSHA1(final String data) {
        final StringBuilder hash = new StringBuilder(40);
        try {
            final MessageDigest sha1 = MessageDigest.getInstance("sha1");
            sha1.update(data.getBytes());
            final byte[] digest = sha1.digest();
            for (byte aDigest : digest) {
                String hex = Integer.toHexString(aDigest);
                if (hex.length() == 1) {
                    hex = "0" + hex;
                }
                hex = hex.substring(hex.length() - 2);
                hash.append(hex);
            }
        } catch (NoSuchAlgorithmException e) {
        }
        return hash.toString();
    }
public Reader create(final URI url) throws IOException {
        this.url = url;
        if (!url.isAbsolute()) {
            return new FileReader(new File(url.toString()));
        }
        URLConnection connection = url.toURL().openConnection();
        connection.setDoInput(true);
        final InputStream inputStream = connection.getInputStream();
        return new InputStreamReader(inputStream);
    }
private void copyResource(String relResourceName) {
        String projectName = layout.getRootDir().getName();
        String resourceName = "/protoj/" + projectName + "/" + relResourceName;
        InputStream source = getClass().getResourceAsStream(resourceName);
        if (source == null) {
            throw new RuntimeException("couldn't find resource " + resourceName);
        }
        File dest = new File(layout.getRootDir(), relResourceName);
        dest.getParentFile().mkdirs();
        dest.createNewFile();
        InputStreamReader in = new InputStreamReader(source);
        try {
            FileOutputStream out = new FileOutputStream(dest);
            try {
                IOUtils.copy(in, out);
            } finally {
                IOUtils.closeQuietly(out);
            }
        } finally {
            IOUtils.closeQuietly(in);
        }
    }
public static void copyFile(File in, File out) throws IOException {
        FileChannel inChannel = new FileInputStream(in).getChannel();
        FileChannel outChannel = new FileOutputStream(out).getChannel();
        try {
            if (System.getProperty("os.name").toUpperCase().indexOf("WIN") != -1) {
                int maxCount = (64 * 1024 * 1024) - (32 * 1024);
                long size = inChannel.size();
                long position = 0;
                while (position < size) {
                    position += inChannel.transferTo(position, maxCount, outChannel);
                }
            } else {
                inChannel.transferTo(0, inChannel.size(), outChannel);
            }
        } finally {
            if (inChannel != null) inChannel.close();
            if (outChannel != null) outChannel.close();
        }
    }
public JSONObject executeJSON(final String path, final JSONObject jsRequest) throws IOException, HttpException, JSONException {
        final HttpPost httpRequest = newHttpPost(path);
        httpRequest.setHeader("Content-Type", "application/json");
        final String request = jsRequest.toString();
        httpRequest.setEntity(new StringEntity(request));
        final HttpResponse httpResponse = executeHttp(httpRequest);
        final String response = EntityUtils.toString(httpResponse.getEntity());
        return new JSONObject(response);
    }
public HTTPResponse makeRequest(BasicHttpRequest request) throws IOException {
        try {
            if (!conn.isOpen()) {
                logger.warn(ApacheHTTP.class, "Creating socket");
                Socket socket = getSocket(host.getHostName(), host.getPort(), ssl, true);
                conn.bind(socket, params);
            }
            HttpContext context = new BasicHttpContext(null);
            context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
            context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, host);
            context.setAttribute(ExecutionContext.HTTP_REQUEST, request);
            request.setParams(params);
            httpexecutor.preProcess(request, httpproc, context);
            HttpResponse response = httpexecutor.execute(request, conn, context);
            httpexecutor.postProcess(response, httpproc, context);
            if (!connStrategy.keepAlive(response, context)) keepAlive = false;
            int statusCode = response.getStatusLine().getStatusCode();
            HttpEntity resp = response.getEntity();
            if (statusCode >= 400) {
                HTTPEntityInfo info = new HTTPEntityInfo((int) resp.getContentLength(), "", resp.getContentType().getValue());
                byte[] bytes = IOUtil.toByteArray(resp.getContent());
                throw new HTTPErrorResponse(response.getStatusLine().getReasonPhrase(), statusCode + "", bytes, info);
            } else {
                Header lastmodHeader = response.getLastHeader("last-modified");
                String lastmod = lastmodHeader == null ? "" : lastmodHeader.getValue();
                Header contentType = resp.getContentType();
                HTTPEntityInfo info = new HTTPEntityInfo((int) resp.getContentLength(), lastmod, contentType == null ? null : contentType.getValue());
                return new HTTPResponse(info, resp.getContent());
            }
        } catch (HttpException he) {
            throw new IOException(he);
        }
    }
public String loadURL(URL url) {
        String retVal = "";
        try {
            InputStream inputStream = url.openStream();
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
            String line = bufferedReader.readLine();
            retVal += line + "\n";
            while (line != null) {
                System.out.println(line);
                line = bufferedReader.readLine();
                if (line != null) retVal += line + "\n";
            }
            bufferedReader.close();
        } catch (MalformedURLException e) {
            e.printStackTrace();
            retVal = e.getMessage();
        } catch (IOException e) {
            e.printStackTrace();
            retVal = e.getMessage();
        } catch (Exception e) {
            e.printStackTrace();
            retVal = e.getMessage();
        }
        return retVal;
    }
public boolean check(Object credentials) {
            try {
                byte[] digest = null;
                if (credentials instanceof Password || credentials instanceof String) {
                    synchronized (__md5Lock) {
                        if (__md == null) __md = MessageDigest.getInstance("MD5");
                        __md.reset();
                        __md.update(credentials.toString().getBytes(StringUtil.__ISO_8859_1));
                        digest = __md.digest();
                    }
                    if (digest == null || digest.length != _digest.length) return false;
                    for (int i = 0; i < digest.length; i++) if (digest[i] != _digest[i]) return false;
                    return true;
                } else if (credentials instanceof MD5) {
                    MD5 md5 = (MD5) credentials;
                    if (_digest.length != md5._digest.length) return false;
                    for (int i = 0; i < _digest.length; i++) if (_digest[i] != md5._digest[i]) return false;
                    return true;
                } else if (credentials instanceof Credential) {
                    return ((Credential) credentials).check(this);
                } else {
                    Log.warn("Can't check " + credentials.getClass() + " against MD5");
                    return false;
                }
            } catch (Exception e) {
                Log.warn(e);
                return false;
            }
        }
public static String digest(String password) {
            try {
                byte[] digest;
                synchronized (__md5Lock) {
                    if (__md == null) {
                        try {
                            __md = MessageDigest.getInstance("MD5");
                        } catch (Exception e) {
                            Log.warn(e);
                            return null;
                        }
                    }
                    __md.reset();
                    __md.update(password.getBytes(StringUtil.__ISO_8859_1));
                    digest = __md.digest();
                }
                return __TYPE + TypeUtil.toString(digest, 16);
            } catch (Exception e) {
                Log.warn(e);
                return null;
            }
        }
public static void copyFile(File source, File destination, long copyLength) throws IOException {
        if (!source.exists()) {
            String message = "File " + source + " does not exist";
            throw new FileNotFoundException(message);
        }
        if (destination.getParentFile() != null && !destination.getParentFile().exists()) {
            forceMkdir(destination.getParentFile());
        }
        if (destination.exists() && !destination.canWrite()) {
            String message = "Unable to open file " + destination + " for writing.";
            throw new IOException(message);
        }
        if (source.getCanonicalPath().equals(destination.getCanonicalPath())) {
            String message = "Unable to write file " + source + " on itself.";
            throw new IOException(message);
        }
        if (copyLength == 0) {
            truncateFile(destination, 0);
        }
        FileInputStream input = null;
        FileOutputStream output = null;
        try {
            input = new FileInputStream(source);
            output = new FileOutputStream(destination);
            long lengthLeft = copyLength;
            byte[] buffer = new byte[(int) Math.min(BUFFER_LENGTH, lengthLeft + 1)];
            int read;
            while (lengthLeft > 0) {
                read = input.read(buffer);
                if (read == -1) {
                    break;
                }
                lengthLeft -= read;
                output.write(buffer, 0, read);
            }
            output.flush();
            output.getFD().sync();
        } finally {
            IOUtil.closeQuietly(input);
            IOUtil.closeQuietly(output);
        }
        destination.setLastModified(source.lastModified());
    }
public static void renameFileMultiFallback(File sourceFile, File destFile) throws FileHandlingException {
        if (destFile.exists()) {
            throw new FileHandlingException(FileHandlingException.FILE_ALREADY_EXISTS);
        }
        if (!sourceFile.exists()) {
            return;
        }
        boolean succ = sourceFile.renameTo(destFile);
        if (succ) {
            NLogger.warn(FileUtils.class, "First renameTo operation worked!");
            return;
        }
        NLogger.warn(FileUtils.class, "First renameTo operation failed.");
        System.gc();
        Thread.yield();
        succ = sourceFile.renameTo(destFile);
        if (succ) {
            return;
        }
        NLogger.warn(FileUtils.class, "Second renameTo operation failed.");
        FileInputStream input = null;
        FileOutputStream output = null;
        try {
            input = new FileInputStream(sourceFile);
            output = new FileOutputStream(destFile);
            long lengthLeft = sourceFile.length();
            byte[] buffer = new byte[(int) Math.min(BUFFER_LENGTH, lengthLeft + 1)];
            int read;
            while (lengthLeft > 0) {
                read = input.read(buffer);
                if (read == -1) {
                    break;
                }
                lengthLeft -= read;
                output.write(buffer, 0, read);
            }
        } catch (IOException exp) {
            NLogger.warn(FileUtils.class, "Third renameTo operation failed.");
            throw new FileHandlingException(FileHandlingException.RENAME_FAILED, exp);
        } finally {
            IOUtil.closeQuietly(input);
            IOUtil.closeQuietly(output);
        }
        destFile.setLastModified(sourceFile.lastModified());
        FileUtils.deleteFileMultiFallback(sourceFile);
    }
private static void doCopyFile(File srcFile, File destFile, boolean preserveFileDate) throws IOException {
        if (destFile.exists() && destFile.isDirectory()) {
            throw new IOException("Destination '" + destFile + "' exists but is a directory");
        }
        FileChannel input = new FileInputStream(srcFile).getChannel();
        try {
            FileChannel output = new FileOutputStream(destFile).getChannel();
            try {
                output.transferFrom(input, 0, input.size());
            } finally {
                IOUtil.closeQuietly(output);
            }
        } finally {
            IOUtil.closeQuietly(input);
        }
        if (srcFile.length() != destFile.length()) {
            throw new IOException("Failed to copy full contents from '" + srcFile + "' to '" + destFile + "'");
        }
        if (preserveFileDate) {
            destFile.setLastModified(srcFile.lastModified());
        }
    }
public static void rewrite(String[] args) throws IOException, CodeCheckException {
        ClassWriter writer = new ClassWriter();
        writer.readClass(new FileInputStream(args[0]));
        for (Iterator i = writer.getMethods().iterator(); i.hasNext(); ) {
            MethodInfo method = (MethodInfo) i.next();
            CodeAttribute attribute = method.getCodeAttribute();
            int origStack = attribute.getMaxStack();
            System.out.print(method.getName());
            attribute.codeCheck();
            System.out.println(" " + origStack + " " + attribute.getMaxStack());
        }
        BufferedOutputStream outStream = new BufferedOutputStream(new FileOutputStream(args[1]));
        writer.writeClass(outStream);
        outStream.close();
    }
public static void testclass(String[] args) throws IOException, CodeCheckException {
        ClassWriter writer = new ClassWriter();
        writer.emptyClass(ClassWriter.ACC_PUBLIC, "TestClass", "java/lang/Object");
        MethodInfo newMethod = writer.addMethod(ClassWriter.ACC_PUBLIC | ClassWriter.ACC_STATIC, "main", "([Ljava/lang/String;)V");
        CodeAttribute attribute = newMethod.getCodeAttribute();
        int constantIndex = writer.getStringConstantIndex("It's alive! It's alive!!");
        int fieldRefIndex = writer.getReferenceIndex(ClassWriter.CONSTANT_Fieldref, "java/lang/System", "out", "Ljava/io/PrintStream;");
        int methodRefIndex = writer.getReferenceIndex(ClassWriter.CONSTANT_Methodref, "java/io/PrintStream", "println", "(Ljava/lang/String;)V");
        ArrayList instructions = new ArrayList();
        byte[] operands;
        operands = new byte[2];
        NetByte.intToPair(fieldRefIndex, operands, 0);
        instructions.add(new Instruction(OpCode.getOpCodeByMnemonic("getstatic"), 0, operands, false));
        operands = new byte[1];
        operands[0] = (byte) constantIndex;
        instructions.add(new Instruction(OpCode.getOpCodeByMnemonic("ldc"), 0, operands, false));
        operands = new byte[2];
        NetByte.intToPair(methodRefIndex, operands, 0);
        instructions.add(new Instruction(OpCode.getOpCodeByMnemonic("invokevirtual"), 0, operands, false));
        instructions.add(new Instruction(OpCode.getOpCodeByMnemonic("return"), 0, null, false));
        attribute.insertInstructions(0, 0, instructions);
        attribute.setMaxLocals(1);
        attribute.codeCheck();
        System.out.println("constantIndex=" + constantIndex + " fieldRef=" + fieldRefIndex + " methodRef=" + methodRefIndex);
        writer.writeClass(new FileOutputStream("c:/cygnus/home/javaodb/classes/TestClass.class"));
        writer.readClass(new FileInputStream("c:/cygnus/home/javaodb/classes/TestClass.class"));
    }
public static void entering(String[] args) throws IOException, CodeCheckException {
        ClassWriter writer = new ClassWriter();
        writer.readClass(new BufferedInputStream(new FileInputStream(args[0])));
        int constantIndex = writer.getStringConstantIndex("Entering ");
        int fieldRefIndex = writer.getReferenceIndex(ClassWriter.CONSTANT_Fieldref, "java/lang/System", "out", "Ljava/io/PrintStream;");
        int printlnRefIndex = writer.getReferenceIndex(ClassWriter.CONSTANT_Methodref, "java/io/PrintStream", "println", "(Ljava/lang/String;)V");
        int printRefIndex = writer.getReferenceIndex(ClassWriter.CONSTANT_Methodref, "java/io/PrintStream", "print", "(Ljava/lang/String;)V");
        for (Iterator i = writer.getMethods().iterator(); i.hasNext(); ) {
            MethodInfo method = (MethodInfo) i.next();
            if (method.getName().equals("readConstant")) continue;
            CodeAttribute attribute = method.getCodeAttribute();
            ArrayList instructions = new ArrayList(10);
            byte[] operands;
            operands = new byte[2];
            NetByte.intToPair(fieldRefIndex, operands, 0);
            instructions.add(new Instruction(OpCode.getOpCodeByMnemonic("getstatic"), 0, operands, false));
            instructions.add(new Instruction(OpCode.getOpCodeByMnemonic("dup"), 0, null, false));
            instructions.add(Instruction.appropriateLdc(constantIndex, false));
            operands = new byte[2];
            NetByte.intToPair(printRefIndex, operands, 0);
            instructions.add(new Instruction(OpCode.getOpCodeByMnemonic("invokevirtual"), 0, operands, false));
            instructions.add(Instruction.appropriateLdc(writer.getStringConstantIndex(method.getName()), false));
            operands = new byte[2];
            NetByte.intToPair(printlnRefIndex, operands, 0);
            instructions.add(new Instruction(OpCode.getOpCodeByMnemonic("invokevirtual"), 0, operands, false));
            attribute.insertInstructions(0, 0, instructions);
            attribute.codeCheck();
        }
        BufferedOutputStream outStream = new BufferedOutputStream(new FileOutputStream(args[1]));
        writer.writeClass(outStream);
        outStream.close();
    }
private void copyFile(File sourceFile, File destFile) throws IOException {
        if (!destFile.exists()) {
            destFile.createNewFile();
        }
        FileChannel source = null;
        FileChannel destination = null;
        try {
            source = new FileInputStream(sourceFile).getChannel();
            destination = new FileOutputStream(destFile).getChannel();
            destination.transferFrom(source, 0, source.size());
        } finally {
            if (source != null) {
                source.close();
            }
            if (destination != null) {
                destination.close();
            }
        }
    }
public static void main(String[] args) throws Exception {
        final URL url = new URL("http://www.ebi.ac.uk/Tools/webservices/psicquic/registry/registry?action=ACTIVE&format=txt");
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        String str;
        Map<String, String> psiqcuicServices = new HashMap<String, String>();
        while ((str = in.readLine()) != null) {
            final int idx = str.indexOf('=');
            psiqcuicServices.put(str.substring(0, idx), str.substring(idx + 1, str.length()));
        }
        in.close();
        System.out.println("Found " + psiqcuicServices.size() + " active service(s).");
        for (Object o : psiqcuicServices.keySet()) {
            String serviceName = (String) o;
            String serviceUrl = psiqcuicServices.get(serviceName);
            System.out.println(serviceName + " -> " + serviceUrl);
            UniversalPsicquicClient client = new UniversalPsicquicClient(serviceUrl);
            try {
                SearchResult<?> result = client.getByInteractor("brca2", 0, 50);
                System.out.println("Interactions found: " + result.getTotalCount());
                for (BinaryInteraction binaryInteraction : result.getData()) {
                    String interactorIdA = binaryInteraction.getInteractorA().getIdentifiers().iterator().next().getIdentifier();
                    String interactorIdB = binaryInteraction.getInteractorB().getIdentifiers().iterator().next().getIdentifier();
                    String interactionAc = "-";
                    if (!binaryInteraction.getInteractionAcs().isEmpty()) {
                        CrossReference cr = (CrossReference) binaryInteraction.getInteractionAcs().iterator().next();
                        interactionAc = cr.getIdentifier();
                    }
                    System.out.println("\tInteraction (" + interactionAc + "): " + interactorIdA + " interacts with " + interactorIdB);
                }
            } catch (Throwable e) {
                System.err.println("Service is down! " + serviceName + "(" + serviceUrl + ")");
            }
        }
    }
@Override
    public String getLatestApplicationVersion() {
        String latestVersion = null;
        String latestVersionInfoURL = "http://movie-browser.googlecode.com/svn/site/latest";
        LOGGER.info("Checking latest version info from: " + latestVersionInfoURL);
        BufferedReader in = null;
        try {
            LOGGER.info("Fetcing latest version info from: " + latestVersionInfoURL);
            URL url = new URL(latestVersionInfoURL);
            in = new BufferedReader(new InputStreamReader(url.openStream()));
            String str;
            while ((str = in.readLine()) != null) {
                latestVersion = str;
            }
        } catch (Exception ex) {
            LOGGER.error("Error fetching latest version info from: " + latestVersionInfoURL, ex);
        } finally {
            try {
                in.close();
            } catch (Exception ex) {
                LOGGER.error("Could not close inputstream", ex);
            }
        }
        return latestVersion;
    }