semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static FileChannel newFileChannel(File file, String rw, boolean enableException) throws IOException {
        if (file == null) return null;
        if (rw == null || rw.length() == 0) {
            return null;
        }
        rw = rw.toLowerCase();
        if (rw.equals(MODE_READ)) {
            if (FileUtil.exists(file, enableException)) {
                FileInputStream fis = new FileInputStream(file);
                FileChannel ch = fis.getChannel();
                setObjectMap(ch.hashCode(), fis, FIS);
                return ch;
            }
        } else if (rw.equals(MODE_WRITE)) {
            FileOutputStream fos = new FileOutputStream(file);
            FileChannel ch = fos.getChannel();
            setObjectMap(ch.hashCode(), fos, FOS_W);
            return ch;
        } else if (rw.equals(MODE_APPEND)) {
            if (FileUtil.exists(file, enableException)) {
                RandomAccessFile raf = new RandomAccessFile(file, "rw");
                FileChannel ch = raf.getChannel();
                ch.position(ch.size());
                setObjectMap(ch.hashCode(), raf, FOS_A);
                return ch;
            }
        } else if (rw.equals(MODE_READ_WRITE)) {
            if (FileUtil.exists(file, enableException)) {
                RandomAccessFile raf = new RandomAccessFile(file, rw);
                FileChannel ch = raf.getChannel();
                setObjectMap(ch.hashCode(), raf, RAF);
                return ch;
            }
        } else {
            throw new IllegalArgumentException("Illegal read/write type : [" + rw + "]\n" + "You can use following types for: \n" + "  (1) Read Only  = \"r\"\n" + "  (2) Write Only = \"w\"\n" + "  (3) Read/Write = \"rw\"\n" + "  (4) Append     = \"a\"");
        }
        return null;
    }
private String getMD5Str(String str) {
        MessageDigest messageDigest = null;
        try {
            messageDigest = MessageDigest.getInstance("MD5");
            messageDigest.reset();
            messageDigest.update(str.getBytes("UTF-8"));
        } catch (NoSuchAlgorithmException e) {
            System.out.println("NoSuchAlgorithmException caught!");
            System.exit(-1);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        byte[] byteArray = messageDigest.digest();
        StringBuffer md5StrBuff = new StringBuffer();
        for (int i = 0; i < byteArray.length; i++) {
            if (Integer.toHexString(0xFF & byteArray[i]).length() == 1) md5StrBuff.append("0").append(Integer.toHexString(0xFF & byteArray[i])); else md5StrBuff.append(Integer.toHexString(0xFF & byteArray[i]));
        }
        return md5StrBuff.toString();
    }
public static void copyClassPathResource(String classPathResourceName, String fileSystemDirectoryName) {
        InputStream resourceInputStream = null;
        OutputStream fileOutputStream = null;
        try {
            resourceInputStream = FileUtils.class.getResourceAsStream(classPathResourceName);
            String fileName = StringUtils.substringAfterLast(classPathResourceName, "/");
            File fileSystemDirectory = new File(fileSystemDirectoryName);
            fileSystemDirectory.mkdirs();
            fileOutputStream = new FileOutputStream(fileSystemDirectoryName + "/" + fileName);
            IOUtils.copy(resourceInputStream, fileOutputStream);
        } catch (IOException e) {
            throw new UnitilsException(e);
        } finally {
            closeQuietly(resourceInputStream);
            closeQuietly(fileOutputStream);
        }
    }
@Override
    public void run() {
        File file = new File(LogHandler.path);
        FileFilter filter = new FileFilter() {

            @Override
            public boolean accept(File file) {
                GregorianCalendar cal = new GregorianCalendar();
                cal.setTime(new Date());
                cal.add(GregorianCalendar.DAY_OF_YEAR, -1);
                String oldTime = LogHandler.dateFormat.format(cal.getTime());
                return file.getName().toLowerCase().startsWith(oldTime);
            }
        };
        File[] list = file.listFiles(filter);
        if (list.length > 0) {
            FileInputStream in;
            int read = 0;
            byte[] data = new byte[1024];
            for (int i = 0; i < list.length; i++) {
                try {
                    in = new FileInputStream(LogHandler.path + list[i].getName());
                    GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(LogHandler.path + list[i].getName() + ".temp"));
                    while ((read = in.read(data, 0, 1024)) != -1) out.write(data, 0, read);
                    in.close();
                    out.close();
                    new File(LogHandler.path + list[i].getName() + ".temp").renameTo(new File(LogHandler.path + list[i].getName() + ".gz"));
                    list[i].delete();
                } catch (FileNotFoundException e) {
                    TrackingServer.incExceptionCounter();
                    e.printStackTrace();
                } catch (IOException ioe) {
                }
            }
        }
    }
void loadImage(Frame frame, URL url) throws Exception {
        URLConnection conn = url.openConnection();
        String mimeType = conn.getContentType();
        long length = conn.getContentLength();
        InputStream is = conn.getInputStream();
        loadImage(frame, is, length, mimeType);
    }
public static String getHash(String text) {
        if (text == null) return null;
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(text.getBytes());
            byte[] hashedTextBytes = md.digest();
            BigInteger hashedTextBigInteger = new BigInteger(1, hashedTextBytes);
            String hashedTextString = hashedTextBigInteger.toString(16);
            return hashedTextString;
        } catch (NoSuchAlgorithmException e) {
            LOG.warning(e.toString());
            return null;
        }
    }
private void putFile(String location, String file) throws Exception {
        System.out.println("Put file to " + location);
        URL url = new URL(location);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("PUT");
        conn.setDoOutput(true);
        RDFFormat dataFormat = RDFFormat.forFileName(file, RDFFormat.RDFXML);
        conn.setRequestProperty("Content-Type", dataFormat.getDefaultMIMEType());
        InputStream dataStream = ProtocolTest.class.getResourceAsStream(file);
        try {
            OutputStream connOut = conn.getOutputStream();
            try {
                IOUtil.transfer(dataStream, connOut);
            } finally {
                connOut.close();
            }
        } finally {
            dataStream.close();
        }
        conn.connect();
        int responseCode = conn.getResponseCode();
        if (responseCode != HttpURLConnection.HTTP_OK && responseCode != HttpURLConnection.HTTP_NO_CONTENT) {
            String response = "location " + location + " responded: " + conn.getResponseMessage() + " (" + responseCode + ")";
            fail(response);
        }
    }
private void delete(String location) throws Exception {
        URL url = new URL(location);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("DELETE");
        conn.connect();
        int responseCode = conn.getResponseCode();
        if (responseCode != HttpURLConnection.HTTP_OK && responseCode != HttpURLConnection.HTTP_NO_CONTENT) {
            String response = "location " + location + " responded: " + conn.getResponseMessage() + " (" + responseCode + ")";
            fail(response);
        }
    }
private TupleQueryResult evaluate(String location, String query, QueryLanguage queryLn) throws Exception {
        location += "?query=" + URLEncoder.encode(query, "UTF-8") + "&queryLn=" + queryLn.getName();
        URL url = new URL(location);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestProperty("Accept", TupleQueryResultFormat.SPARQL.getDefaultMIMEType());
        conn.connect();
        try {
            int responseCode = conn.getResponseCode();
            if (responseCode == HttpURLConnection.HTTP_OK) {
                return QueryResultIO.parse(conn.getInputStream(), TupleQueryResultFormat.SPARQL);
            } else {
                String response = "location " + location + " responded: " + conn.getResponseMessage() + " (" + responseCode + ")";
                fail(response);
                throw new RuntimeException(response);
            }
        } finally {
            conn.disconnect();
        }
    }
public void get() {
        try {
            int cnt;
            URL url = new URL(urlStr);
            URLConnection conn = url.openConnection();
            conn.setDoInput(true);
            conn.setDoOutput(false);
            InputStream is = conn.getInputStream();
            String filename = new File(url.getFile()).getName();
            FileOutputStream fos = new FileOutputStream(dstDir + File.separator + filename);
            byte[] buffer = new byte[4096];
            while ((cnt = is.read(buffer, 0, buffer.length)) != -1) fos.write(buffer, 0, cnt);
            fos.close();
            is.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
public static void copyFile(File source, File destination) throws IOException {
        FileInputStream fis = new FileInputStream(source);
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(destination);
            FileChannel sourceChannel = fis.getChannel();
            FileChannel destinationChannel = fos.getChannel();
            sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
            destinationChannel.close();
            sourceChannel.close();
        } finally {
            if (fos != null) fos.close();
            fis.close();
        }
    }
private static URL getURL(String name) throws EfreetException {
        URL url = ClassLoader.getSystemResource(name + ".xml");
        try {
            if (url == null) {
                try {
                    Context initContext = new InitialContext();
                    Context envContext = (Context) initContext.lookup("java:/comp/env");
                    String xmlFileDir = (String) envContext.lookup("xml/efreet");
                    url = new URL("file:" + xmlFileDir + "/" + name + ".xml");
                } catch (NameNotFoundException nnfe) {
                    logger.warn("Name not found on context ");
                } catch (NamingException e) {
                    logger.error("Error retrieving Context : ", e);
                }
            }
            try {
                if (url != null) {
                    url.openConnection();
                }
            } catch (FileNotFoundException fnfe) {
                url = null;
            }
            if (url == null) {
                url = Thread.currentThread().getContextClassLoader().getResource(name + ".xml");
            }
        } catch (IOException ioe) {
            logger.error("Error reading XML file", ioe);
            throw new EfreetException(ioe.getMessage());
        }
        return url;
    }
public void metodo1() {
        int temp;
        boolean flagDesordenado = true;
        while (flagDesordenado) {
            flagDesordenado = false;
            for (int i = 0; i < this.tamanoTabla - 1; i++) {
                if (tabla[i] > tabla[i + 1]) {
                    flagDesordenado = true;
                    temp = tabla[i];
                    tabla[i] = tabla[i + 1];
                    tabla[i + 1] = temp;
                }
            }
        }
    }
private void extractSpecifications(String id, File specification) {
        Object resource = getClass().getResource(id + ".xml");
        if (resource instanceof URL) {
            URL url = (URL) resource;
            try {
                InputStream istream = url.openStream();
                try {
                    OutputStream ostream = new FileOutputStream(specification);
                    try {
                        byte[] buffer = new byte[1024];
                        int length;
                        while ((length = istream.read(buffer)) > 0) {
                            ostream.write(buffer, 0, length);
                        }
                    } finally {
                        ostream.close();
                    }
                } finally {
                    istream.close();
                }
            } catch (IOException ex) {
                throw new RuntimeException("Failed to open " + url, ex);
            }
        }
    }
public boolean exists(String filename) {
        String localFileName = (java.io.File.separatorChar != '/') ? filename.replace('/', java.io.File.separatorChar) : filename;
        for (int i = 0; i < dirs.length; i++) {
            if (zipEntries[i] != null) {
                if (zipEntries[i].get(filename) != null) return true;
                String dir = "";
                String name = filename;
                int index = filename.lastIndexOf('/');
                if (index >= 0) {
                    dir = filename.substring(0, index);
                    name = filename.substring(index + 1);
                }
                Vector directory = (Vector) zipEntries[i].get(dir);
                if (directory != null && directory.contains(name)) return true;
                continue;
            }
            if (bases[i] != null) {
                try {
                    URL url = new URL(bases[i], filename);
                    URLConnection conn = url.openConnection();
                    conn.connect();
                    conn.getInputStream().close();
                    return true;
                } catch (IOException ex) {
                }
                continue;
            }
            if (dirs[i] == null) continue;
            if (zips[i] != null) {
                String fullname = zipDirs[i] != null ? zipDirs[i] + filename : filename;
                ZipEntry ze = zips[i].getEntry(fullname);
                if (ze != null) return true;
            } else {
                try {
                    File f = new File(dirs[i], localFileName);
                    if (f.exists()) return true;
                } catch (SecurityException ex) {
                }
            }
        }
        return false;
    }
private static void fileUpload() throws Exception {
        DefaultHttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(postURL);
        file = new File("h:\\Fantastic face.jpg");
        MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
        ContentBody cbFile = new FileBody(file);
        mpEntity.addPart("MAX_FILE_SIZE", new StringBody("2147483647"));
        mpEntity.addPart("owner", new StringBody(""));
        mpEntity.addPart("pin", new StringBody(pin));
        mpEntity.addPart("base", new StringBody(base));
        mpEntity.addPart("host", new StringBody("letitbit.net"));
        mpEntity.addPart("file0", cbFile);
        httppost.setEntity(mpEntity);
        System.out.println("executing request " + httppost.getRequestLine());
        System.out.println("Now uploading your file into letitbit.net");
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity resEntity = response.getEntity();
        System.out.println(response.getStatusLine());
        if (resEntity != null) {
            uploadresponse = EntityUtils.toString(resEntity);
        }
        System.out.println("Upload response : " + uploadresponse);
    }
public static void loginLetitbit() throws Exception {
        HttpParams params = new BasicHttpParams();
        params.setParameter("http.useragent", "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2) Gecko/20100115 Firefox/3.6");
        DefaultHttpClient httpclient = new DefaultHttpClient(params);
        System.out.println("Trying to log in to letitbit.com");
        HttpPost httppost = new HttpPost("http://letitbit.net/");
        httppost.setHeader("Cookie", phpsessioncookie);
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        formparams.add(new BasicNameValuePair("act", "login"));
        formparams.add(new BasicNameValuePair("login", ""));
        formparams.add(new BasicNameValuePair("password", ""));
        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
        httppost.setEntity(entity);
        HttpResponse httpresponse = httpclient.execute(httppost);
        System.out.println("Getting cookies........");
        Iterator<Cookie> it = httpclient.getCookieStore().getCookies().iterator();
        Cookie escookie = null;
        while (it.hasNext()) {
            escookie = it.next();
            if (escookie.getName().equalsIgnoreCase("log")) {
                logcookie = "log=" + escookie.getValue();
                System.out.println(logcookie);
            }
            if (escookie.getName().equalsIgnoreCase("pas")) {
                pascookie = "pas=" + escookie.getValue();
                System.out.println(pascookie);
            }
            if (escookie.getName().equalsIgnoreCase("host")) {
                hostcookie = "host=" + escookie.getValue();
                System.out.println(hostcookie);
            }
        }
    }
public static void copy(File src, File dest) throws IOException {
        if (!src.exists()) {
            throw new IOException(StaticUtils.format(OStrings.getString("LFC_ERROR_FILE_DOESNT_EXIST"), new Object[] { src.getAbsolutePath() }));
        }
        FileInputStream fis = new FileInputStream(src);
        dest.getParentFile().mkdirs();
        FileOutputStream fos = new FileOutputStream(dest);
        byte[] b = new byte[BUFSIZE];
        int readBytes;
        while ((readBytes = fis.read(b)) > 0) fos.write(b, 0, readBytes);
        fis.close();
        fos.close();
    }
protected static URL[] createUrls(URL jarUrls[]) {
        ArrayList<URL> additionalUrls = new ArrayList<URL>(Arrays.asList(jarUrls));
        for (URL ju : jarUrls) {
            try {
                JarFile jar = new JarFile(ju.getFile());
                Enumeration<JarEntry> entries = jar.entries();
                while (entries.hasMoreElements()) {
                    JarEntry j = entries.nextElement();
                    if (j.isDirectory()) continue;
                    if (j.getName().startsWith("lib/") && j.getName().endsWith(".jar")) {
                        URL url = new URL("jar:" + ju.getProtocol() + ":" + ju.getFile() + "!/" + j.getName());
                        InputStream is = url.openStream();
                        File tmpFile = File.createTempFile("SCDeploy", ".jar");
                        FileOutputStream fos = new FileOutputStream(tmpFile);
                        IOUtils.copy(is, fos);
                        is.close();
                        fos.close();
                        additionalUrls.add(new URL("file://" + tmpFile.getAbsolutePath()));
                    }
                }
            } catch (IOException e) {
            }
        }
        return additionalUrls.toArray(new URL[] {});
    }
private byte[] getFileFromFtp(String remote) throws Exception {
        ftp = new FTPClient();
        int reply;
        ftp.connect(ftpServer);
        reply = ftp.getReplyCode();
        if (!FTPReply.isPositiveCompletion(reply)) {
            ftp.disconnect();
            throw new Exception("FTP server refused connection.");
        }
        if (!ftp.login(ftpUsername, ftpPassword)) {
            ftp.logout();
            throw new Exception("Cann't login to ftp.");
        }
        ftp.enterLocalPassiveMode();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ftp.retrieveFile(remote, baos);
        ftp.logout();
        if (ftp.isConnected()) {
            try {
                ftp.disconnect();
            } catch (IOException f) {
            }
        }
        return baos.toByteArray();
    }
public static final String calculate(File f) {
        MessageDigest md;
        BufferedReader rd;
        StringBuffer buffer = new StringBuffer("");
        try {
            rd = new BufferedReader(new FileReader(f));
            md = MessageDigest.getInstance("SHA");
            String line = "";
            while ((line = rd.readLine()) != null) buffer.append(line);
            md.update(buffer.toString().getBytes());
            byte[] digest = md.digest();
            String result = "";
            for (byte b : digest) result += String.format("%h", b & 0xFF);
            return result;
        } catch (Exception ex) {
            ex.printStackTrace();
            return "";
        }
    }
@Override
    protected <T> T execute(final HttpMethod method, final String url, Parameters parameters, final Handler<T> handler) throws FoursquareException {
        HttpURLConnection connection = null;
        try {
            switch(method) {
                case GET:
                    connection = openConnection(url.concat("?").concat(formEncode(parameters)));
                    connection.setRequestMethod("GET");
                    connection.connect();
                    break;
                case POST:
                    connection = openConnection(url);
                    connection.setRequestMethod("POST");
                    connection.setDoOutput(true);
                    connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
                    connection.connect();
                    final OutputStream out = connection.getOutputStream();
                    out.write(formEncode(parameters).getBytes());
                    out.flush();
                    out.close();
                    break;
            }
            final int statusCode = connection.getResponseCode();
            if (statusCode / 100 != 2) {
                final Error error = parseBody(connection.getErrorStream(), new ErrorHandler());
                if (error == null) throw new FoursquareException(connection.getResponseMessage()); else if ("error".equals(error.getType())) throw new FoursquareException(error.getMessage()); else if ("unauthorized".equals(error.getType())) throw new AuthenticationException(error.getMessage()); else if ("ratelimited".equals(error.getType())) throw new RateLimitingException(error.getMessage()); else throw new FoursquareException(connection.getResponseMessage());
            }
            return parseBody(connection.getInputStream(), handler);
        } catch (final IOException e) {
            throw new FoursquareException(e);
        } catch (final ParserConfigurationException e) {
            throw new FoursquareException(e);
        } catch (final SAXException e) {
            throw new FoursquareException(e);
        } finally {
            if (connection != null) connection.disconnect();
        }
    }
protected HttpURLConnection openConnection(final String url) throws IOException {
        final HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
        connection.setInstanceFollowRedirects(true);
        connection.setRequestProperty("User-Agent", userAgent);
        connection.setRequestProperty("Accept", "application/xhtml+xml,application/xml,text/xml;q=0.9,*/*;q=0.8");
        connection.setRequestProperty("Accept-Language", "ja,en-us;q=0.7,en;q=0.3");
        connection.setRequestProperty("Accept-Encoding", "deflate");
        connection.setRequestProperty("Accept-Charset", "utf-8");
        connection.setRequestProperty("Authorization", "Basic ".concat(base64Encode((username.concat(":").concat(password)).getBytes("UTF-8"))));
        return connection;
    }