semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static void uploadFile(String localPath, String hostname, String username, String password, String remotePath) {
        FTPClient ftpClient = new FTPClient();
        try {
            ftpClient.connect(hostname);
            int reply = ftpClient.getReplyCode();
            boolean success = false;
            if (FTPReply.isPositiveCompletion(reply)) {
                success = ftpClient.login(username, password);
                if (!success) {
                    Output.error("Failed to login with username/password " + username + "/" + password);
                    return;
                }
                ftpClient.enterLocalPassiveMode();
                ftpClient.setFileType(FTP.ASCII_FILE_TYPE);
            }
            FileInputStream in = new FileInputStream(localPath);
            boolean result = ftpClient.storeFile(remotePath, in);
            if (!result) {
                Output.error("Logged in but failed to upload " + localPath + " to " + remotePath + "\nPerhaps one of the paths was wrong.");
            }
            in.close();
            ftpClient.disconnect();
        } catch (IOException ioe) {
            Output.error("Error ftp'ing using " + "\nlocalPath: " + localPath + "\nhostname: " + hostname + "\nusername: " + username + "\npassword: " + password + "\nremotePath: " + remotePath, ioe);
        }
    }
private void loadProperties() {
        if (properties == null) {
            properties = new Properties();
            try {
                URL url = getClass().getResource(propsFile);
                if (url != null) properties.load(url.openStream());
            } catch (IOException ioe) {
                ioe.printStackTrace();
            }
        }
    }
@Override
    protected final void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        if (beforeServingFile(req, resp)) {
            String pathInfo = req.getPathInfo();
            Validate.notNull(pathInfo, "the path info is null -> the sevlet should be mapped with /<mapping>/*");
            String resurouce = pathInfo.substring(1);
            if (log.isDebugEnabled()) {
                log.debug("resource to expose: " + resurouce);
            }
            String extension = resurouce.substring(resurouce.lastIndexOf('.') + 1);
            MimeType mimeType = MimeTypeRegistry.getByExtension(extension);
            Validate.notNull(mimeType, "no mimetype found for extension: " + extension);
            if (log.isDebugEnabled()) {
                log.debug("the mime type to set: " + mimeType.getMimeType());
            }
            File f = new File(mappedFolder, resurouce);
            Validate.isTrue(f.exists(), "file: " + f + " does not exist");
            Validate.isTrue(f.canRead(), "can not read the file: " + f);
            if (log.isDebugEnabled()) {
                log.debug("exposing the file: " + f);
            }
            resp.setContentType(mimeType.getMimeType());
            FileInputStream fis = new FileInputStream(f);
            ServletOutputStream os = resp.getOutputStream();
            IOUtils.copy(fis, os);
            os.flush();
            IOUtils.closeQuietly(fis);
            IOUtils.closeQuietly(os);
        }
    }
private void refreshCacheFile(RepositoryFile file, File cacheFile) throws FileNotFoundException, IOException {
        FileOutputStream fos = new FileOutputStream(cacheFile);
        InputStream is = file.getInputStream();
        int count = IOUtils.copy(is, fos);
        logger.debug("===========================================================> wrote bytes to cache " + count);
        fos.flush();
        IOUtils.closeQuietly(fos);
        IOUtils.closeQuietly(file.getInputStream());
    }
protected InputStream[] getInputStreams(List<URL> files) throws ResourceException {
        InputStream[] result = new InputStream[files.size()];
        int i = 0;
        try {
            for (URL url : files) {
                result[i++] = url.openStream();
            }
        } catch (IOException e) {
            for (int j = 0; j < i; j++) {
                try {
                    if (UtilLog.LOG.isDebugEnabled()) {
                        UtilLog.LOG.debug("Closing " + files.get(j));
                    }
                    result[j].close();
                } catch (IOException e1) {
                    if (UtilLog.LOG.isDebugEnabled()) {
                        UtilLog.LOG.debug(e1.getMessage(), e1);
                    }
                }
            }
            if (UtilLog.LOG.isDebugEnabled()) {
                UtilLog.LOG.debug(e.getMessage(), e);
            }
            throw new ResourceException(e);
        }
        return result;
    }
private void copy(File sourceFile, File destinationFile) {
        try {
            FileChannel in = new FileInputStream(sourceFile).getChannel();
            FileChannel out = new FileOutputStream(destinationFile).getChannel();
            try {
                in.transferTo(0, in.size(), out);
                in.close();
                out.close();
            } catch (IOException e) {
                GTLogger.getInstance().error(e);
            }
        } catch (FileNotFoundException e) {
            GTLogger.getInstance().error(e);
        }
    }
public boolean backup() {
        try {
            File sd = Environment.getExternalStorageDirectory();
            File data = Environment.getDataDirectory();
            if (sd.canWrite()) {
                String currentDBPath = "/data/android.bluebox/databases/bluebox.db";
                String backupDBPath = "/Android/bluebox.bak";
                File currentDB = new File(data, currentDBPath);
                File backupDB = new File(sd, backupDBPath);
                if (currentDB.exists()) {
                    FileChannel src = new FileInputStream(currentDB).getChannel();
                    FileChannel dst = new FileOutputStream(backupDB).getChannel();
                    dst.transferFrom(src, 0, src.size());
                    src.close();
                    dst.close();
                    return true;
                }
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;
    }
public boolean restore() {
        try {
            File sd = Environment.getExternalStorageDirectory();
            File data = Environment.getDataDirectory();
            if (sd.canWrite()) {
                String currentDBPath = "/Android/bluebox.bak";
                String backupDBPath = "/data/android.bluebox/databases/bluebox.db";
                File currentDB = new File(sd, currentDBPath);
                File backupDB = new File(data, backupDBPath);
                if (currentDB.exists()) {
                    FileChannel src = new FileInputStream(currentDB).getChannel();
                    FileChannel dst = new FileOutputStream(backupDB).getChannel();
                    dst.transferFrom(src, 0, src.size());
                    src.close();
                    dst.close();
                    return true;
                }
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;
    }
@Override
    public void run() {
        try {
            FTPClient ftp = new FTPClient();
            try {
                ftp.connect("localhost", 21);
                ftp.login("ftpuser", "ftpuser123");
                System.out.println("Current: " + ftp.printWorkingDirectory());
                System.out.println("Dir status: " + ftp.makeDirectory(DIR));
                ftp.changeWorkingDirectory(DIR);
                System.out.println("File status: " + ftp.storeFile(FILE_PREFIX + this.getName(), getByteInputStream()));
            } finally {
                ftp.disconnect();
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
public static void copyFile(File source, File dest) throws Exception {
        FileInputStream fis = new FileInputStream(source);
        try {
            FileOutputStream fos = new FileOutputStream(dest);
            try {
                int read = fis.read();
                while (read != -1) {
                    fos.write(read);
                    read = fis.read();
                }
            } finally {
                fos.close();
            }
        } finally {
            fis.close();
        }
    }
public void init() {
        String filename = getParameter("filename");
        if (filename == null) {
            Error("Illegal filename");
            return;
        }
        Dimension dim = DEFAULT_SIZE;
        try {
            int w = Integer.parseInt(getParameter("width"));
            int h = Integer.parseInt(getParameter("height"));
            dim = new Dimension(w, h);
        } catch (Exception e) {
        }
        InputStream in;
        try {
            File ff = new File(filename);
            in = new FileInputStream(ff);
        } catch (Exception ignore) {
            try {
                URL url = new URL(filename);
                in = url.openStream();
            } catch (Exception e) {
                Error("Graph viewer: Failed to open: " + filename + "\n" + e);
                return;
            }
        }
        getContentPane().add(getWindow(in));
        resize(dim);
        repaint();
    }
public void parseFile(String filespec, URL documentBase) {
        DataInputStream in = null;
        if (filespec == null || filespec.length() == 0) {
            in = new DataInputStream(System.in);
        } else {
            try {
                URL url = null;
                if (documentBase == null && _documentBase != null) {
                    documentBase = _documentBase;
                }
                if (documentBase == null) {
                    url = new URL(filespec);
                } else {
                    try {
                        url = new URL(documentBase, filespec);
                    } catch (NullPointerException e) {
                        url = new URL(filespec);
                    }
                }
                in = new DataInputStream(url.openStream());
            } catch (MalformedURLException e) {
                try {
                    in = new DataInputStream(new FileInputStream(filespec));
                } catch (FileNotFoundException me) {
                    _errorMsg = new String[2];
                    _errorMsg[0] = "File not found: " + filespec;
                    _errorMsg[1] = me.getMessage();
                    return;
                } catch (SecurityException me) {
                    _errorMsg = new String[2];
                    _errorMsg[0] = "Security Exception: " + filespec;
                    _errorMsg[1] = me.getMessage();
                    return;
                }
            } catch (IOException ioe) {
                _errorMsg = new String[3];
                _errorMsg[0] = "Failure opening URL: ";
                _errorMsg[1] = " " + filespec;
                _errorMsg[2] = ioe.getMessage();
                return;
            }
        }
        try {
            BufferedReader din = new BufferedReader(new InputStreamReader(in));
            String line = din.readLine();
            while (line != null) {
                _parseLine(line);
                line = din.readLine();
            }
        } catch (MalformedURLException e) {
            _errorMsg = new String[2];
            _errorMsg[0] = "Malformed URL: " + filespec;
            _errorMsg[1] = e.getMessage();
            return;
        } catch (IOException e) {
            _errorMsg = new String[2];
            _errorMsg[0] = "Failure reading data: " + filespec;
            _errorMsg[1] = e.getMessage();
            _errorMsg[1] = e.getMessage();
        } finally {
            try {
                in.close();
            } catch (IOException me) {
            }
        }
    }
public boolean parseResults(URL url, String analysis_type, CurationI curation, Date analysis_date, String regexp) throws OutputMalFormatException {
        boolean parsed = false;
        try {
            InputStream data_stream = url.openStream();
            parsed = parseResults(data_stream, analysis_type, curation, analysis_date, regexp);
        } catch (OutputMalFormatException ex) {
            throw new OutputMalFormatException(ex.getMessage(), ex);
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
        return parsed;
    }
private void getRandomGUID(boolean secure) {
        MessageDigest md5 = null;
        StringBuffer sbValueBeforeMD5 = new StringBuffer();
        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            System.out.println("Error: " + e);
        }
        try {
            long time = System.currentTimeMillis();
            long rand = 0L;
            if (secure) rand = mySecureRand.nextLong(); else rand = myRand.nextLong();
            sbValueBeforeMD5.append(s_id);
            sbValueBeforeMD5.append(":");
            sbValueBeforeMD5.append(Long.toString(time));
            sbValueBeforeMD5.append(":");
            sbValueBeforeMD5.append(Long.toString(rand));
            valueBeforeMD5 = sbValueBeforeMD5.toString();
            md5.update(valueBeforeMD5.getBytes());
            byte array[] = md5.digest();
            StringBuffer sb = new StringBuffer();
            for (int j = 0; j < array.length; j++) {
                int b = array[j] & 0xff;
                if (b < 16) sb.append('0');
                sb.append(Integer.toHexString(b));
            }
            valueAfterMD5 = sb.toString();
        } catch (Exception e) {
            System.out.println("Error:" + e);
        }
    }
private void loadServers() {
        try {
            URL url = new URL(VirtualDeckConfig.SERVERS_URL);
            cmbServer.addItem("Local");
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String str;
            if (in.readLine().equals("[list]")) {
                while ((str = in.readLine()) != null) {
                    String[] host_line = str.split(";");
                    Host h = new Host();
                    h.setIp(host_line[0]);
                    h.setPort(Integer.parseInt(host_line[1]));
                    h.setName(host_line[2]);
                    getServers().add(h);
                    cmbServer.addItem(h.getName());
                }
            }
            in.close();
        } catch (MalformedURLException e) {
        } catch (IOException e) {
        }
    }
public static String encodePassword(String _originalPassword) {
        MessageDigest md = null;
        String encodedPassword = null;
        try {
            md = MessageDigest.getInstance("SHA-1");
            md.update(_originalPassword.getBytes("UTF-8"));
            encodedPassword = (new BASE64Encoder()).encode(md.digest());
        } catch (NoSuchAlgorithmException _e) {
            _e.printStackTrace();
        } catch (UnsupportedEncodingException _e) {
            _e.printStackTrace();
        }
        return encodedPassword;
    }
public String login(String nUsuario, String contrasena) {
        String responce = "";
        String request = conf.Conf.login;
        OutputStreamWriter wr = null;
        BufferedReader rd = null;
        try {
            URL url = new URL(request);
            URLConnection conn = url.openConnection();
            conn.setDoOutput(true);
            wr = new OutputStreamWriter(conn.getOutputStream());
            wr.write("nUsuario=" + nUsuario + "&contrasena=" + contrasena);
            wr.flush();
            rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String line;
            while ((line = rd.readLine()) != null) {
                responce += line;
            }
        } catch (Exception e) {
        }
        return responce;
    }
public String buscarArchivos(String nUsuario) {
        String responce = "";
        String request = conf.Conf.buscarArchivo;
        OutputStreamWriter wr = null;
        BufferedReader rd = null;
        try {
            URL url = new URL(request);
            URLConnection conn = url.openConnection();
            conn.setDoOutput(true);
            wr = new OutputStreamWriter(conn.getOutputStream());
            wr.write("nUsuario=" + nUsuario);
            wr.flush();
            rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String line;
            while ((line = rd.readLine()) != null) {
                responce += line;
            }
        } catch (Exception e) {
        }
        return responce;
    }
public String descargarArchivo(String miArchivo, String nUsuario) {
        try {
            URL url = new URL(conf.Conf.descarga + nUsuario + "/" + miArchivo);
            URLConnection urlCon = url.openConnection();
            System.out.println(urlCon.getContentType());
            InputStream is = urlCon.getInputStream();
            FileOutputStream fos = new FileOutputStream("D:/" + miArchivo);
            byte[] array = new byte[1000];
            int leido = is.read(array);
            while (leido > 0) {
                fos.write(array, 0, leido);
                leido = is.read(array);
            }
            is.close();
            fos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "llego";
    }
public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) throws IllegalAccessException, InstantiationException, IOException {
            String bundleName = toBundleName(baseName, locale);
            String resourceName = toResourceName(bundleName, "properties");
            ResourceBundle bundle = null;
            InputStream stream = null;
            if (reload) {
                URL url = loader.getResource(resourceName);
                if (url != null) {
                    URLConnection connection = url.openConnection();
                    if (connection != null) {
                        connection.setUseCaches(false);
                        stream = connection.getInputStream();
                    }
                }
            } else {
                stream = loader.getResourceAsStream(resourceName);
            }
            if (stream != null) {
                try {
                    bundle = new PropertyResourceBundle(new InputStreamReader(stream, "UTF-8"));
                } finally {
                    stream.close();
                }
            }
            return bundle;
        }
public int run(String[] args) throws Exception {
        if (args.length < 2) {
            System.err.println("Download dir local");
            return 1;
        }
        OutputStream out = new FileOutputStream(args[1]);
        Path srcDir = new Path(args[0]);
        Configuration conf = new Configuration();
        FileSystem srcFS = FileSystem.get(conf);
        if (!srcFS.getFileStatus(srcDir).isDirectory()) {
            System.err.println(args[0] + " is not a directory.");
            return 1;
        }
        try {
            FileStatus contents[] = srcFS.listStatus(srcDir);
            for (int i = 0; i < contents.length; i++) {
                if (contents[i].isFile()) {
                    System.err.println(contents[i].getPath());
                    InputStream in = srcFS.open(contents[i].getPath());
                    try {
                        IOUtils.copyBytes(in, out, conf, false);
                    } finally {
                        in.close();
                    }
                }
            }
        } finally {
            out.close();
        }
        return 0;
    }
public InputStream openAsStream() throws IOException {
        ClassLoader cl = _preferredClassLoader;
        if (cl == null) {
            cl = Thread.currentThread().getContextClassLoader();
        }
        final URL url = (cl == null) ? null : cl.getResource(_path);
        return (url == null) ? null : url.openStream();
    }
public void install(Session session) throws Exception {
        String cfgPath = ConfigurationFactory.getConfigSonInstance().getConfigurationPath();
        File setupKson = new File(cfgPath, "setup.kson");
        InputStream is = null;
        if (setupKson.exists()) {
            log.debug("Reagind kson from " + setupKson.getAbsolutePath());
            is = new FileInputStream(setupKson);
        } else {
            String ksonCp = "/org/chon/cms/core/setup/setup.kson";
            is = Setup.class.getResourceAsStream(ksonCp);
            log.info("Creating initial setup.kson in " + setupKson.getAbsolutePath());
            IOUtils.copy(is, new FileOutputStream(setupKson));
            is = new FileInputStream(setupKson);
        }
        BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
        List<String> lines = new ArrayList<String>();
        while (true) {
            String line = br.readLine();
            if (line == null) break;
            lines.add(line);
        }
        List<NodeCreation> ncList = readKSon(lines.toArray(new String[lines.size()]));
        for (NodeCreation nc : ncList) {
            try {
                createNode(session, nc);
            } catch (Exception e) {
                System.err.println("error crating node " + nc.path + " -> " + e.getMessage());
            }
        }
        session.save();
    }
public byte[] getXQueryForWorkflow(String workflowURI, Log4JLogger log) throws MalformedURLException, IOException, InstantiationException, IllegalAccessException, ClassNotFoundException {
        if (workflowURI == null) {
            throw new XQGeneratorException("Null workflow URI");
        }
        URL url = new URL(workflowURI);
        URLConnection urlconn = url.openConnection();
        urlconn.setAllowUserInteraction(false);
        urlconn.setDoInput(true);
        urlconn.setDoOutput(false);
        urlconn.setUseCaches(true);
        urlconn.connect();
        InputStream is = urlconn.getInputStream();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        TavXQueryGenerator generator = (TavXQueryGenerator) Class.forName(generatorClass).newInstance();
        generator.setLogger(log);
        generator.setInputStream(is);
        generator.setOutputStream(baos);
        generator.generateXQuery();
        is.close();
        return baos.toByteArray();
    }
public byte[] loadClassFirst(final String className) {
        if (className.equals("com.sun.sgs.impl.kernel.AppKernelAppContext")) {
            final URL url = Thread.currentThread().getContextClassLoader().getResource("com/sun/sgs/impl/kernel/AppKernelAppContext.0.9.5.1.class.bin");
            if (url != null) {
                try {
                    return StreamUtil.read(url.openStream());
                } catch (IOException e) {
                }
            }
            throw new IllegalStateException("Unable to load AppKernelAppContext.0.9.5.1.class.bin");
        }
        return null;
    }
public int read(String name) {
        status = STATUS_OK;
        try {
            name = name.trim();
            if (name.indexOf("://") > 0) {
                URL url = new URL(name);
                in = new BufferedInputStream(url.openStream());
            } else {
                in = new BufferedInputStream(new FileInputStream(name));
            }
            status = read(in);
        } catch (IOException e) {
            status = STATUS_OPEN_ERROR;
        }
        return status;
    }