semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void seeURLConnection() throws Exception {
        URL url = new URL("http://wantmeet.iptime.org");
        URLConnection uc = url.openConnection();
        BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream()));
        String s = null;
        StringBuffer sb = new StringBuffer();
        while ((s = br.readLine()) != null) {
            sb.append(s);
        }
        br.close();
        log.debug("sb=[" + sb.toString() + "]");
    }
public void url2SaveAsFile(String urlStr, String saveAsFileName) throws Exception {
        URL url = new URL(urlStr);
        URLConnection uc = url.openConnection();
        File f = new File(saveAsFileName);
        if (!f.exists()) {
            FileOutputStream fos = new FileOutputStream(f);
            BufferedInputStream bis = new BufferedInputStream(uc.getInputStream());
            byte[] buffer = new byte[4096];
            int readCount = 0;
            while ((readCount = bis.read(buffer)) != -1) {
                fos.write(buffer, 0, readCount);
            }
            fos.flush();
            fos.close();
            bis.close();
        }
    }
private String[] getPamFiles() throws IOException {
        URL url = WorkflowStructure.class.getResource("/de/ibis/permoto/loganalyzer/pam");
        Set<String> result = new LinkedHashSet<String>(8);
        if (url.getProtocol().equals("jar")) {
            URLConnection con = url.openConnection();
            JarURLConnection jarCon = (JarURLConnection) con;
            JarFile jarFile = jarCon.getJarFile();
            JarEntry jarEntry = jarCon.getJarEntry();
            String rootEntryPath = (jarEntry != null ? jarEntry.getName() : "");
            rootEntryPath = rootEntryPath + "/";
            for (Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements(); ) {
                JarEntry entry = entries.nextElement();
                String entryPath = entry.getName();
                if (entryPath.startsWith(rootEntryPath)) {
                    if (entryPath.endsWith(".pam")) {
                        result.add("/" + entryPath);
                    }
                }
            }
        } else {
            String rootEntryPath = url.getFile();
            File dir = new File(url.getFile());
            File[] dirContents = dir.listFiles();
            for (int i = 0; i < dirContents.length; i++) {
                File content = dirContents[i];
                if (content.getName().endsWith(".pam")) {
                    String relativePath = content.getAbsolutePath().substring(rootEntryPath.length());
                    result.add("/de/ibis/permoto/loganalyzer/pam/" + relativePath.replace(File.separatorChar, '/'));
                }
            }
        }
        return result.toArray(new String[result.size()]);
    }
static void copy(String src, String dest) throws IOException {
        InputStream in = null;
        OutputStream out = null;
        try {
            in = new FileInputStream(src);
            out = new FileOutputStream(dest);
            byte[] buf = new byte[1024];
            int n;
            while ((n = in.read(buf)) > 0) out.write(buf, 0, n);
        } finally {
            if (in != null) in.close();
            if (out != null) out.close();
        }
    }
public void test() throws Exception {
        StringDocument doc = new StringDocument("Test", "UTF-8");
        doc.open();
        try {
            assertEquals("UTF-8", doc.getCharacterEncoding());
            assertEquals("Test", doc.getText());
            InputStream input = doc.getInputStream();
            StringWriter writer = new StringWriter();
            try {
                IOUtils.copy(input, writer, "UTF-8");
            } finally {
                writer.close();
            }
            assertEquals("Test", writer.toString());
        } finally {
            doc.close();
        }
    }
private File unpackZIP(URL url, String dirName) {
        try {
            URLConnection connection = url.openConnection();
            if (connection instanceof JarURLConnection) {
                File destDir = new File(getExtensionsDirectory() + EGEConstants.fS + dirName);
                destDir.mkdirs();
                EGEIOUtils.unzipFile(((JarURLConnection) connection).getJarFile(), destDir);
                return destDir;
            }
        } catch (IOException e) {
            LOGGER.error("Could not unzip jar file.", e);
        }
        return null;
    }
public String sendGetRequest(String endpoint, String requestParameters, String username, String password) throws Exception {
        String result = null;
        if (endpoint.startsWith("http://")) {
            try {
                String urlStr = endpoint;
                if (requestParameters != null && requestParameters.length() > 0) {
                    urlStr += "?" + requestParameters;
                }
                URL url = new URL(urlStr);
                URLConnection conn = url.openConnection();
                String userPassword = username + ":" + password;
                byte[] encoding = org.apache.commons.codec.binary.Base64.encodeBase64(userPassword.getBytes());
                String authStringEnc = new String(encoding);
                log.debug("Base64 encoded auth string: '" + authStringEnc + "'");
                conn.setRequestProperty("Authorization", "Basic " + authStringEnc);
                BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                StringBuffer sb = new StringBuffer();
                String line;
                while ((line = rd.readLine()) != null) {
                    sb.append(line);
                }
                rd.close();
                result = sb.toString();
            } catch (Throwable e) {
                throw new Exception("problem issuing get to URL", e);
            }
        }
        return result;
    }
public void save(InputStream is) throws IOException {
        File dest = Config.getDataFile(getInternalDate(), getPhysMessageID());
        OutputStream os = null;
        try {
            os = new FileOutputStream(dest);
            IOUtils.copyLarge(is, os);
        } finally {
            IOUtils.closeQuietly(os);
            IOUtils.closeQuietly(is);
        }
    }
public static Object getInputStream(String name, boolean showMsg, URL appletDocumentBase, String appletProxy) {
        String errorMessage = null;
        int iurlPrefix;
        for (iurlPrefix = urlPrefixes.length; --iurlPrefix >= 0; ) if (name.startsWith(urlPrefixes[iurlPrefix])) break;
        boolean isURL = (iurlPrefix >= 0);
        boolean isApplet = (appletDocumentBase != null);
        InputStream in = null;
        int length;
        try {
            if (isApplet || isURL) {
                if (isApplet && isURL && appletProxy != null) name = appletProxy + "?url=" + URLEncoder.encode(name, "utf-8");
                URL url = (isApplet ? new URL(appletDocumentBase, name) : new URL(name));
                name = url.toString();
                if (showMsg) Logger.info("FileManager opening " + url.toString());
                URLConnection conn = url.openConnection();
                length = conn.getContentLength();
                in = conn.getInputStream();
            } else {
                if (showMsg) Logger.info("FileManager opening " + name);
                File file = new File(name);
                length = (int) file.length();
                in = new FileInputStream(file);
            }
            return new MonitorInputStream(in, length);
        } catch (Exception e) {
            try {
                if (in != null) in.close();
            } catch (IOException e1) {
            }
            errorMessage = "" + e;
        }
        return errorMessage;
    }
public static HttpURLConnection create(URL url, String id, String action, HTTPRequestInfo info) throws IOException {
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("POST");
        if (id != null) {
            connection.setRequestProperty("id", id);
        }
        connection.setRequestProperty("action", action);
        connection.setUseCaches(false);
        if (info.getProxyUser() != null && info.getProxyPassword() != null) {
            String pwd = info.getProxyUser() + ":" + info.getProxyPassword();
            String encoded = new String(Base64.encodeBase64(pwd.getBytes()));
            connection.setRequestProperty("Proxy-Authorization", "Basic " + encoded);
        }
        return connection;
    }
private static void copy(String fromFileName, String toFileName) throws IOException {
        File fromFile = new File(fromFileName);
        File toFile = new File(toFileName);
        if (!fromFile.exists()) throw new IOException("FileCopy: " + "no such source file: " + fromFileName);
        if (!fromFile.isFile()) throw new IOException("FileCopy: " + "can't copy directory: " + fromFileName);
        if (!fromFile.canRead()) throw new IOException("FileCopy: " + "source file is unreadable: " + fromFileName);
        if (toFile.isDirectory()) toFile = new File(toFile, fromFile.getName());
        if (toFile.exists()) {
            if (!toFile.canWrite()) throw new IOException("FileCopy: " + "destination file is unwriteable: " + toFileName);
            System.out.print("Overwrite existing file " + toFile.getName() + "? (Y/N): ");
            System.out.flush();
            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
            String response = in.readLine();
            if (!response.equals("Y") && !response.equals("y")) throw new IOException("FileCopy: " + "existing file was not overwritten.");
        } else {
            String parent = toFile.getParent();
            if (parent == null) parent = System.getProperty("user.dir");
            File dir = new File(parent);
            if (!dir.exists()) throw new IOException("FileCopy: " + "destination directory doesn't exist: " + parent);
            if (dir.isFile()) throw new IOException("FileCopy: " + "destination is not a directory: " + parent);
            if (!dir.canWrite()) throw new IOException("FileCopy: " + "destination directory is unwriteable: " + parent);
        }
        FileInputStream from = null;
        FileOutputStream to = null;
        try {
            from = new FileInputStream(fromFile);
            to = new FileOutputStream(toFile);
            byte[] buffer = new byte[4096];
            int bytesRead;
            while ((bytesRead = from.read(buffer)) != -1) to.write(buffer, 0, bytesRead);
        } finally {
            if (from != null) try {
                from.close();
            } catch (IOException e) {
                ;
            }
            if (to != null) try {
                to.close();
            } catch (IOException e) {
                ;
            }
        }
    }
public InputStream getDaoConfig(String connectionType) throws IOException {
        URL url = null;
        if (connectionType.equals(SQL.ORACLE)) {
            url = DBCreateConfig.class.getResource("oracle.xml");
        } else if (connectionType.equals(SQL.SQL2K)) {
            url = DBCreateConfig.class.getResource("sql2k.xml");
        }
        return url.openStream();
    }
public static void copy(File source, File target) {
        FileChannel in = null;
        FileChannel out = null;
        try {
            in = new FileInputStream(source).getChannel();
            out = new FileOutputStream(target).getChannel();
            ByteBuffer buffer = ByteBuffer.allocateDirect(BUFFER);
            while (in.read(buffer) != -1) {
                buffer.flip();
                while (buffer.hasRemaining()) {
                    out.write(buffer);
                }
                buffer.clear();
            }
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        } finally {
            close(in);
            close(out);
        }
    }
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setCharacterEncoding("UTF-8");
        try {
            String content = "";
            URL url = new URL(request.getParameter("url"));
            URLConnection connection = url.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String line;
            while ((line = in.readLine()) != null) {
                content += line + "\n";
            }
            in.close();
            String result = getResult(content);
            response.setContentType("text/plain");
            PrintWriter out = response.getWriter();
            out.println(result);
        } catch (Exception e) {
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            out.println(getErrorPage(e));
        }
    }
public String getHash(String type, String text, String salt) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest md;
        md = MessageDigest.getInstance(type);
        byte[] hash = new byte[md.getDigestLength()];
        if (!salt.isEmpty()) {
            md.update(salt.getBytes("iso-8859-1"), 0, salt.length());
        }
        md.update(text.getBytes("iso-8859-1"), 0, text.length());
        hash = md.digest();
        return convertToHex(hash);
    }
public void parseFile(String dataurl, URL documentBase) {
        DataInputStream in;
        if (_debug > 2) System.out.println("PlotBox: parseFile(" + dataurl + " " + documentBase + ") _dataurl = " + _dataurl + " " + _documentBase);
        if (dataurl == null || dataurl.length() == 0) {
            in = new DataInputStream(System.in);
        } else {
            try {
                URL url;
                if (documentBase == null && _documentBase != null) {
                    documentBase = _documentBase;
                }
                if (documentBase == null) {
                    url = new URL(_dataurl);
                } else {
                    try {
                        url = new URL(documentBase, dataurl);
                    } catch (NullPointerException e) {
                        url = new URL(_dataurl);
                    }
                }
                in = new DataInputStream(url.openStream());
            } catch (MalformedURLException e) {
                try {
                    in = new DataInputStream(new FileInputStream(dataurl));
                } catch (FileNotFoundException me) {
                    _errorMsg = new String[2];
                    _errorMsg[0] = "File not found: " + dataurl;
                    _errorMsg[1] = me.getMessage();
                    return;
                } catch (SecurityException me) {
                    _errorMsg = new String[2];
                    _errorMsg[0] = "Security Exception: " + dataurl;
                    _errorMsg[1] = me.getMessage();
                    return;
                }
            } catch (IOException ioe) {
                _errorMsg = new String[2];
                _errorMsg[0] = "Failure opening URL: " + dataurl;
                _errorMsg[1] = ioe.getMessage();
                return;
            }
        }
        _newFile();
        try {
            if (_binary) {
                _parseBinaryStream(in);
            } else {
                String line = in.readLine();
                while (line != null) {
                    _parseLine(line);
                    line = in.readLine();
                }
            }
        } catch (MalformedURLException e) {
            _errorMsg = new String[2];
            _errorMsg[0] = "Malformed URL: " + dataurl;
            _errorMsg[1] = e.getMessage();
            return;
        } catch (IOException e) {
            _errorMsg = new String[2];
            _errorMsg[0] = "Failure reading data: " + dataurl;
            _errorMsg[1] = e.getMessage();
        } catch (PlotDataException e) {
            _errorMsg = new String[2];
            _errorMsg[0] = "Incorrectly formatted plot data in " + dataurl;
            _errorMsg[1] = e.getMessage();
        } finally {
            try {
                in.close();
            } catch (IOException me) {
            }
        }
    }
public boolean register(Object o) {
        String passwordAsText;
        if (o == null) throw new IllegalArgumentException("object cannot be null");
        if (!(o instanceof User)) {
            throw new IllegalArgumentException("passed argument is not an instance of the User class");
        }
        User newUser = (User) o;
        passwordAsText = newUser.getPassword();
        newUser.setPassword(passwordEncoder.encodePassword(passwordAsText, null));
        newUser.setRegDate(new Date());
        logger.debug("Setting default Authority {} to new user!", Authority.DEFAULT_NAME);
        newUser.getAuthorities().add(super.find(Authority.class, 1));
        logger.debug("Creating hash from email address! using Base64");
        newUser.setHash(new String(Base64.encodeBase64(newUser.getEmail().getBytes())));
        logger.debug("Creating phpBB forum User, by calling URL: {}", forumUrl);
        try {
            StringBuilder urlString = new StringBuilder(forumUrl);
            urlString.append("phpBB.php?action=register").append("&login=").append(newUser.getLogin()).append("&password=").append(passwordAsText).append("&email=").append(newUser.getEmail());
            sqlInjectionPreventer(urlString.toString());
            logger.debug("Connecting to URL: {}", urlString.toString());
            URL url = new URL(urlString.toString());
            URLConnection urlCon = url.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(urlCon.getInputStream()));
            String inputLine;
            while ((inputLine = in.readLine()) != null) newUser.setForumID(Integer.valueOf(inputLine));
            in.close();
        } catch (IOException io) {
            logger.error("Connecting failed! Msg: {}", io.getMessage());
            throw new RuntimeException("Couldn't conntect to phpBB");
        } catch (NumberFormatException e) {
            logger.error("phpBB user generation failed! Msg: {}", e.getMessage());
            throw new RuntimeException("phpBB user generation failed!");
        }
        entityManager.persist(newUser);
        try {
            sendConfirmationEmail(newUser);
            return true;
        } catch (MailException ex) {
            return false;
        }
    }
public static String hashPassword(String password) {
        String passwordHash = "";
        try {
            MessageDigest sha1 = MessageDigest.getInstance("SHA-1");
            sha1.reset();
            sha1.update(password.getBytes());
            Base64 encoder = new Base64();
            passwordHash = new String(encoder.encode(sha1.digest()));
        } catch (NoSuchAlgorithmException e) {
            LoggerFactory.getLogger(UmsAuthenticationProcessingFilter.class.getClass()).error("Failed to generate password hash: " + e.getMessage());
        }
        return passwordHash;
    }
private void copyFile(File file, File targetFile) {
        try {
            BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(targetFile));
            byte[] tmp = new byte[8192];
            int read = -1;
            while ((read = bis.read(tmp)) > 0) {
                bos.write(tmp, 0, read);
            }
            bis.close();
            bos.close();
        } catch (Exception e) {
            if (!targetFile.delete()) {
                System.err.println("Ups, created copy cant be deleted (" + targetFile.getAbsolutePath() + ")");
            }
        }
    }
private String getManifestVersion() {
        URL url = AceTree.class.getResource("/org/rhwlab/help/messages/manifest.html");
        InputStream istream = null;
        String s = "";
        try {
            istream = url.openStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(istream));
            while (br.ready()) {
                s = br.readLine();
                if (s.indexOf("Manifest-Version:") == 0) {
                    s = s.substring(17);
                    break;
                }
                System.out.println("read: " + s);
            }
            br.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "Version: " + s + C.NL;
    }
static void copy(String scr, String dest) throws IOException {
        InputStream in = null;
        OutputStream out = null;
        try {
            in = new FileInputStream(scr);
            out = new FileOutputStream(dest);
            byte[] buf = new byte[1024];
            int n;
            while ((n = in.read(buf)) >= 0) out.write(buf, 0, n);
        } finally {
            closeIgnoringException(in);
            closeIgnoringException(out);
        }
    }
@Override
    protected void write(InputStream in, OutputStream out, javax.sound.sampled.AudioFormat javaSoundFormat) throws IOException {
        if (USE_JAVASOUND) {
            super.write(in, out, javaSoundFormat);
        } else {
            try {
                byte[] header = JavaSoundCodec.createWavHeader(javaSoundFormat);
                if (header == null) throw new IOException("Unable to create wav header");
                out.write(header);
                IOUtils.copyStream(in, out);
            } catch (InterruptedIOException e) {
                logger.log(Level.FINE, "" + e, e);
                throw e;
            } catch (IOException e) {
                logger.log(Level.WARNING, "" + e, e);
                throw e;
            }
        }
    }
public static final void copyFile(String srcFilename, String dstFilename) throws IOException {
        FileInputStream fis = null;
        FileOutputStream fos = null;
        FileChannel ifc = null;
        FileChannel ofc = null;
        Util.copyBuffer.clear();
        try {
            fis = new FileInputStream(srcFilename);
            ifc = fis.getChannel();
            fos = new FileOutputStream(dstFilename);
            ofc = fos.getChannel();
            int sz = (int) ifc.size();
            int n = 0;
            while (n < sz) {
                if (ifc.read(Util.copyBuffer) < 0) {
                    break;
                }
                Util.copyBuffer.flip();
                n += ofc.write(Util.copyBuffer);
                Util.copyBuffer.compact();
            }
        } finally {
            try {
                if (ifc != null) {
                    ifc.close();
                } else if (fis != null) {
                    fis.close();
                }
            } catch (IOException exc) {
            }
            try {
                if (ofc != null) {
                    ofc.close();
                } else if (fos != null) {
                    fos.close();
                }
            } catch (IOException exc) {
            }
        }
    }