semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private void transformFile(File input, File output, Cipher cipher, boolean compress, String progressMessage) throws IOException {
        FileInputStream fileInputStream = new FileInputStream(input);
        InputStream inputStream;
        if (progressMessage != null) {
            inputStream = new ProgressMonitorInputStream(null, progressMessage, fileInputStream);
        } else {
            inputStream = fileInputStream;
        }
        FilterInputStream is = new BufferedInputStream(inputStream);
        FilterOutputStream os = new BufferedOutputStream(new FileOutputStream(output));
        FilterInputStream fis;
        FilterOutputStream fos;
        if (compress) {
            fis = is;
            fos = new GZIPOutputStream(new CipherOutputStream(os, cipher));
        } else {
            fis = new GZIPInputStream(new CipherInputStream(is, cipher));
            fos = os;
        }
        byte[] buffer = new byte[cipher.getBlockSize() * blocksInBuffer];
        int readLength = fis.read(buffer);
        while (readLength != -1) {
            fos.write(buffer, 0, readLength);
            readLength = fis.read(buffer);
        }
        if (compress) {
            GZIPOutputStream gos = (GZIPOutputStream) fos;
            gos.finish();
        }
        fos.close();
        fis.close();
    }
public static String fetchUrl(String urlString) {
        try {
            URL url = new URL(urlString);
            BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
            String line = null;
            StringBuilder builder = new StringBuilder();
            while ((line = reader.readLine()) != null) {
                builder.append(line);
            }
            reader.close();
            return builder.toString();
        } catch (MalformedURLException e) {
        } catch (IOException e) {
        }
        return "";
    }
protected ExternalDecoder(InputStream source, Process process) {
        super(source);
        this.process = process;
        this.processStdOut = process.getInputStream();
        this.processStdIn = process.getOutputStream();
        new Thread() {

            @Override
            public void run() {
                try {
                    IOUtils.copy(getSource(), processStdIn);
                    System.err.println("Copy done.");
                    close();
                } catch (IOException e) {
                    e.printStackTrace();
                    IOUtils.closeQuietly(ExternalDecoder.this);
                }
            }
        }.start();
    }
@Override
            public void run() {
                try {
                    IOUtils.copy(getSource(), processStdIn);
                    System.err.println("Copy done.");
                    close();
                } catch (IOException e) {
                    e.printStackTrace();
                    IOUtils.closeQuietly(ExternalDecoder.this);
                }
            }
public int subclass(int objectId, String description) throws FidoDatabaseException, ObjectNotFoundException {
        try {
            Connection conn = null;
            Statement stmt = null;
            ResultSet rs = null;
            try {
                String sql = "insert into Objects (Description) " + "values ('" + description + "')";
                conn = fido.util.FidoDataSource.getConnection();
                conn.setAutoCommit(false);
                stmt = conn.createStatement();
                if (contains(stmt, objectId) == false) throw new ObjectNotFoundException(objectId);
                stmt.executeUpdate(sql);
                int id;
                sql = "select currval('objects_objectid_seq')";
                rs = stmt.executeQuery(sql);
                if (rs.next() == false) throw new SQLException("No rows returned from select currval() query"); else id = rs.getInt(1);
                ObjectLinkTable objectLinkList = new ObjectLinkTable();
                objectLinkList.linkObjects(stmt, id, "isa", objectId);
                conn.commit();
                return id;
            } catch (SQLException e) {
                if (conn != null) conn.rollback();
                throw e;
            } finally {
                if (rs != null) rs.close();
                if (stmt != null) stmt.close();
                if (conn != null) conn.close();
            }
        } catch (SQLException e) {
            throw new FidoDatabaseException(e);
        }
    }
public int instantiate(int objectId, String description) throws FidoDatabaseException, ObjectNotFoundException, ClassLinkTypeNotFoundException {
        try {
            Connection conn = null;
            Statement stmt = null;
            ResultSet rs = null;
            try {
                String sql = "insert into Objects (Description) " + "values ('" + description + "')";
                conn = fido.util.FidoDataSource.getConnection();
                conn.setAutoCommit(false);
                stmt = conn.createStatement();
                if (contains(stmt, objectId) == false) throw new ObjectNotFoundException(objectId);
                stmt.executeUpdate(sql);
                int id;
                sql = "select currval('objects_objectid_seq')";
                rs = stmt.executeQuery(sql);
                if (rs.next() == false) throw new SQLException("No rows returned from select currval() query"); else id = rs.getInt(1);
                ObjectLinkTable objectLinkList = new ObjectLinkTable();
                objectLinkList.linkObjects(stmt, id, "instance", objectId);
                conn.commit();
                return id;
            } catch (SQLException e) {
                if (conn != null) conn.rollback();
                throw e;
            } finally {
                if (rs != null) rs.close();
                if (stmt != null) stmt.close();
                if (conn != null) conn.close();
            }
        } catch (SQLException e) {
            throw new FidoDatabaseException(e);
        }
    }
public void deleteInstance(int instanceId) throws FidoDatabaseException, ObjectNotFoundException {
        try {
            Connection conn = null;
            Statement stmt = null;
            try {
                conn = fido.util.FidoDataSource.getConnection();
                conn.setAutoCommit(false);
                stmt = conn.createStatement();
                if (contains(stmt, instanceId) == false) throw new ObjectNotFoundException(instanceId);
                ObjectLinkTable objectLinkList = new ObjectLinkTable();
                ObjectAttributeTable objectAttributeList = new ObjectAttributeTable();
                objectLinkList.deleteObject(stmt, instanceId);
                objectAttributeList.deleteObject(stmt, instanceId);
                stmt.executeUpdate("delete from Objects where ObjectId = " + instanceId);
                conn.commit();
            } catch (SQLException e) {
                if (conn != null) conn.rollback();
                throw e;
            } finally {
                if (stmt != null) stmt.close();
                if (conn != null) conn.close();
            }
        } catch (SQLException e) {
            throw new FidoDatabaseException(e);
        }
    }
private File downloadURL(URL url) {
        MerlotDebug.msg("Downloading URL: " + url);
        String filename = url.getFile();
        if (filename.indexOf('/') >= 0) {
            filename = filename.substring(filename.lastIndexOf('/') + 1);
        }
        File userPluginsDir = new File(XMLEditorSettings.USER_MERLOT_DIR, "plugins");
        File cache = new File(userPluginsDir, filename);
        try {
            if (!userPluginsDir.exists()) {
                userPluginsDir.mkdirs();
            }
            URLConnection connection = url.openConnection();
            if (cache.exists() && cache.canRead()) {
                connection.connect();
                long remoteTimestamp = connection.getLastModified();
                if (remoteTimestamp == 0 || remoteTimestamp > cache.lastModified()) {
                    cache = downloadContent(connection, cache);
                } else {
                    MerlotDebug.msg("Using cached version for URL: " + url);
                }
            } else {
                cache = downloadContent(connection, cache);
            }
        } catch (IOException ex) {
            MerlotDebug.exception(ex);
        }
        if (cache != null && cache.exists()) {
            return cache;
        } else {
            return null;
        }
    }
private static String fetchUrl(String url, boolean keepLineEnds) throws IOException, MalformedURLException {
        URLConnection destConnection = (new URL(url)).openConnection();
        BufferedReader br;
        String inputLine;
        StringBuffer doc = new StringBuffer();
        String contentEncoding;
        destConnection.setRequestProperty("Accept-Encoding", "gzip");
        if (proxyAuth != null) destConnection.setRequestProperty("Proxy-Authorization", proxyAuth);
        destConnection.connect();
        contentEncoding = destConnection.getContentEncoding();
        if ((contentEncoding != null) && contentEncoding.equals("gzip")) {
            br = new BufferedReader(new InputStreamReader(new GZIPInputStream(destConnection.getInputStream())));
        } else {
            br = new BufferedReader(new InputStreamReader(destConnection.getInputStream()));
        }
        while ((inputLine = br.readLine()) != null) {
            if (keepLineEnds) doc.append(inputLine + "\n"); else doc.append(inputLine);
        }
        br.close();
        return doc.toString();
    }
protected Document getRawResults(String urlString, Map args) throws Exception {
        int count = 0;
        Iterator keys = args.keySet().iterator();
        while (keys.hasNext()) {
            String sep = count++ == 0 ? "?" : "&";
            String name = (String) keys.next();
            if (args.get(name) != null) {
                urlString += sep + name + "=" + args.get(name);
            }
        }
        URL url = new URL(urlString);
        URLConnection conn = url.openConnection();
        conn.connect();
        SAXBuilder builder = new SAXBuilder();
        return builder.build(conn.getInputStream());
    }
public boolean renameTo(File dest) throws IOException {
        if (dest == null) {
            throw new NullPointerException("dest");
        }
        if (!file.renameTo(dest)) {
            FileInputStream inputStream = new FileInputStream(file);
            FileOutputStream outputStream = new FileOutputStream(dest);
            FileChannel in = inputStream.getChannel();
            FileChannel out = outputStream.getChannel();
            long destsize = in.transferTo(0, size, out);
            in.close();
            out.close();
            if (destsize == size) {
                file.delete();
                file = dest;
                isRenamed = true;
                return true;
            } else {
                dest.delete();
                return false;
            }
        }
        file = dest;
        isRenamed = true;
        return true;
    }
private static void zipFolder(File folder, ZipOutputStream zipOutputStream, String relativePath) throws IOException {
        File[] children = folder.listFiles();
        for (int i = 0; i < children.length; i++) {
            File child = children[i];
            if (child.isFile()) {
                String zipEntryName = children[i].getCanonicalPath().replace(relativePath + File.separator, "");
                ZipEntry entry = new ZipEntry(zipEntryName);
                zipOutputStream.putNextEntry(entry);
                InputStream inputStream = new FileInputStream(child);
                IOUtils.copy(inputStream, zipOutputStream);
                inputStream.close();
            } else {
                ZipUtil.zipFolder(child, zipOutputStream, relativePath);
            }
        }
    }
private static void addFolderToZip(File folder, ZipOutputStream zip, String baseName) throws IOException {
        File[] files = folder.listFiles();
        for (File file : files) {
            if (file.isDirectory()) {
                addFolderToZip(file, zip, baseName);
            } else {
                String name = file.getAbsolutePath().substring(baseName.length());
                ZipEntry zipEntry = new ZipEntry(name);
                zip.putNextEntry(zipEntry);
                IOUtils.copy(new FileInputStream(file), zip);
                zip.closeEntry();
            }
        }
    }
public static void main(String[] args) throws Exception {
        if (args.length < 2) {
            System.out.println("Usage: <target URI> <no of requests>");
            System.exit(-1);
        }
        URI targetURI = new URI(args[0]);
        int n = Integer.parseInt(args[1]);
        URL url = targetURI.toURL();
        byte[] buffer = new byte[4096];
        long startTime;
        long finishTime;
        int successCount = 0;
        int failureCount = 0;
        String serverName = "unknown";
        long total = 0;
        long contentLen = 0;
        long totalContentLen = 0;
        startTime = System.currentTimeMillis();
        for (int i = 0; i < n; i++) {
            HttpURLConnection c = (HttpURLConnection) url.openConnection();
            c.connect();
            InputStream instream = c.getInputStream();
            try {
                contentLen = 0;
                if (instream != null) {
                    int l = 0;
                    while ((l = instream.read(buffer)) != -1) {
                        total += l;
                        contentLen += l;
                    }
                }
                if (c.getResponseCode() == 200) {
                    successCount++;
                } else {
                    failureCount++;
                }
                totalContentLen += contentLen;
            } catch (IOException ex) {
                failureCount++;
            }
            String s = c.getHeaderField("Server");
            if (s != null) {
                serverName = s;
            }
        }
        finishTime = System.currentTimeMillis();
        float totalTimeSec = (float) (finishTime - startTime) / 1000;
        float reqsPerSec = (float) successCount / totalTimeSec;
        float timePerReqMs = (float) (finishTime - startTime) / (float) successCount;
        System.out.print("Server Software:\t");
        System.out.println(serverName);
        System.out.println();
        System.out.print("Document URI:\t\t");
        System.out.println(targetURI);
        System.out.print("Document Length:\t");
        System.out.print(contentLen);
        System.out.println(" bytes");
        System.out.println();
        System.out.print("Time taken for tests:\t");
        System.out.print(totalTimeSec);
        System.out.println(" seconds");
        System.out.print("Complete requests:\t");
        System.out.println(successCount);
        System.out.print("Failed requests:\t");
        System.out.println(failureCount);
        System.out.print("Content transferred:\t");
        System.out.print(total);
        System.out.println(" bytes");
        System.out.print("Requests per second:\t");
        System.out.print(reqsPerSec);
        System.out.println(" [#/sec] (mean)");
        System.out.print("Time per request:\t");
        System.out.print(timePerReqMs);
        System.out.println(" [ms] (mean)");
    }
public osid.shared.Id ingest(String fileName, String templateFileName, String fileType, File file, Properties properties) throws osid.dr.DigitalRepositoryException, java.net.SocketException, java.io.IOException, osid.shared.SharedException, javax.xml.rpc.ServiceException {
        long sTime = System.currentTimeMillis();
        if (DEBUG) System.out.println("INGESTING FILE TO FEDORA:fileName =" + fileName + "fileType =" + fileType + "t = 0");
        String host = FedoraUtils.getFedoraProperty(this, "admin.ftp.address");
        String url = FedoraUtils.getFedoraProperty(this, "admin.ftp.url");
        int port = Integer.parseInt(FedoraUtils.getFedoraProperty(this, "admin.ftp.port"));
        String userName = FedoraUtils.getFedoraProperty(this, "admin.ftp.username");
        String password = FedoraUtils.getFedoraProperty(this, "admin.ftp.password");
        String directory = FedoraUtils.getFedoraProperty(this, "admin.ftp.directory");
        FTPClient client = new FTPClient();
        client.connect(host, port);
        client.login(userName, password);
        client.changeWorkingDirectory(directory);
        client.setFileType(FTP.BINARY_FILE_TYPE);
        client.storeFile(fileName, new FileInputStream(file.getAbsolutePath().replaceAll("%20", " ")));
        client.logout();
        client.disconnect();
        if (DEBUG) System.out.println("INGESTING FILE TO FEDORA: Writting to FTP Server:" + (System.currentTimeMillis() - sTime));
        fileName = url + fileName;
        int BUFFER_SIZE = 10240;
        StringBuffer sb = new StringBuffer();
        String s = new String();
        BufferedInputStream fis = new BufferedInputStream(new FileInputStream(new File(getResource(templateFileName).getFile().replaceAll("%20", " "))));
        byte[] buf = new byte[BUFFER_SIZE];
        int ch;
        int len;
        while ((len = fis.read(buf)) > 0) {
            s = s + new String(buf);
        }
        fis.close();
        if (DEBUG) System.out.println("INGESTING FILE TO FEDORA: Read Mets File:" + (System.currentTimeMillis() - sTime));
        String r = updateMetadata(s, fileName, file.getName(), fileType, properties);
        if (DEBUG) System.out.println("INGESTING FILE TO FEDORA: Resplaced Metadata:" + (System.currentTimeMillis() - sTime));
        File METSfile = File.createTempFile("vueMETSMap", ".xml");
        FileOutputStream fos = new FileOutputStream(METSfile);
        fos.write(r.getBytes());
        fos.close();
        if (DEBUG) System.out.println("INGESTING FILE TO FEDORA: Ingest complete:" + (System.currentTimeMillis() - sTime));
        String pid = "Method Not Supported any more";
        System.out.println(" METSfile= " + METSfile.getPath() + " PID = " + pid);
        return new PID(pid);
    }
private static String md5(String digest, String data) throws IOException {
        MessageDigest messagedigest;
        try {
            messagedigest = MessageDigest.getInstance(digest);
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
        messagedigest.update(data.getBytes("ISO-8859-1"));
        byte[] bytes = messagedigest.digest();
        StringBuilder stringbuffer = new StringBuilder(bytes.length * 2);
        for (int j = 0; j < bytes.length; j++) {
            int k = bytes[j] >>> 4 & 0x0f;
            stringbuffer.append(hexChars[k]);
            k = bytes[j] & 0x0f;
            stringbuffer.append(hexChars[k]);
        }
        return stringbuffer.toString();
    }
public Dbf(URL url) throws java.io.IOException, DbfFileException {
        if (DEBUG) System.out.println("---->uk.ac.leeds.ccg.dbffile.Dbf constructed. Will identify itself as " + DBC);
        URLConnection uc = url.openConnection();
        InputStream in = uc.getInputStream();
        EndianDataInputStream sfile = new EndianDataInputStream(in);
        init(sfile);
    }
private static String getRegistrationClasses() {
        CentralRegistrationClass c = new CentralRegistrationClass();
        String name = c.getClass().getCanonicalName().replace('.', '/').concat(".class");
        try {
            Enumeration<URL> urlEnum = c.getClass().getClassLoader().getResources("META-INF/MANIFEST.MF");
            while (urlEnum.hasMoreElements()) {
                URL url = urlEnum.nextElement();
                String file = url.getFile();
                JarURLConnection jarConnection = (JarURLConnection) url.openConnection();
                Manifest mf = jarConnection.getManifest();
                Attributes attrs = (Attributes) mf.getAttributes(name);
                if (attrs != null) {
                    String classes = attrs.getValue("RegistrationClasses");
                    return classes;
                }
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        return "";
    }
private ModelDefinition buildModel(String name) {
        ModelDefinition model = null;
        URL url = ResourceLocator.locateBinaryModel(name);
        InputStream is = null;
        if (url == null) {
            url = ResourceLocator.locateTextModel(name);
            try {
                is = url.openStream();
                model = buildModelFromText(name, is);
                File file = ResourceLocator.replaceExtension(url, ResourceLocator.BINARY_MODEL_EXTENSION);
                BinaryExporter.getInstance().save(model, file);
            } catch (IOException e) {
                e.printStackTrace();
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }
        } else {
            try {
                is = url.openStream();
                model = (ModelDefinition) BinaryImporter.getInstance().load(is);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return model;
    }
private String[] read(String path) throws Exception {
        final String[] names = { "index.txt", "", "index.html", "index.htm" };
        String[] list = null;
        for (int i = 0; i < names.length; i++) {
            URL url = new URL(path + names[i]);
            try {
                BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
                StringBuffer sb = new StringBuffer();
                String s = null;
                while ((s = in.readLine()) != null) {
                    s = s.trim();
                    if (s.length() > 0) {
                        sb.append(s + "\n");
                    }
                }
                in.close();
                if (sb.indexOf("<") != -1 && sb.indexOf(">") != -1) {
                    List links = LinkExtractor.scan(url, sb.toString());
                    HashSet set = new HashSet();
                    int prefixLen = path.length();
                    for (Iterator it = links.iterator(); it.hasNext(); ) {
                        String link = it.next().toString();
                        if (!link.startsWith(path)) {
                            continue;
                        }
                        link = link.substring(prefixLen);
                        int idx = link.indexOf("/");
                        int idxq = link.indexOf("?");
                        if (idx > 0 && (idxq == -1 || idx < idxq)) {
                            set.add(link.substring(0, idx + 1));
                        } else {
                            set.add(link);
                        }
                    }
                    list = (String[]) set.toArray(new String[0]);
                } else {
                    list = sb.toString().split("\n");
                }
                return list;
            } catch (FileNotFoundException e) {
                e.printStackTrace();
                continue;
            }
        }
        return new String[0];
    }