semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void testQueryForBinary() throws InvalidNodeTypeDefException, ParseException, Exception {
        JCRNodeSource source = (JCRNodeSource) resolveSource(BASE_URL + "images/photo.png");
        assertNotNull(source);
        assertEquals(false, source.exists());
        OutputStream os = source.getOutputStream();
        assertNotNull(os);
        String content = "foo is a bar";
        os.write(content.getBytes());
        os.flush();
        os.close();
        QueryResultSource qResult = (QueryResultSource) resolveSource(BASE_URL + "images?/*[contains(local-name(), 'photo.png')]");
        assertNotNull(qResult);
        Collection results = qResult.getChildren();
        assertEquals(1, results.size());
        Iterator it = results.iterator();
        JCRNodeSource rSrc = (JCRNodeSource) it.next();
        InputStream rSrcIn = rSrc.getInputStream();
        ByteArrayOutputStream actualOut = new ByteArrayOutputStream();
        IOUtils.copy(rSrcIn, actualOut);
        rSrcIn.close();
        assertEquals(content, actualOut.toString());
        actualOut.close();
        rSrc.delete();
    }
public static boolean isInternetReachable() {
        try {
            URL url = new URL("http://code.google.com/p/ilias-userimport/downloads/list");
            HttpURLConnection urlConnect = (HttpURLConnection) url.openConnection();
            Object objData = urlConnect.getContent();
        } catch (UnknownHostException e) {
            e.printStackTrace();
            return false;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
public static void executePost(String targetURL, File file, int msec) {
        URL url;
        HttpURLConnection connection = null;
        try {
            long wrCount = 0;
            long fileLen = file.length();
            log("File length is " + fileLen);
            log("Sleep " + msec + " between each send");
            FileInputStream fis = new FileInputStream(file);
            url = new URL(targetURL);
            connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Content-Type", "text/xml");
            connection.setRequestProperty("Content-Length", Long.toString(fileLen));
            connection.setUseCaches(false);
            connection.setDoInput(true);
            connection.setDoOutput(true);
            OutputStream wr = connection.getOutputStream();
            int count = 0;
            byte[] buffer = new byte[1024 * 10];
            while ((count = fis.read(buffer)) != -1) {
                wr.write(buffer, 0, count);
                wr.flush();
                wrCount += (long) count;
                log("Progress is " + (wrCount * 100) / fileLen + "%");
                Thread.sleep(msec);
            }
            wr.close();
            fis.close();
            InputStream is = connection.getInputStream();
            BufferedReader rd = new BufferedReader(new InputStreamReader(is));
            String line;
            while ((line = rd.readLine()) != null) {
                System.out.println(line);
            }
            rd.close();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (connection != null) {
                connection.disconnect();
            }
        }
        return;
    }
public static void main(String[] args) {
        File file = null;
        try {
            file = File.createTempFile("TestFileChannel", ".dat");
            final ByteBuffer buffer = ByteBuffer.allocateDirect(4);
            final ByteChannel output = new FileOutputStream(file).getChannel();
            buffer.putInt(MAGIC_INT);
            buffer.flip();
            output.write(buffer);
            output.close();
            final ByteChannel input = new FileInputStream(file).getChannel();
            buffer.clear();
            while (buffer.hasRemaining()) {
                input.read(buffer);
            }
            input.close();
            buffer.flip();
            final int file_int = buffer.getInt();
            if (file_int != MAGIC_INT) {
                System.out.println("TestFileChannel FAILURE");
                System.out.println("Wrote " + Integer.toHexString(MAGIC_INT) + " but read " + Integer.toHexString(file_int));
            } else {
                System.out.println("TestFileChannel SUCCESS");
            }
        } catch (Exception e) {
            System.out.println("TestFileChannel FAILURE");
            e.printStackTrace(System.out);
        } finally {
            if (null != file) {
                file.delete();
            }
        }
    }
@Override
    public void parse() throws DocumentException, IOException {
        URL url = new URL(this.XMLAddress);
        URLConnection con = url.openConnection();
        BufferedReader bStream = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String str;
        bStream.readLine();
        while ((str = bStream.readLine()) != null) {
            String[] tokens = str.split("(\\s+)");
            String charCode = tokens[0].replaceAll("([0-9+])", "");
            Float value = Float.parseFloat(tokens[2].trim().replace(",", "."));
            ResultUnit unit = new ResultUnit(charCode, value, DEFAULT_MULTIPLIER);
            this.set.add(unit);
        }
    }
public static String getUrl(String url) {
        BufferedInputStream in = null;
        BufferedOutputStream out = null;
        try {
            ByteArrayOutputStream bytearray = new ByteArrayOutputStream();
            in = new BufferedInputStream(new URL(url).openStream());
            out = new BufferedOutputStream(bytearray, 1024);
            byte[] data = new byte[1024];
            int x = 0;
            while ((x = in.read(data, 0, 1024)) >= 0) {
                out.write(data, 0, x);
            }
            return bytearray.toString();
        } catch (Exception e) {
            throw new CVardbException(e);
        } finally {
            try {
                if (out != null) out.close();
                if (in != null) in.close();
            } catch (Exception e) {
            }
        }
    }
public URLConnection openConnection(String string) throws ParserException {
        final String prefix = "file://localhost";
        String resource;
        URL url;
        StringBuffer buffer;
        URLConnection ret;
        try {
            url = new URL(fixSpaces(string));
            ret = openConnection(url);
        } catch (MalformedURLException murle) {
            try {
                File file = new File(string);
                resource = file.getCanonicalPath();
                buffer = new StringBuffer(prefix.length() + resource.length());
                buffer.append(prefix);
                if (!resource.startsWith("/")) buffer.append("/");
                buffer.append(resource);
                url = new URL(fixSpaces(buffer.toString()));
                ret = openConnection(url);
            } catch (MalformedURLException murle2) {
                String msg = "Error in opening a connection to " + string;
                ParserException ex = new ParserException(msg, murle2);
                throw ex;
            } catch (IOException ioe) {
                String msg = "Error in opening a connection to " + string;
                ParserException ex = new ParserException(msg, ioe);
                throw ex;
            }
        }
        return (ret);
    }
private void downloadResults() {
        GregorianCalendar cal = new GregorianCalendar();
        cal.setTimeInMillis(System.currentTimeMillis());
        String filename = String.format("%s%sresult_%tF.xml", vysledky, File.separator, cal);
        String EOL = "" + (char) 0x0D + (char) 0x0A;
        try {
            LogManager.getInstance().log("Stahuji soubor result.xml a ukl�d�m do vysledky ...");
            File f = new File(filename);
            FileWriter fw = new FileWriter(f);
            URL url = new URL(Konfigurace.getInstance().getURLvysledkuValidatoru());
            BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
            String line = "";
            while ((line = br.readLine()) != null) {
                fw.write(line + EOL);
            }
            fw.write("</vysledky>" + EOL);
            br.close();
            fw.close();
            LogManager.getInstance().changeLog("Stahuji soubor result.xml a ukl�d�m do slo�ky vysledky ... OK");
        } catch (IOException e) {
            e.printStackTrace();
            LogManager.getInstance().changeLog("Stahuji soubor result.xml a ukl�d�m do slo�ky vysledky ... X");
        }
    }
private void copyValidFile(File file, int cviceni) {
        try {
            String filename = String.format("%s%s%02d%s%s", validovane, File.separator, cviceni, File.separator, file.getName());
            boolean copy = false;
            File newFile = new File(filename);
            if (newFile.exists()) {
                if (file.lastModified() > newFile.lastModified()) copy = true; else copy = false;
            } else {
                newFile.createNewFile();
                copy = true;
            }
            if (copy) {
                String EOL = "" + (char) 0x0D + (char) 0x0A;
                FileReader fr = new FileReader(file);
                BufferedReader br = new BufferedReader(fr);
                FileWriter fw = new FileWriter(newFile);
                String line;
                while ((line = br.readLine()) != null) fw.write(line + EOL);
                br.close();
                fw.close();
                newFile.setLastModified(file.lastModified());
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
public static void copyFileTo(String src, String dest) throws FileNotFoundException, IOException {
        File destFile = new File(dest);
        InputStream in = new FileInputStream(new File(src));
        OutputStream out = new FileOutputStream(destFile);
        byte buf[] = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0) out.write(buf, 0, len);
        in.close();
        out.close();
    }
private String getBytes(String in) throws NoSuchAlgorithmException {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        md5.update(in.getBytes());
        byte[] passWordBytes = md5.digest();
        String s = "[";
        for (int i = 0; i < passWordBytes.length; i++) s += passWordBytes[i] + ", ";
        s = s.substring(0, s.length() - 2);
        s += "]";
        return s;
    }
public boolean doUpload(int count) {
        String objFileName = Long.toString(new java.util.Date().getTime()) + Integer.toString(count);
        try {
            this.objectFileName[count] = objFileName + "_bak." + this.sourceFileExt[count];
            File objFile = new File(this.contextPath + "/" + this.savePath, this.objectFileName[count]);
            if (objFile.exists()) {
                this.doUpload(count);
            } else {
                objFile.createNewFile();
            }
            FileOutputStream fos = new FileOutputStream(objFile);
            BufferedOutputStream bos = new BufferedOutputStream(fos);
            int readLength = 0;
            int offset = 0;
            String str = "";
            long readSize = 0L;
            while ((readLength = this.inStream.readLine(this.b, 0, this.b.length)) != -1) {
                str = new String(this.b, 0, readLength);
                if (str.indexOf("Content-Type:") != -1) {
                    break;
                }
            }
            this.inStream.readLine(this.b, 0, this.b.length);
            while ((readLength = this.inStream.readLine(this.b, 0, b.length)) != -1) {
                str = new String(this.b, 0, readLength);
                if (this.b[0] == 45 && this.b[1] == 45 && this.b[2] == 45 && this.b[3] == 45 && this.b[4] == 45) {
                    break;
                }
                bos.write(this.b, 0, readLength);
                readSize += readLength;
                if (readSize > this.size) {
                    this.fileMessage[count] = "�ϴ��ļ������ļ���С�������ƣ�";
                    this.ok = false;
                    break;
                }
            }
            if (this.ok) {
                bos.flush();
                bos.close();
                int fileLength = (int) (objFile.length());
                byte[] bb = new byte[fileLength - 2];
                FileInputStream fis = new FileInputStream(objFile);
                BufferedInputStream bis = new BufferedInputStream(fis);
                bis.read(bb, 0, (fileLength - 2));
                fis.close();
                bis.close();
                this.objectFileName[count] = objFileName + "." + this.sourceFileExt[count];
                File ok_file = new File(this.contextPath + "/" + this.savePath, this.objectFileName[count]);
                ok_file.createNewFile();
                BufferedOutputStream bos_ok = new BufferedOutputStream(new FileOutputStream(ok_file));
                bos_ok.write(bb);
                bos_ok.close();
                objFile.delete();
                this.fileMessage[count] = "OK";
                return true;
            } else {
                bos.flush();
                bos.close();
                File delFile = new File(this.contextPath + "/" + this.savePath, this.objectFileName[count]);
                delFile.delete();
                this.objectFileName[count] = "none";
                return false;
            }
        } catch (Exception e) {
            this.objectFileName[count] = "none";
            this.fileMessage[count] = e.toString();
            return false;
        }
    }
public static void copy(File srcDir, File dstDir) throws IOException {
        if (srcDir.isDirectory()) {
            if (!dstDir.exists()) dstDir.mkdir();
            String[] children = srcDir.list();
            for (int i = 0; i < children.length; i++) copy(new File(srcDir, children[i]), new File(dstDir, children[i]));
        } else {
            InputStream in = null;
            OutputStream out = null;
            try {
                in = new FileInputStream(srcDir);
                out = new FileOutputStream(dstDir);
                byte[] buf = new byte[1024];
                int len;
                while ((len = in.read(buf)) > 0) out.write(buf, 0, len);
            } finally {
                Util.close(in);
                Util.close(out);
            }
        }
    }
public static URL[] getURLsForAllJars(URL url, File tmpDir) {
        FileInputStream fin = null;
        InputStream in = null;
        ZipInputStream zin = null;
        try {
            ArrayList array = new ArrayList();
            in = url.openStream();
            String fileName = url.getFile();
            int index = fileName.lastIndexOf('/');
            if (index != -1) {
                fileName = fileName.substring(index + 1);
            }
            final File f = createTempFile(fileName, in, tmpDir);
            fin = (FileInputStream) org.apache.axis2.java.security.AccessController.doPrivileged(new PrivilegedExceptionAction() {

                public Object run() throws FileNotFoundException {
                    return new FileInputStream(f);
                }
            });
            array.add(f.toURL());
            zin = new ZipInputStream(fin);
            ZipEntry entry;
            String entryName;
            while ((entry = zin.getNextEntry()) != null) {
                entryName = entry.getName();
                if ((entryName != null) && entryName.toLowerCase().startsWith("lib/") && entryName.toLowerCase().endsWith(".jar")) {
                    String suffix = entryName.substring(4);
                    File f2 = createTempFile(suffix, zin, tmpDir);
                    array.add(f2.toURL());
                }
            }
            return (URL[]) array.toArray(new URL[array.size()]);
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            if (fin != null) {
                try {
                    fin.close();
                } catch (IOException e) {
                }
            }
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                }
            }
            if (zin != null) {
                try {
                    zin.close();
                } catch (IOException e) {
                }
            }
        }
    }
private void copyFile(File sourceFile, File destFile) throws IOException {
        if (log.isDebugEnabled()) {
            log.debug("CopyFile : Source[" + sourceFile.getAbsolutePath() + "] Dest[" + destFile.getAbsolutePath() + "]");
        }
        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 String getSHA1Hash(String stringToHash) {
        String result = "";
        MessageDigest md;
        try {
            md = MessageDigest.getInstance("SHA-1");
            md.update(stringToHash.getBytes("utf-8"));
            byte[] hash = md.digest();
            StringBuffer hashString = new StringBuffer();
            for (int i = 0; i < hash.length; i++) {
                int halfByte = (hash[i] >>> 4) & 0x0F;
                int twoHalves = 0;
                do {
                    if ((0 <= halfByte) && (halfByte <= 9)) {
                        hashString.append((char) ('0' + halfByte));
                    } else {
                        hashString.append((char) ('a' + (halfByte - 10)));
                    }
                    halfByte = hash[i] & 0x0F;
                } while (twoHalves++ < 1);
            }
            result = hashString.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return result;
    }
public void put(IMetaCollection aCollection) throws TransducerException {
        if (null != ioTransducer) {
            try {
                URL urlObj = new URL(url);
                URLConnection urlConn = urlObj.openConnection();
                OutputStreamWriter sw = new OutputStreamWriter(urlConn.getOutputStream());
                ioTransducer.setWriter(new BufferedWriter(sw));
                ioTransducer.put(aCollection);
            } catch (Exception e) {
                throw new TransducerException(e);
            }
        } else {
            throw new TransducerException("An IIOTransducer instance must first be set on the URLTransducerAdapter.");
        }
    }
private FileLog(LOG_LEVEL displayLogLevel, LOG_LEVEL logLevel, String logPath) {
        this.logLevel = logLevel;
        this.displayLogLevel = displayLogLevel;
        if (null != logPath) {
            logFile = new File(logPath, "current.log");
            log(LOG_LEVEL.DEBUG, "FileLog", "Initialising logfile " + logFile.getAbsolutePath() + " .");
            try {
                if (logFile.exists()) {
                    if (!logFile.renameTo(new File(logPath, System.currentTimeMillis() + ".log"))) {
                        File newFile = new File(logPath, System.currentTimeMillis() + ".log");
                        if (newFile.exists()) {
                            log(LOG_LEVEL.WARN, "FileLog", "The file (" + newFile.getAbsolutePath() + newFile.getName() + ") already exists, will overwrite it.");
                            newFile.delete();
                        }
                        newFile.createNewFile();
                        FileInputStream inStream = new FileInputStream(logFile);
                        FileOutputStream outStream = new FileOutputStream(newFile);
                        byte buffer[] = null;
                        int offSet = 0;
                        while (inStream.read(buffer, offSet, 2048) != -1) {
                            outStream.write(buffer);
                            offSet += 2048;
                        }
                        inStream.close();
                        outStream.close();
                        logFile.delete();
                        logFile = new File(logPath, "current.log");
                    }
                }
                logFile.createNewFile();
            } catch (IOException e) {
                logFile = null;
            }
        } else {
            logFile = null;
        }
    }
private static final void cloneFile(File origin, File target) throws IOException {
        FileChannel srcChannel = null;
        FileChannel destChannel = null;
        try {
            srcChannel = new FileInputStream(origin).getChannel();
            destChannel = new FileOutputStream(target).getChannel();
            destChannel.transferFrom(srcChannel, 0, srcChannel.size());
        } finally {
            if (srcChannel != null) srcChannel.close();
            if (destChannel != null) destChannel.close();
        }
    }
public static void bubbleSort(int[] array) {
        for (int i = 0; i < array.length - 1; i++) {
            for (int j = 0; j < array.length - i - 1; j++) {
                if (array[j] > array[j + 1]) {
                    int temp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = temp;
                }
            }
            System.out.println("��" + (i + 1) + "������");
            for (int k = 0; k < array.length; k++) {
                System.out.print(array[k] + " ");
            }
            System.out.println();
        }
    }
public static String setErrorServer(String newServer) {
        String old = errorServerURL;
        try {
            URL url = new URL(newServer);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setInstanceFollowRedirects(false);
            BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            StringBuilder page = new StringBuilder();
            String line = null;
            while ((line = rd.readLine()) != null) {
                page.append(line);
            }
            rd.close();
            if (!page.toString().equals("maRla")) throw new ConfigurationException("URL given for error server is invalid", ConfigType.ErrorServer);
        } catch (UnknownHostException ex) {
            System.out.println("Accepting setting for error sever, unable to check");
        } catch (MalformedURLException ex) {
            throw new ConfigurationException("URL given for error server ('" + newServer + "') appears invalid", ConfigType.ErrorServer, ex);
        } catch (IOException ex) {
            throw new ConfigurationException("URL given for error server could not be reached", ConfigType.ErrorServer, ex);
        }
        errorServerURL = newServer;
        return old;
    }