semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private LoadReturnCode loadChild(Map<Key, ValueItem> map, String fileOrUrl, LoadReturnCode defaultResult) throws IOException {
        try {
            URL childurl = getAsUrl(fileOrUrl);
            if (childurl == null) return defaultResult;
            InputStream childStream = childurl.openStream();
            fileOrUrl = childurl.toString();
            LinkedProperties child = new LinkedProperties();
            child.initFromParent(this);
            child.setFilename(fileOrUrl);
            int p = fileOrUrl.lastIndexOf('/');
            setLoadPath((p < 0) ? null : fileOrUrl.substring(0, p));
            Map<Key, ValueItem> childMap = new HashMap<Key, ValueItem>(map);
            removeLocalKeys(childMap);
            @SuppressWarnings("unused") LoadReturnCode childresult = child.onLoad(childMap, childStream);
            try {
                if (childStream != null) childStream.close();
            } catch (IOException ioex) {
            }
            childStream = null;
            map.putAll(childMap);
            return resolveMap(map);
        } catch (IOException ioe) {
            System.out.println(getFilename() + ": error loading childfile " + fileOrUrl);
            throw ioe;
        }
    }
public static GoogleResponse getElevation(String lat, String lon) throws IOException {
        String url = "http://maps.google.com/maps/api/elevation/xml?locations=";
        url = url + String.valueOf(lat);
        url = url + ",";
        url = url + String.valueOf(lon);
        url = url + "&sensor=false";
        BufferedReader in = new BufferedReader(new InputStreamReader(new URL(url).openStream()));
        String line;
        GoogleResponse googleResponse = new GoogleResponse();
        googleResponse.lat = Double.valueOf(lat);
        googleResponse.lon = Double.valueOf(lon);
        while ((line = in.readLine()) != null) {
            line = line.trim();
            if (line.startsWith("<status>")) {
                line = line.replace("<status>", "");
                line = line.replace("</status>", "");
                googleResponse.status = line;
                if (!line.toLowerCase().equals("ok")) return googleResponse;
            } else if (line.startsWith("<elevation>")) {
                line = line.replace("<elevation>", "");
                line = line.replace("</elevation>", "");
                googleResponse.elevation = Double.valueOf(line);
                return googleResponse;
            }
        }
        return googleResponse;
    }
public static void main(String[] args) throws IOException {
        FileOutputStream f = new FileOutputStream("test.zip");
        CheckedOutputStream csum = new CheckedOutputStream(f, new Adler32());
        ZipOutputStream zos = new ZipOutputStream(csum);
        BufferedOutputStream out = new BufferedOutputStream(zos);
        zos.setComment("A test of Java Zipping");
        for (String arg : args) {
            print("Writing file " + arg);
            BufferedReader in = new BufferedReader(new FileReader(arg));
            zos.putNextEntry(new ZipEntry(arg));
            int c;
            while ((c = in.read()) != -1) out.write(c);
            in.close();
            out.flush();
        }
        out.close();
        print("Checksum: " + csum.getChecksum().getValue());
        print("Reading file");
        FileInputStream fi = new FileInputStream("test.zip");
        CheckedInputStream csumi = new CheckedInputStream(fi, new Adler32());
        ZipInputStream in2 = new ZipInputStream(csumi);
        BufferedInputStream bis = new BufferedInputStream(in2);
        ZipEntry ze;
        while ((ze = in2.getNextEntry()) != null) {
            print("Reading file " + ze);
            int x;
            while ((x = bis.read()) != -1) System.out.write(x);
        }
        if (args.length == 1) print("Checksum: " + csumi.getChecksum().getValue());
        bis.close();
        ZipFile zf = new ZipFile("test.zip");
        Enumeration e = zf.entries();
        while (e.hasMoreElements()) {
            ZipEntry ze2 = (ZipEntry) e.nextElement();
            print("File: " + ze2);
        }
    }
public static String getStringResponse(String urlString) throws Exception {
        URL url = new URL(urlString);
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        String inputLine;
        StringBuilder buffer = new StringBuilder();
        while ((inputLine = in.readLine()) != null) {
            buffer.append(inputLine);
        }
        in.close();
        return buffer.toString();
    }
public String hasheMotDePasse(String mdp) {
        MessageDigest sha = null;
        try {
            sha = MessageDigest.getInstance("SHA-1");
        } catch (NoSuchAlgorithmException ex) {
        }
        sha.reset();
        sha.update(mdp.getBytes());
        byte[] digest = sha.digest();
        String pass = new String(Base64.encode(digest));
        pass = "{SHA}" + pass;
        return pass;
    }
public Document parse(InputSource is) throws SAXException, IOException {
        LSInput input = ls.createLSInput();
        String systemId = is.getSystemId();
        InputStream in = is.getByteStream();
        if (in != null) {
            input.setByteStream(in);
        } else {
            Reader reader = is.getCharacterStream();
            if (reader != null) {
                input.setCharacterStream(reader);
            } else {
                URL url = new URL(systemId);
                input.setByteStream(url.openStream());
            }
        }
        input.setPublicId(is.getPublicId());
        input.setSystemId(systemId);
        input.setEncoding(is.getEncoding());
        return parser.parse(input);
    }
public void write(File file) throws Exception {
        if (isInMemory()) {
            FileOutputStream fout = null;
            try {
                fout = new FileOutputStream(file);
                fout.write(get());
            } finally {
                if (fout != null) {
                    fout.close();
                }
            }
        } else {
            File outputFile = getStoreLocation();
            if (outputFile != null) {
                size = outputFile.length();
                if (!outputFile.renameTo(file)) {
                    BufferedInputStream in = null;
                    BufferedOutputStream out = null;
                    try {
                        in = new BufferedInputStream(new FileInputStream(outputFile));
                        out = new BufferedOutputStream(new FileOutputStream(file));
                        IOUtils.copy(in, out);
                    } finally {
                        if (in != null) {
                            try {
                                in.close();
                            } catch (IOException e) {
                            }
                        }
                        if (out != null) {
                            try {
                                out.close();
                            } catch (IOException e) {
                            }
                        }
                    }
                }
            } else {
                throw new FileUploadException("Cannot write uploaded file to disk!");
            }
        }
    }
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
        in.defaultReadObject();
        OutputStream output = getOutputStream();
        if (cachedContent != null) {
            output.write(cachedContent);
        } else {
            FileInputStream input = new FileInputStream(dfosFile);
            IOUtils.copy(input, output);
            dfosFile.delete();
            dfosFile = null;
        }
        output.close();
        cachedContent = null;
    }
public boolean validateLogin(String username, String password) {
        boolean user_exists = false;
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(password.getBytes());
            BigInteger hash = new BigInteger(1, md5.digest());
            String password_hash = hash.toString(16);
            statement = connect.prepareStatement("SELECT id from toepen.users WHERE username = ? AND password = ?");
            statement.setString(1, username);
            statement.setString(2, password_hash);
            resultSet = statement.executeQuery();
            while (resultSet.next()) {
                user_exists = true;
            }
        } catch (Exception ex) {
            System.out.println(ex);
        } finally {
            close();
            return user_exists;
        }
    }
public boolean createUser(String username, String password, String name) throws Exception {
        boolean user_created = false;
        try {
            statement = connect.prepareStatement("SELECT COUNT(*) from toepen.users WHERE username = ? LIMIT 1");
            statement.setString(1, username);
            resultSet = statement.executeQuery();
            resultSet.next();
            if (resultSet.getInt(1) == 0) {
                MessageDigest md5 = MessageDigest.getInstance("MD5");
                md5.update(password.getBytes());
                BigInteger hash = new BigInteger(1, md5.digest());
                String password_hash = hash.toString(16);
                long ctime = System.currentTimeMillis() / 1000;
                statement = connect.prepareStatement("INSERT INTO toepen.users " + "(username, password, name, ctime) " + "VALUES (?, ?, ?, ?)");
                statement.setString(1, username);
                statement.setString(2, password_hash);
                statement.setString(3, name);
                statement.setLong(4, ctime);
                if (statement.executeUpdate() > 0) {
                    user_created = true;
                }
            }
        } catch (Exception ex) {
            System.out.println(ex);
        } finally {
            close();
            return user_created;
        }
    }
public static byte[] read(URL url) throws IOException {
        byte[] bytes;
        InputStream is = null;
        try {
            is = url.openStream();
            bytes = readAllBytes(is);
        } finally {
            if (is != null) {
                is.close();
            }
        }
        return bytes;
    }
public static String CopyFile(String sourcefile, String destfile) throws FileNotFoundException, IOException {
        int last = destfile.lastIndexOf('/');
        if (last < 0) {
            DrxWriteError("CopyFile", "Destination filepath " + destfile + " doesn't contain /");
            throw new java.io.FileNotFoundException(destfile);
        }
        String parent = destfile.substring(0, last);
        if (parent.length() > 0) {
            File f = new File(parent);
            if (!f.isDirectory()) {
                if (!f.mkdirs()) {
                    DrxWriteError("CopyFile", "Folder " + parent + " doesn't exist, cannot create");
                }
            }
        }
        FileChannel srcChannel = new FileInputStream(sourcefile).getChannel();
        FileChannel dstChannel = new FileOutputStream(destfile).getChannel();
        dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
        srcChannel.close();
        dstChannel.close();
        return destfile;
    }
public static String gerarDigest(String mensagem) {
        String mensagemCriptografada = null;
        try {
            MessageDigest md = MessageDigest.getInstance("SHA");
            System.out.println("Mensagem original: " + mensagem);
            md.update(mensagem.getBytes());
            byte[] digest = md.digest();
            mensagemCriptografada = converterBytesEmHexa(digest);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return mensagemCriptografada;
    }
private String readCreditsHtml(IApplication app) {
            final URL url = app.getResources().getCreditsURL();
            StringBuffer buf = new StringBuffer(2048);
            if (url != null) {
                try {
                    BufferedReader rdr = new BufferedReader(new InputStreamReader(url.openStream()));
                    try {
                        String line = null;
                        while ((line = rdr.readLine()) != null) {
                            String internationalizedLine = Utilities.replaceI18NSpanLine(line, s_stringMgr);
                            buf.append(internationalizedLine);
                        }
                    } finally {
                        rdr.close();
                    }
                } catch (IOException ex) {
                    String errorMsg = s_stringMgr.getString("AboutBoxDialog.error.creditsfile");
                    s_log.error(errorMsg, ex);
                    buf.append(errorMsg + ": " + ex.toString());
                }
            } else {
                String errorMsg = s_stringMgr.getString("AboutBoxDialog.error.creditsfileurl");
                s_log.error(errorMsg);
                buf.append(errorMsg);
            }
            return buf.toString();
        }
public void load(String filename) throws VisbardException {
        String defaultFilename = VisbardMain.getSettingsDir() + File.separator + DEFAULT_SETTINGS_FILE;
        File defaultFile = new File(defaultFilename);
        InputStream settingsInStreamFromFile = null;
        try {
            sLogger.info("Loading settings from : " + defaultFilename);
            settingsInStreamFromFile = new FileInputStream(defaultFile);
        } catch (FileNotFoundException fnf) {
            sLogger.info("Unable to load custom settings from user's settings directory (" + fnf.getMessage() + "); reverting to default settings");
            try {
                InputStream settingsInStreamFromJar = VisbardMain.class.getClassLoader().getResourceAsStream(filename);
                FileOutputStream settingsOutStream = new FileOutputStream(defaultFile);
                int c;
                while ((c = settingsInStreamFromJar.read()) != -1) settingsOutStream.write(c);
                settingsInStreamFromJar.close();
                settingsOutStream.close();
                settingsInStreamFromFile = new FileInputStream(defaultFile);
            } catch (IOException ioe) {
                sLogger.warn("Unable to copy default settings to user's settings directory (" + ioe.getMessage() + "); using default settings from ViSBARD distribution package");
                settingsInStreamFromFile = VisbardMain.class.getClassLoader().getResourceAsStream(filename);
            }
        }
        this.processSettingsFile(settingsInStreamFromFile, filename);
    }
void run(PseudolocalizerArguments arguments) throws IOException {
        List<String> fileNames = arguments.getFileNames();
        PseudolocalizationPipeline pipeline = arguments.getPipeline();
        if (arguments.isInteractive()) {
            runStdin(pipeline);
            return;
        }
        if (fileNames.size() == 0) {
            MessageCatalog msgCat = FormatRegistry.getMessageCatalog(arguments.getType());
            writeMessages(msgCat, readAndProcessMessages(pipeline, msgCat, System.in), System.out);
            return;
        }
        String suffix = arguments.getVariant();
        if (suffix == null) {
            suffix = "_pseudo";
        } else {
            suffix = "_" + suffix;
        }
        for (String fileName : fileNames) {
            File file = new File(fileName);
            if (!file.exists()) {
                System.err.println("File " + fileName + " not found");
                continue;
            }
            int lastDot = fileName.lastIndexOf('.');
            String extension;
            String outFileName;
            if (lastDot >= 0) {
                extension = fileName.substring(lastDot + 1);
                outFileName = fileName.substring(0, lastDot) + suffix + "." + extension;
            } else {
                extension = "";
                outFileName = fileName + suffix;
            }
            System.out.println("Processing " + fileName + " into " + outFileName);
            String fileType = arguments.getType();
            if (fileType == null) {
                fileType = extension;
            }
            MessageCatalog msgCat = FormatRegistry.getMessageCatalog(fileType);
            InputStream inputStream = new FileInputStream(file);
            List<Message> processedMessages = readAndProcessMessages(pipeline, msgCat, inputStream);
            OutputStream outputStream = new FileOutputStream(new File(outFileName));
            writeMessages(msgCat, processedMessages, outputStream);
        }
    }
public JspBaseTestCase(String name) {
        super(name);
        String propertyFile = "bugbase.properties";
        Properties properties = new Properties();
        setProperties(properties);
        try {
            URL url = this.getClass().getResource("/" + propertyFile);
            if (url != null) {
                InputStream is = url.openStream();
                properties.load(is);
                is.close();
                getLog().debug("Cactus LogService successfully instantiated.");
                getLog().debug("Log4J successfully instantiated.");
            }
        } catch (IOException e) {
            System.err.println("ERROR: cannot load " + propertyFile + "!");
        }
        setDefault("openfuture.bugbase.test.host", "localhost:8080");
        setDefault("openfuture.bugbase.test.context", "bugbase");
        setDefault("openfuture.bugbase.test.userid", "admin");
        setDefault("openfuture.bugbase.test.password", "bugbase");
        setDefault("openfuture.bugbase.test.project", "BugBase Test");
    }
public static void copyFile(final String inFile, final String outFile) {
        FileChannel in = null;
        FileChannel out = null;
        try {
            in = new FileInputStream(inFile).getChannel();
            out = new FileOutputStream(outFile).getChannel();
            in.transferTo(0, in.size(), out);
        } catch (final Exception e) {
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (final Exception e) {
                }
            }
            if (out != null) {
                try {
                    out.close();
                } catch (final Exception e) {
                }
            }
        }
    }
private Component createLicensePane(String propertyKey) {
        if (licesePane == null) {
            String licenseText = "";
            BufferedReader in = null;
            try {
                String filename = "conf/LICENSE.txt";
                java.net.URL url = FileUtil.toURL(filename);
                in = new BufferedReader(new InputStreamReader(url.openStream()));
                String line = null;
                while (true) {
                    line = in.readLine();
                    if (line == null) break;
                    licenseText += line;
                }
            } catch (Exception e) {
                log.error(e);
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (Exception e) {
                    }
                }
            }
            licenseText = StringUtils.replace(licenseText, "<br>", "\n");
            licenseText = StringUtils.replace(licenseText, "<p>", "\n\n");
            StyleContext context = new StyleContext();
            StyledDocument document = new DefaultStyledDocument(context);
            Style style = context.getStyle(StyleContext.DEFAULT_STYLE);
            StyleConstants.setAlignment(style, StyleConstants.ALIGN_CENTER);
            StyleConstants.setSpaceAbove(style, 4);
            StyleConstants.setSpaceBelow(style, 4);
            StyleConstants.setFontSize(style, 14);
            try {
                document.insertString(document.getLength(), licenseText, style);
            } catch (BadLocationException e) {
                log.error(e);
            }
            JTextPane textPane = new JTextPane(document);
            textPane.setEditable(false);
            licesePane = new JScrollPane(textPane);
        }
        return licesePane;
    }
private static String processRequest(String request, HttpMethod method) {
        SimpleClientHttpRequestFactory simpleClientHttpRequestFactory = new SimpleClientHttpRequestFactory();
        URI uri = null;
        try {
            uri = new URI(request);
            ClientHttpRequest clientHttpRequest = simpleClientHttpRequestFactory.createRequest(uri, method);
            ClientHttpResponse response = clientHttpRequest.execute();
            InputStream bodyInputStream = response.getBody();
            String body = org.apache.commons.io.IOUtils.toString(bodyInputStream);
            return body;
        } catch (URISyntaxException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
public String[] getFile() {
        List<String> records = new ArrayList<String>();
        FTPClient ftp = new FTPClient();
        try {
            int reply;
            FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_UNIX);
            ftp.configure(conf);
            ftp.connect(host, port);
            System.out.println("Connected to " + host + ".");
            System.out.print(ftp.getReplyString());
            reply = ftp.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                ftp.disconnect();
                System.err.println("FTP server refused connection.");
            }
            ftp.login(user, password);
            reply = ftp.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                ftp.disconnect();
                System.err.println("FTP server refused login.");
            }
            InputStream is = ftp.retrieveFileStream(remotedir + "/" + remotefile);
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);
            String line = null;
            while ((line = br.readLine()) != null) {
                if (!line.equals("")) {
                    records.add(line);
                }
            }
            br.close();
            isr.close();
            is.close();
            ftp.logout();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (ftp.isConnected()) {
                try {
                    ftp.disconnect();
                } catch (IOException ioe) {
                    ioe.printStackTrace();
                }
            }
        }
        return records.toArray(new String[0]);
    }
public JythonWrapperAction(AActionBO.ActionDTO dto, URL url) throws IOException {
        super(dto);
        InputStream in = url.openStream();
        InputStreamReader rin = new InputStreamReader(in);
        BufferedReader reader = new BufferedReader(rin);
        StringBuffer s = new StringBuffer();
        String str;
        while ((str = reader.readLine()) != null) {
            s.append(str);
            s.append("\n");
        }
        in.close();
        script = s.toString();
    }