semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void end() throws Exception {
        handle.waitFor();
        Calendar endTime = Calendar.getInstance();
        File resultsDir = new File(runDir, "results");
        if (!resultsDir.isDirectory()) throw new Exception("The results directory not found!");
        String resHtml = null;
        String resTxt = null;
        String[] resultFiles = resultsDir.list();
        for (String resultFile : resultFiles) {
            if (resultFile.indexOf("html") >= 0) resHtml = resultFile; else if (resultFile.indexOf("txt") >= 0) resTxt = resultFile;
        }
        if (resHtml == null) throw new IOException("SPECweb2005 output (html) file not found");
        if (resTxt == null) throw new IOException("SPECweb2005 output (txt) file not found");
        File resultHtml = new File(resultsDir, resHtml);
        copyFile(resultHtml.getAbsolutePath(), runDir + "SPECWeb-result.html", false);
        BufferedReader reader = new BufferedReader(new FileReader(new File(resultsDir, resTxt)));
        logger.fine("Text file: " + resultsDir + resTxt);
        Writer writer = new FileWriter(runDir + "summary.xml");
        SummaryParser parser = new SummaryParser(getRunId(), startTime, endTime, logger);
        parser.convert(reader, writer);
        writer.close();
        reader.close();
    }
private String getContents(Server server, String uri) throws TechnicalException {
        try {
            URL url = new URL("http://localhost:" + PORT + uri);
            return StreamUtils.getStreamContent(url.openStream());
        } catch (Exception e) {
            e.printStackTrace();
            throw new TechnicalException(e);
        }
    }
public void run() {
        try {
            HttpURLConnection con = (HttpURLConnection) url.openConnection();
            Osm2Model osm = new Osm2Model(pedestrian, filterCyclic);
            osm.progress.connect(this, "progress(int)");
            osm.parseFile(con.getInputStream(), con.getContentLength());
            if (osm.somethingImported()) {
                done.emit();
            } else {
                nothing.emit();
            }
        } catch (Exception e) {
            failed.emit();
        }
    }
public void convert(File file, String fromEncoding, String toEncoding) throws IOException {
        InputStream in = new FileInputStream(file);
        StringWriter cache = new StringWriter();
        Reader reader = new InputStreamReader(in, fromEncoding);
        char[] buffer = new char[128];
        int read;
        while ((read = reader.read(buffer)) > -1) {
            cache.write(buffer, 0, read);
        }
        reader.close();
        in.close();
        Log.warn(this, "read from file " + file + " (" + fromEncoding + "):" + cache);
        OutputStream out = new FileOutputStream(file);
        OutputStreamWriter writer = new OutputStreamWriter(out, toEncoding);
        writer.write(cache.toString());
        cache.close();
        writer.close();
        out.close();
    }
public byte[] md5(String clearText) {
        MessageDigest md;
        byte[] digest;
        try {
            md = MessageDigest.getInstance("MD5");
            md.update(clearText.getBytes());
            digest = md.digest();
        } catch (NoSuchAlgorithmException e) {
            throw new UnsupportedOperationException(e.toString());
        }
        return digest;
    }
private boolean addBookmark0(Bookmark bookmark, BookmarkFolder folder, PreparedStatement preparedStatement) throws SQLException {
        Object[] bindVariables = new Object[8];
        int[] types = new int[8];
        types[0] = Types.BOOLEAN;
        types[1] = Types.TIMESTAMP;
        types[2] = Types.TIMESTAMP;
        types[3] = Types.VARCHAR;
        types[4] = Types.VARCHAR;
        types[5] = Types.BIGINT;
        types[6] = Types.VARCHAR;
        types[7] = Types.VARCHAR;
        bindVariables[0] = Boolean.valueOf(bookmark.isFavorite());
        Date time = bookmark.getCreationTime();
        bindVariables[1] = new Timestamp(time == null ? System.currentTimeMillis() : time.getTime());
        time = bookmark.getLastAccess();
        bindVariables[2] = new Timestamp(time == null ? System.currentTimeMillis() : time.getTime());
        bindVariables[3] = bookmark.getName();
        bindVariables[4] = bookmark.getCommandText();
        bindVariables[5] = new Long(bookmark.getUseCount());
        bindVariables[6] = folder == null ? bookmark.getPath() : folder.getPath();
        ColorLabel colorLabel = bookmark.getColorLabel();
        bindVariables[7] = colorLabel == null ? null : colorLabel.name();
        boolean doBatch = (preparedStatement != null);
        boolean hasError = true;
        embeddedConnection.setAutoCommit(false);
        PreparedStatement statement = null;
        try {
            if (preparedStatement == null) {
                statement = embeddedConnection.prepareStatement(BOOKMARK_INSERT);
            } else {
                statement = preparedStatement;
            }
            for (int i = 0; i < bindVariables.length; i++) {
                if (bindVariables[i] == null) {
                    statement.setNull(i + 1, types[i]);
                } else {
                    statement.setObject(i + 1, bindVariables[i]);
                }
            }
            try {
                int affectedCount = statement.executeUpdate();
                long identityValue = getInsertedPrimaryKey();
                bookmark.setId(identityValue);
                addBindVariables(bookmark);
                hasError = false;
                return affectedCount == 1;
            } catch (SQLException exception) {
                if (CONSTRAINT_VIOLATION.equals(exception.getSQLState())) {
                    return false;
                }
                throw exception;
            }
        } finally {
            if (hasError) {
                embeddedConnection.rollback();
            } else {
                embeddedConnection.commit();
            }
            embeddedConnection.setAutoCommit(true);
            if (preparedStatement != null) {
                if (!doBatch) {
                    try {
                        preparedStatement.close();
                    } catch (SQLException ignored) {
                    }
                } else if (doBatch) {
                    preparedStatement.clearParameters();
                    preparedStatement.clearWarnings();
                }
            }
        }
    }
public File read() throws IOException {
        URLConnection conn = url.openConnection();
        conn.setConnectTimeout(5000);
        conn.setReadTimeout(5000);
        conn.connect();
        int length = conn.getContentLength();
        String tempDir = System.getProperty("java.io.tmpdir");
        if (tempDir == null) {
            tempDir = ".";
        }
        File tempFile = new File(tempDir + "/" + new GUID() + ".dat");
        tempFile.deleteOnExit();
        InputStream in = null;
        OutputStream out = null;
        ProgressMonitor monitor = new ProgressMonitor(parentComponent, "Downloading " + url, null, 0, length);
        try {
            in = conn.getInputStream();
            out = new BufferedOutputStream(new FileOutputStream(tempFile));
            int buflen = 1024 * 30;
            int bytesRead = 0;
            byte[] buf = new byte[buflen];
            ;
            long start = System.currentTimeMillis();
            for (int nRead = in.read(buf); nRead != -1; nRead = in.read(buf)) {
                if (monitor.isCanceled()) {
                    return null;
                }
                bytesRead += nRead;
                out.write(buf, 0, nRead);
                monitor.setProgress(bytesRead);
            }
        } finally {
            if (in != null) {
                in.close();
            }
            if (out != null) {
                out.close();
            }
            monitor.close();
        }
        return tempFile;
    }
@Override
    protected void writeFile() {
        super.writeFile();
        try {
            String tagListFilePath = file.toURI().toASCIIString();
            tagListFilePath = tagListFilePath.substring(0, tagListFilePath.lastIndexOf(FileManager.GLIPS_VIEW_EXTENSION)) + FileManager.TAG_LIST_FILE_EXTENSION;
            File tagListFile = new File(new URI(tagListFilePath));
            StringBuffer buffer = new StringBuffer("");
            for (String tagName : tags) {
                buffer.append(tagName + "\n");
            }
            ByteBuffer byteBuffer = ByteBuffer.wrap(buffer.toString().getBytes("UTF-8"));
            FileOutputStream out = new FileOutputStream(tagListFile);
            FileChannel channel = out.getChannel();
            channel.write(byteBuffer);
            channel.close();
        } catch (Exception ex) {
        }
        try {
            String parentPath = file.getParentFile().toURI().toASCIIString();
            if (!parentPath.endsWith("/")) {
                parentPath += "/";
            }
            File srcFile = null, destFile = null;
            byte[] tab = new byte[1000];
            int nb = 0;
            InputStream in = null;
            OutputStream out = null;
            for (String destinationName : dataBaseFiles.keySet()) {
                srcFile = dataBaseFiles.get(destinationName);
                if (srcFile != null) {
                    destFile = new File(new URI(parentPath + destinationName));
                    in = new BufferedInputStream(new FileInputStream(srcFile));
                    out = new BufferedOutputStream(new FileOutputStream(destFile));
                    while (in.available() > 0) {
                        nb = in.read(tab);
                        if (nb > 0) {
                            out.write(tab, 0, nb);
                        }
                    }
                    in.close();
                    out.flush();
                    out.close();
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
private static byte[] getKey(String password) throws UnsupportedEncodingException, NoSuchAlgorithmException {
        MessageDigest messageDigest = MessageDigest.getInstance(Constants.HASH_FUNCTION);
        messageDigest.update(password.getBytes(Constants.ENCODING));
        byte[] hashValue = messageDigest.digest();
        int keyLengthInbytes = Constants.ENCRYPTION_KEY_LENGTH / 8;
        byte[] result = new byte[keyLengthInbytes];
        System.arraycopy(hashValue, 0, result, 0, keyLengthInbytes);
        return result;
    }
public void run() {
            final String basename = FilenameUtils.removeExtension(file.getName());
            final File compressed = new File(logDirectory, basename + ".gz");
            InputStream in = null;
            OutputStream out = null;
            try {
                in = new FileInputStream(file);
                out = new GZIPOutputStream(new FileOutputStream(compressed));
                IOUtils.copy(in, out);
                in.close();
                out.close();
            } catch (IOException e) {
                reportError("Error compressing olg log file after file rotation", e, ErrorManager.GENERIC_FAILURE);
            } finally {
                IOUtils.closeQuietly(in);
                IOUtils.closeQuietly(out);
            }
            Collections.replaceAll(files, file, compressed);
        }
@SuppressWarnings("unchecked")
    private void updatePortfolio(List entries, String query) {
        BufferedReader in = null;
        try {
            URL url = new URL(query);
            System.out.println(query);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            int status = conn.getResponseCode();
            if (status == 200) {
                in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                int count = 0;
                while (true) {
                    String line = in.readLine();
                    if (line == null || count >= entries.size()) break;
                    updateEntry((PortfolioEntry) entries.get(count), line);
                    count++;
                }
            }
        } catch (Exception e) {
            logger.error(MiscUtils.stackTrace2String(e));
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (Exception ignore) {
                }
            }
        }
    }
private byte[] pullMapBytes(String directoryLocation) {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        try {
            URL url = new URL(directoryLocation);
            HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
            InputStream is = httpURLConnection.getInputStream();
            int nRead;
            byte[] data = new byte[1024];
            while ((nRead = is.read(data, 0, data.length)) != -1) {
                buffer.write(data, 0, nRead);
            }
            buffer.flush();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return buffer.toByteArray();
    }
protected static void createBackup() throws IOException, IllegalStateException, FTPIllegalReplyException, FTPException, FileNotFoundException, FTPDataTransferException, FTPAbortedException {
        String cmd = "mysqldump -u " + Constants.dbUser + " -p" + Constants.dbPassword + " " + Constants.dbName + " > " + Constants.tmpDir + "Backup.sql";
        FileWriter fstream = new FileWriter(Constants.tmpDir + Constants.tmpScript);
        BufferedWriter out = new BufferedWriter(fstream);
        out.write(cmd);
        out.close();
        Process process = Runtime.getRuntime().exec(Constants.tmpDir + Constants.tmpScript);
        InputStream is = process.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(isr);
        while (br.readLine() != null) {
            ;
        }
        String fileName = now4backup();
        cmd = "\"C:\\Archivos de programa\\WinRAR\\Rar.exe\" a -m5 -ed " + Constants.tmpDir + fileName + " " + Constants.tmpDir + "Backup.sql";
        process = Runtime.getRuntime().exec(cmd);
        is = process.getInputStream();
        isr = new InputStreamReader(is);
        br = new BufferedReader(isr);
        while (br.readLine() != null) {
            ;
        }
        FTPClient client = new FTPClient();
        client.connect(Constants.ftpBackupAddr);
        client.login(Constants.ftpBackupUser, Constants.ftpBackupPassword);
        client.changeDirectory("/" + Shared.getConfig("storeName"));
        File f = new File(Constants.tmpDir + fileName);
        client.upload(f);
        client.disconnect(false);
    }
protected final Properties getResourceProperties(Long id, String baseURL) {
        try {
            URL url = getClass().getResource(baseURL + id + ".properties");
            if (url == null) {
                url = new URL(baseURL + id + ".properties");
            }
            Properties props = new Properties();
            InputStream is = url.openStream();
            props.load(is);
            is.close();
            return props;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
private void doImageProcess(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("image/" + type + "");
        Point imgSize = null;
        if (width > 0 || height > 0) {
            imgSize = new Point(width, height);
        }
        if (fmt != null && imageFormats.containsKey(fmt)) {
            imgSize = imageFormats.get(fmt);
        }
        InputStream imageInputStream = inputStream != null ? inputStream : imageUrl.openStream();
        if (imageInputStream == null) {
            throw new RuntimeException("File " + imageUrl + " does not exist!");
        }
        if (imgSize == null) {
            IOUtils.copy(imageInputStream, response.getOutputStream());
        } else {
            byte[] imageBytes = getImageBytes(type, imgSize, imageInputStream);
            response.setContentLength(imageBytes.length);
            response.getOutputStream().write(imageBytes);
        }
        response.getOutputStream().flush();
        response.getOutputStream().close();
    }
protected static String getURLandWriteToDisk(String url, Model retModel) throws MalformedURLException, IOException {
        String path = null;
        URL ontURL = new URL(url);
        InputStream ins = ontURL.openStream();
        InputStreamReader bufRead;
        OutputStreamWriter bufWrite;
        int offset = 0, read = 0;
        initModelHash();
        if (System.getProperty("user.dir") != null) {
            String delimiter;
            path = System.getProperty("user.dir");
            if (path.contains("/")) {
                delimiter = "/";
            } else {
                delimiter = "\\";
            }
            char c = path.charAt(path.length() - 1);
            if (c == '/' || c == '\\') {
                path = path.substring(0, path.length() - 2);
            }
            path = path.substring(0, path.lastIndexOf(delimiter) + 1);
            path = path.concat("ontologies" + delimiter + "downloaded");
            (new File(path)).mkdir();
            path = path.concat(delimiter);
            path = createFullPath(url, path);
            bufWrite = new OutputStreamWriter(new FileOutputStream(path));
            bufRead = new InputStreamReader(ins);
            read = bufRead.read();
            while (read != -1) {
                bufWrite.write(read);
                offset += read;
                read = bufRead.read();
            }
            bufRead.close();
            bufWrite.close();
            ins.close();
            FileInputStream fs = new FileInputStream(path);
            retModel.read(fs, "");
        }
        return path;
    }
protected ResourceBundle loadBundle(String prefix) {
        URL url = Thread.currentThread().getContextClassLoader().getResource(prefix + ".properties");
        if (url != null) {
            try {
                return new PropertyResourceBundle(url.openStream());
            } catch (IOException e) {
                throw ThrowableManagerRegistry.caught(e);
            }
        }
        return null;
    }
public static void main(String[] args) throws IOException {
        File inputFile = new File("D:/farrago.txt");
        File outputFile = new File("D:/outagain.txt");
        FileReader in = new FileReader(inputFile);
        FileWriter out = new FileWriter(outputFile);
        int c;
        while ((c = in.read()) != -1) out.write(c);
        in.close();
        out.close();
    }
public String digest(String algorithm, String text) {
        MessageDigest digester = null;
        try {
            digester = MessageDigest.getInstance(algorithm);
            digester.update(text.getBytes(Digester.ENCODING));
        } catch (NoSuchAlgorithmException nsae) {
            _log.error(nsae, nsae);
        } catch (UnsupportedEncodingException uee) {
            _log.error(uee, uee);
        }
        byte[] bytes = digester.digest();
        if (_BASE_64) {
            return Base64.encode(bytes);
        } else {
            return new String(Hex.encodeHex(bytes));
        }
    }
private void downloadFile(String name, URL url, File file) throws IOException {
        InputStream in = null;
        FileOutputStream out = null;
        try {
            URLConnection conn = url.openConnection();
            conn.setConnectTimeout(10000);
            conn.setReadTimeout(10000);
            int expectedSize = conn.getContentLength();
            progressPanel.downloadStarting(name, expectedSize == -1);
            int downloaded = 0;
            byte[] buf = new byte[1024];
            int length;
            in = conn.getInputStream();
            out = new FileOutputStream(file);
            while ((in != null) && ((length = in.read(buf)) != -1)) {
                downloaded += length;
                out.write(buf, 0, length);
                if (expectedSize != -1) progressPanel.downloadProgress((downloaded * 100) / expectedSize);
            }
            out.flush();
        } finally {
            progressPanel.downloadFinished();
            if (out != null) out.close();
            if (in != null) in.close();
        }
    }
public static String calculateHA1(String username, byte[] password) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(getBytes(username, ISO_8859_1));
            md.update((byte) ':');
            md.update(getBytes(DAAP_REALM, ISO_8859_1));
            md.update((byte) ':');
            md.update(password);
            return toHexString(md.digest());
        } catch (NoSuchAlgorithmException err) {
            throw new RuntimeException(err);
        }
    }
public static String calculateHA2(String uri) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(getBytes("GET", ISO_8859_1));
            md.update((byte) ':');
            md.update(getBytes(uri, ISO_8859_1));
            return toHexString(md.digest());
        } catch (NoSuchAlgorithmException err) {
            throw new RuntimeException(err);
        }
    }
public static String digest(String ha1, String ha2, String nonce) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(getBytes(ha1, ISO_8859_1));
            md.update((byte) ':');
            md.update(getBytes(nonce, ISO_8859_1));
            md.update((byte) ':');
            md.update(getBytes(ha2, ISO_8859_1));
            return toHexString(md.digest());
        } catch (NoSuchAlgorithmException err) {
            throw new RuntimeException(err);
        }
    }
private File tmpFileFromURL(String name) {
        if (name == null) {
            System.out.println("ERROR: the provided URL is invalid, aborting download!");
            return null;
        }
        try {
            final URL url = new URL(name);
            final InputStream in = url.openStream();
            final URLConnection conn = url.openConnection();
            final int total = conn.getContentLength();
            final String contentType = conn.getContentType();
            logger.fine("DOWNLOADING   Content-type: " + contentType);
            if (contentType.trim().toLowerCase().indexOf("html") != -1) {
                return tmpFileFromURL(extractRedirectURL(in));
            }
            final FileManager fileManager = system.getFileManager();
            final File dest = fileManager.createTmpModuleFile();
            final FileOutputStream out = new FileOutputStream(dest);
            final byte[] buf = new byte[2048];
            logger.fine("Total number of bytes to download: " + total);
            int len, current = 0;
            progress(new ProgressEvent(this, "Downloading " + name, 0));
            while ((len = in.read(buf)) > 0) {
                current += len;
                progress(new ProgressEvent(this, "Downloading " + name, (int) ((current * 100.0) / total)));
                out.write(buf, 0, len);
                out.flush();
            }
            in.close();
            out.flush();
            out.close();
            return dest;
        } catch (IOException ex) {
            progress(new ProgressEvent("  ERROR: downloading of " + name + " failed. URL does not exist!"));
            return null;
        }
    }