semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private void copyMerge(Path[] sources, OutputStream out) throws IOException {
        Configuration conf = getConf();
        for (int i = 0; i < sources.length; ++i) {
            FileSystem fs = sources[i].getFileSystem(conf);
            InputStream in = fs.open(sources[i]);
            try {
                IOUtils.copyBytes(in, out, conf, false);
            } finally {
                in.close();
            }
        }
    }
public void doActionOn(TomcatProject prj) throws Exception {
        String path = TomcatLauncherPlugin.getDefault().getManagerAppUrl();
        try {
            path += "/reload?path=" + prj.getWebPath();
            URL url = new URL(path);
            Authenticator.setDefault(new Authenticator() {

                protected PasswordAuthentication getPasswordAuthentication() {
                    String user = TomcatLauncherPlugin.getDefault().getManagerAppUser();
                    String password = TomcatLauncherPlugin.getDefault().getManagerAppPassword();
                    return new PasswordAuthentication(user, password.toCharArray());
                }
            });
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.getContent();
            connection.disconnect();
            Authenticator.setDefault(null);
        } catch (Exception e) {
            throw new Exception("The following url was used : \n" + path + "\n\nCheck manager app settings (username and password)\n\n");
        }
    }
protected void convertInternal(InputStream inputStream, DocumentFormat inputFormat, OutputStream outputStream, DocumentFormat outputFormat) {
        File inputFile = null;
        File outputFile = null;
        try {
            inputFile = File.createTempFile("document", "." + inputFormat.getFileExtension());
            OutputStream inputFileStream = null;
            try {
                inputFileStream = new FileOutputStream(inputFile);
                IOUtils.copy(inputStream, inputFileStream);
            } finally {
                IOUtils.closeQuietly(inputFileStream);
            }
            outputFile = File.createTempFile("document", "." + outputFormat.getFileExtension());
            convert(inputFile, inputFormat, outputFile, outputFormat);
            InputStream outputFileStream = null;
            try {
                outputFileStream = new FileInputStream(outputFile);
                IOUtils.copy(outputFileStream, outputStream);
            } finally {
                IOUtils.closeQuietly(outputFileStream);
            }
        } catch (IOException ioException) {
            throw new OpenOfficeException("conversion failed", ioException);
        } finally {
            if (inputFile != null) {
                inputFile.delete();
            }
            if (outputFile != null) {
                outputFile.delete();
            }
        }
    }
protected void connect() throws SocketException, IOException, LoginFailException {
        logger.info("Connect to FTP Server " + account.getServer());
        client = new FTPClient();
        client.connect(account.getServer());
        if (client.login(account.getId(), account.getPassword()) == false) {
            logger.info("Fail to login with id=" + account.getId());
            throw new LoginFailException(account.getId(), account.getPassword());
        }
    }
public String control(final String allOptions) throws SQLException {
        connect();
        final Statement stmt = connection.createStatement();
        final ResultSet rst1 = stmt.executeQuery("SELECT versionId FROM versions WHERE version='" + Concrete.version() + "'");
        final long versionId;
        if (rst1.next()) {
            versionId = rst1.getInt(1);
        } else {
            disconnect();
            return "";
        }
        rst1.close();
        final MessageDigest msgDigest;
        try {
            msgDigest = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e1) {
            logger.throwing(SQLExecutionController.class.getSimpleName(), "control", e1);
            disconnect();
            return "";
        }
        msgDigest.update(allOptions.getBytes());
        final ResultSet rst2 = stmt.executeQuery("SELECT configId FROM configs WHERE md5='" + Concrete.md5(msgDigest.digest()) + "'");
        final long configId;
        if (rst2.next()) {
            configId = rst2.getInt(1);
        } else {
            disconnect();
            return "";
        }
        rst2.close();
        final ResultSet rst4 = stmt.executeQuery("SELECT problems.md5 FROM executions " + "LEFT JOIN problems ON executions.problemId = problems.problemId WHERE " + "configId=" + configId + " AND versionId=" + versionId);
        final StringBuilder stb = new StringBuilder();
        while (rst4.next()) {
            stb.append(rst4.getString(1)).append('\n');
        }
        rst4.close();
        stmt.close();
        return stb.toString();
    }
public static String encrypt(String text) {
        final char[] HEX_CHARS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
        String result = "";
        MessageDigest digest = null;
        try {
            digest = MessageDigest.getInstance("MD5");
            digest.update(text.getBytes());
            byte[] hash = digest.digest();
            char buffer[] = new char[hash.length * 2];
            for (int i = 0, x = 0; i < hash.length; i++) {
                buffer[x++] = HEX_CHARS[(hash[i] >>> 4) & 0xf];
                buffer[x++] = HEX_CHARS[hash[i] & 0xf];
            }
            result = new String(buffer);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return result;
    }
public void jsFunction_addFile(ScriptableFile infile) throws IOException {
        if (!infile.jsFunction_exists()) throw new IllegalArgumentException("Cannot add a file that doesn't exists to an archive");
        ZipArchiveEntry entry = new ZipArchiveEntry(infile.getName());
        entry.setSize(infile.jsFunction_getSize());
        out.putArchiveEntry(entry);
        try {
            InputStream inStream = infile.jsFunction_createInputStream();
            IOUtils.copy(inStream, out);
            inStream.close();
        } finally {
            out.closeArchiveEntry();
        }
    }
public static void copy(Context cx, Scriptable thisObj, Object[] args, Function funObj) throws IOException {
        InputStream input = (InputStream) ((NativeJavaObject) args[0]).unwrap();
        OutputStream output = (OutputStream) ((NativeJavaObject) args[1]).unwrap();
        IOUtils.copy(input, output);
    }
protected static File UrlToFile(String urlSt) throws CaughtException {
        try {
            logger.info("copy from url: " + urlSt);
            URL url = new URL(urlSt);
            InputStream input = url.openStream();
            File dir = tempDir;
            File tempFile = new File(tempDir + File.separator + fileName(url));
            logger.info("created: " + tempFile.getAbsolutePath());
            copyFile(tempFile, input);
            return tempFile;
        } catch (IOException e) {
            throw new CaughtException(e, logger);
        }
    }
protected static File UrlToAFile(File target, String urlSt, String fileName) throws CaughtException {
        try {
            logger.info("copy from url: " + urlSt);
            URL url = new URL(urlSt);
            InputStream input = url.openStream();
            File dir = tempDir;
            File tempFile = new File(target, fileName);
            logger.info("created: " + tempFile.getAbsolutePath());
            copyFile(tempFile, input);
            return tempFile;
        } catch (IOException e) {
            throw new CaughtException(e, logger);
        }
    }
protected static File UrlGzipToFile(File dir, String urlSt, String suffix) throws CaughtException {
        try {
            URL url = new URL(urlSt);
            InputStream zipped = url.openStream();
            InputStream unzipped = new GZIPInputStream(zipped);
            File tempFile = File.createTempFile("input", suffix, dir);
            copyFile(tempFile, unzipped);
            return tempFile;
        } catch (IOException e) {
            throw new CaughtException(e, logger);
        }
    }
protected static File UrlGzipToAFile(File dir, String urlSt, String fileName) throws CaughtException {
        try {
            URL url = new URL(urlSt);
            InputStream zipped = url.openStream();
            InputStream unzipped = new GZIPInputStream(zipped);
            File tempFile = new File(dir, fileName);
            copyFile(tempFile, unzipped);
            return tempFile;
        } catch (IOException e) {
            throw new CaughtException(e, logger);
        }
    }
protected boolean copyFile(File sourceFile, File destinationFile) {
        try {
            FileChannel srcChannel = new FileInputStream(sourceFile).getChannel();
            FileChannel dstChannel = new FileOutputStream(destinationFile).getChannel();
            dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
            srcChannel.close();
            dstChannel.close();
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
public void compressImage(BufferedImage bi, OutputStream output, DjatokaEncodeParam params) throws DjatokaException {
        if (params == null) params = new DjatokaEncodeParam();
        if (params.getLevels() == 0) params.setLevels(ImageProcessingUtils.getLevelCount(bi.getWidth(), bi.getHeight()));
        File in = null;
        File out = null;
        try {
            in = IOUtils.createTempTiff(bi);
            out = File.createTempFile("tmp", ".jp2");
            compressImage(in.getAbsolutePath(), out.getAbsolutePath(), params);
            IOUtils.copyStream(new FileInputStream(out), output);
        } catch (IOException e) {
            logger.error(e, e);
            throw new DjatokaException(e);
        } catch (Exception e) {
            logger.error(e, e);
            throw new DjatokaException(e);
        }
        if (in != null) in.delete();
        if (out != null) out.delete();
    }
public void compressImage(InputStream input, String output, DjatokaEncodeParam params) throws DjatokaException {
        if (params == null) params = new DjatokaEncodeParam();
        File inputFile;
        try {
            inputFile = File.createTempFile("tmp", ".tif");
            inputFile.deleteOnExit();
            IOUtils.copyStream(input, new FileOutputStream(inputFile));
            if (params.getLevels() == 0) {
                ImageRecord dim = ImageRecordUtils.getImageDimensions(inputFile.getAbsolutePath());
                params.setLevels(ImageProcessingUtils.getLevelCount(dim.getWidth(), dim.getHeight()));
                dim = null;
            }
        } catch (IOException e) {
            logger.error(e, e);
            throw new DjatokaException(e);
        }
        compressImage(inputFile.getAbsolutePath(), output, params);
        if (inputFile != null) inputFile.delete();
    }
public void compressImage(InputStream input, OutputStream output, DjatokaEncodeParam params) throws DjatokaException {
        if (params == null) params = new DjatokaEncodeParam();
        File inputFile = null;
        try {
            inputFile = File.createTempFile("tmp", ".tif");
            IOUtils.copyStream(input, new FileOutputStream(inputFile));
            if (params.getLevels() == 0) {
                ImageRecord dim = ImageRecordUtils.getImageDimensions(inputFile.getAbsolutePath());
                params.setLevels(ImageProcessingUtils.getLevelCount(dim.getWidth(), dim.getHeight()));
                dim = null;
            }
        } catch (IOException e1) {
            logger.error("Unexpected file format; expecting uncompressed TIFF", e1);
            throw new DjatokaException("Unexpected file format; expecting uncompressed TIFF");
        }
        String out = STDOUT;
        File winOut = null;
        if (isWindows) {
            try {
                winOut = File.createTempFile("pipe_", ".jp2");
            } catch (IOException e) {
                logger.error(e, e);
                throw new DjatokaException(e);
            }
            out = winOut.getAbsolutePath();
        }
        String command = getKduCompressCommand(inputFile.getAbsolutePath(), out, params);
        logger.debug("compressCommand: " + command);
        Runtime rt = Runtime.getRuntime();
        try {
            final Process process = rt.exec(command, envParams, new File(env));
            if (out.equals(STDOUT)) {
                IOUtils.copyStream(process.getInputStream(), output);
            } else if (isWindows) {
                FileInputStream fis = new FileInputStream(out);
                IOUtils.copyStream(fis, output);
                fis.close();
            }
            process.waitFor();
            if (process != null) {
                String errorCheck = null;
                try {
                    errorCheck = new String(IOUtils.getByteArray(process.getErrorStream()));
                } catch (Exception e1) {
                    logger.error(e1, e1);
                }
                process.getInputStream().close();
                process.getOutputStream().close();
                process.getErrorStream().close();
                process.destroy();
                if (errorCheck != null) throw new DjatokaException(errorCheck);
            }
        } catch (IOException e) {
            logger.error(e, e);
            throw new DjatokaException(e);
        } catch (InterruptedException e) {
            logger.error(e, e);
            throw new DjatokaException(e);
        }
        if (inputFile != null) inputFile.delete();
        if (winOut != null) winOut.delete();
    }
public static final String crypt(String password, String salt) throws NoSuchAlgorithmException {
        String magic = "$1$";
        byte finalState[];
        MessageDigest ctx, ctx1;
        long l;
        if (salt.startsWith(magic)) {
            salt = salt.substring(magic.length());
        }
        if (salt.indexOf('$') != -1) {
            salt = salt.substring(0, salt.indexOf('$'));
        }
        if (salt.length() > 8) {
            salt = salt.substring(0, 8);
        }
        ctx = MessageDigest.getInstance("MD5");
        ctx.update(password.getBytes());
        ctx.update(magic.getBytes());
        ctx.update(salt.getBytes());
        ctx1 = MessageDigest.getInstance("MD5");
        ctx1.update(password.getBytes());
        ctx1.update(salt.getBytes());
        ctx1.update(password.getBytes());
        finalState = ctx1.digest();
        for (int pl = password.length(); pl > 0; pl -= 16) {
            for (int i = 0; i < (pl > 16 ? 16 : pl); i++) ctx.update(finalState[i]);
        }
        clearbits(finalState);
        for (int i = password.length(); i != 0; i >>>= 1) {
            if ((i & 1) != 0) {
                ctx.update(finalState[0]);
            } else {
                ctx.update(password.getBytes()[0]);
            }
        }
        finalState = ctx.digest();
        for (int i = 0; i < 1000; i++) {
            ctx1 = MessageDigest.getInstance("MD5");
            if ((i & 1) != 0) {
                ctx1.update(password.getBytes());
            } else {
                for (int c = 0; c < 16; c++) ctx1.update(finalState[c]);
            }
            if ((i % 3) != 0) {
                ctx1.update(salt.getBytes());
            }
            if ((i % 7) != 0) {
                ctx1.update(password.getBytes());
            }
            if ((i & 1) != 0) {
                for (int c = 0; c < 16; c++) ctx1.update(finalState[c]);
            } else {
                ctx1.update(password.getBytes());
            }
            finalState = ctx1.digest();
        }
        StringBuffer result = new StringBuffer();
        result.append(magic);
        result.append(salt);
        result.append("$");
        l = (bytes2u(finalState[0]) << 16) | (bytes2u(finalState[6]) << 8) | bytes2u(finalState[12]);
        result.append(to64(l, 4));
        l = (bytes2u(finalState[1]) << 16) | (bytes2u(finalState[7]) << 8) | bytes2u(finalState[13]);
        result.append(to64(l, 4));
        l = (bytes2u(finalState[2]) << 16) | (bytes2u(finalState[8]) << 8) | bytes2u(finalState[14]);
        result.append(to64(l, 4));
        l = (bytes2u(finalState[3]) << 16) | (bytes2u(finalState[9]) << 8) | bytes2u(finalState[15]);
        result.append(to64(l, 4));
        l = (bytes2u(finalState[4]) << 16) | (bytes2u(finalState[10]) << 8) | bytes2u(finalState[5]);
        result.append(to64(l, 4));
        l = bytes2u(finalState[11]);
        result.append(to64(l, 2));
        clearbits(finalState);
        return result.toString();
    }
protected void doSetInput(IEditorInput input, IProgressMonitor monitor) throws CoreException {
        IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
        IFileFormat format = null;
        Object source = null;
        InputStream in = null;
        try {
            IPath path;
            if (input instanceof IStorageEditorInput) {
                IStorage s = ((IStorageEditorInput) input).getStorage();
                in = s.getContents();
                if (s instanceof IFile) {
                    IFile file = (IFile) s;
                    path = file.getRawLocation();
                    if (root.exists(path)) {
                        path = root.getLocation().append(path);
                    }
                    source = path.toFile();
                }
            } else if (input instanceof IPathEditorInput) {
                path = ((IPathEditorInput) input).getPath();
                source = path.toFile();
            } else if (input instanceof IURIEditorInput) {
                URI uri = ((IURIEditorInput) input).getURI();
                if (URIUtil.isFileURI(uri)) {
                    source = URIUtil.toFile(uri);
                } else {
                    URL url = URIUtil.toURL(uri);
                    in = url.openStream();
                }
            }
            if (source == null) {
                if (!in.markSupported()) {
                    in = new BufferedInputStream(in);
                }
                in.mark(10);
                source = in;
            }
            IContentDescription cd = Platform.getContentTypeManager().getDescriptionFor(in, input.getName(), new QualifiedName[] { ImageCore.VALID_FORMATS });
            if (in != null) {
                in.reset();
            }
            Collection<?> valid = (Collection<?>) cd.getProperty(ImageCore.VALID_FORMATS);
            if (valid.isEmpty()) throw new CoreException(new Status(Status.ERROR, ImageUI.PLUGIN_ID, "Unsupported file format."));
            ImageInputStream stream = ImageIO.createImageInputStream(source);
            format = (IFileFormat) valid.iterator().next();
            IDocument document = format.decode(stream, monitor);
            setDocument(document);
        } catch (IOException e) {
            Status status = new Status(Status.ERROR, ImageUI.PLUGIN_ID, "IO Error", e);
            throw new CoreException(status);
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                }
            }
        }
        super.setInput(input);
    }
public static void copyFile(File oldFile, File newFile) throws Exception {
        newFile.getParentFile().mkdirs();
        newFile.createNewFile();
        FileChannel srcChannel = new FileInputStream(oldFile).getChannel();
        FileChannel dstChannel = new FileOutputStream(newFile).getChannel();
        dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
        srcChannel.close();
        dstChannel.close();
    }
private String getMD5Password(String plainText) throws NoSuchAlgorithmException {
        MessageDigest mdAlgorithm;
        StringBuffer hexString = new StringBuffer();
        String md5Password = "";
        mdAlgorithm = MessageDigest.getInstance("MD5");
        mdAlgorithm.update(plainText.getBytes());
        byte[] digest = mdAlgorithm.digest();
        for (int i = 0; i < digest.length; i++) {
            plainText = Integer.toHexString(0xFF & digest[i]);
            if (plainText.length() < 2) {
                plainText = "0" + plainText;
            }
            hexString.append(plainText);
        }
        md5Password = hexString.toString();
        return md5Password;
    }
public boolean loadResource(String resourcePath) {
        try {
            URL url = Thread.currentThread().getContextClassLoader().getResource(resourcePath);
            if (url == null) {
                logger.error("Cannot find the resource named: '" + resourcePath + "'. Failed to load the keyword list.");
                return false;
            }
            InputStreamReader isr = new InputStreamReader(url.openStream());
            BufferedReader br = new BufferedReader(isr);
            String ligne = br.readLine();
            while (ligne != null) {
                if (!contains(ligne.toUpperCase())) {
                    addLast(ligne.toUpperCase());
                }
                ligne = br.readLine();
            }
            return true;
        } catch (IOException ioe) {
            logger.log(Level.ERROR, "Cannot load default SQL keywords file.", ioe);
        }
        return false;
    }
private String jarDiagnostics(Throwable throwable, File[] files) throws IOException {
        File home = new File(System.getProperty("user.home"));
        File jar_file = File.createTempFile("nuages-diagnostic.", ".jar", home);
        FileOutputStream fos = new FileOutputStream(jar_file);
        JarOutputStream jos = new JarOutputStream(fos);
        ZipEntry ze = new ZipEntry("Exception");
        jos.putNextEntry(ze);
        PrintStream ps = new PrintStream(jos);
        throwable.printStackTrace(ps);
        for (File file : files) if ((file != null) && file.exists()) {
            ze = new ZipEntry(file.getName());
            jos.putNextEntry(ze);
            byte[] buffer = new byte[65536];
            FileInputStream fis = new FileInputStream(file);
            int len;
            while ((len = fis.read(buffer)) > 0) jos.write(buffer, 0, len);
            fis.close();
        }
        jos.close();
        return jar_file.getPath();
    }
public static void copyFile(File src, File dst) throws ResourceNotFoundException, ParseErrorException, Exception {
        if (src.getAbsolutePath().endsWith(".vm")) {
            copyVMFile(src, dst.getAbsolutePath().substring(0, dst.getAbsolutePath().lastIndexOf(".vm")));
        } else {
            FileInputStream fIn;
            FileOutputStream fOut;
            FileChannel fIChan, fOChan;
            long fSize;
            MappedByteBuffer mBuf;
            fIn = new FileInputStream(src);
            fOut = new FileOutputStream(dst);
            fIChan = fIn.getChannel();
            fOChan = fOut.getChannel();
            fSize = fIChan.size();
            mBuf = fIChan.map(FileChannel.MapMode.READ_ONLY, 0, fSize);
            fOChan.write(mBuf);
            fIChan.close();
            fIn.close();
            fOChan.close();
            fOut.close();
        }
    }