semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static HttpsURLConnection createRequest(String feedUrl, String httpMethod, Map<String, String> headers) throws BuzzIOException {
        HttpsURLConnection con;
        try {
            URL url = new URL(feedUrl);
            con = (HttpsURLConnection) url.openConnection();
            con.setRequestMethod(httpMethod);
            if (headers != null && !headers.isEmpty()) {
                for (String key : headers.keySet()) {
                    con.setRequestProperty(key, headers.get(key));
                }
            }
        } catch (IOException e) {
            throw new BuzzIOException(e);
        }
        return con;
    }
public static boolean postData(URL url, String parameters) {
        HttpURLConnection hpcon = null;
        try {
            hpcon = (HttpURLConnection) url.openConnection();
            hpcon.setRequestMethod("POST");
            hpcon.setRequestProperty("Content-Length", "" + Integer.toString(parameters.getBytes().length));
            hpcon.setUseCaches(false);
            hpcon.setDoInput(true);
            hpcon.setDoOutput(true);
            DataOutputStream printout = new DataOutputStream(hpcon.getOutputStream());
            printout.writeBytes(parameters);
            printout.flush();
            printout.close();
            BufferedReader in = new BufferedReader(new InputStreamReader(hpcon.getInputStream()));
            String input;
            boolean success = false;
            while ((input = in.readLine()) != null) {
                if (input.contains("OK")) success = true;
            }
            return success;
        } catch (Exception e) {
            try {
                if (hpcon != null) hpcon.disconnect();
            } catch (Exception e2) {
            }
            return false;
        }
    }
public static String getAnalysisServletOutput(String inputXml) {
        java.io.BufferedWriter bWriter = null;
        URLConnection connection = null;
        String resultString = "";
        bWriter = null;
        connection = null;
        String target = ServletConstant.ANALYSIS_SERVLET;
        String message = "\nTHIS MESSAGE IS SENT FROM THE CLIENT APPLET   \n\r";
        try {
            URL url = new URL(target);
            connection = (HttpURLConnection) url.openConnection();
            ((HttpURLConnection) connection).setRequestMethod("POST");
            connection.setDoOutput(true);
            bWriter = new java.io.BufferedWriter(new java.io.OutputStreamWriter(connection.getOutputStream()));
            bWriter.write(message);
            bWriter.flush();
            bWriter.close();
            java.io.BufferedReader bReader = null;
            bReader = new java.io.BufferedReader(new java.io.InputStreamReader(connection.getInputStream()));
            String line;
            StringBuffer sb = new StringBuffer();
            while ((line = bReader.readLine()) != null) {
                sb.append(line);
            }
            resultString = sb.toString();
            bReader.close();
            ((HttpURLConnection) connection).disconnect();
        } catch (java.io.IOException ex) {
            resultString += ex.toString();
        } finally {
            if (bWriter != null) {
                try {
                    bWriter.close();
                } catch (Exception ex) {
                    resultString += ex.toString();
                }
            }
            if (connection != null) {
                try {
                    ((HttpURLConnection) connection).disconnect();
                } catch (Exception ex) {
                    resultString += ex.toString();
                }
            }
        }
        return resultString;
    }
private void download(String fileName) {
        String filePath = Activator.showSaveDialog(fileName, new String[] { ".xls" });
        if (filePath != null) {
            InputStream in = null;
            OutputStream out = null;
            try {
                in = this.getClass().getResourceAsStream("/" + fileName);
                out = new FileOutputStream(filePath);
                IOUtils.copy(in, out);
            } catch (IOException ioe) {
                Activator.showExceptionDialog(ioe);
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException e1) {
                        Activator.showExceptionDialog(e1);
                    }
                }
                if (out != null) {
                    try {
                        out.close();
                    } catch (IOException e1) {
                        Activator.showExceptionDialog(e1);
                    }
                }
            }
        }
    }
public static void main(String[] args) throws Exception {
        dataList = new ArrayList<String>();
        System.setProperty("http.agent", Phex.getFullPhexVendor());
        URL url = new URL(listUrl);
        URLConnection connection = url.openConnection();
        InputStream inputStream = connection.getInputStream();
        readData(inputStream);
        System.out.println("Total data read: " + dataList.size());
        inputStream.close();
        writeToOutputFile();
    }
public static boolean napiUserCheck(String user, String pass) throws TimeoutException, InterruptedException, IOException {
        URLConnection conn = null;
        InputStream in = null;
        URL url = new URL("http://www.napiprojekt.pl/users_check.php?nick=" + user + "&pswd=" + pass);
        conn = url.openConnection(Global.getProxy());
        in = Timeouts.getInputStream(conn);
        byte[] buffer = new byte[1024];
        in.read(buffer, 0, 1024);
        if (in != null) {
            in.close();
        }
        String response = new String(buffer);
        if (response.indexOf("ok") == 0) {
            return true;
        } else {
            return false;
        }
    }
public static AddUserResponse napiUserAdd(String user, String pass, String email) throws TimeoutException, InterruptedException, IOException {
        if (user.matches("^[a-zA-Z0-9]{2,20}$") == false) {
            return AddUserResponse.NAPI_ADD_USER_BAD_LOGIN;
        }
        if (pass.equals("")) {
            return AddUserResponse.NAPI_ADD_USER_BAD_PASS;
        }
        if (email.matches("^[a-zA-Z0-9\\-\\_]{1,30}@[a-zA-Z0-9]+(\\.[a-zA-Z0-9]+)+$") == false) {
            return AddUserResponse.NAPI_ADD_USER_BAD_EMAIL;
        }
        URLConnection conn = null;
        ClientHttpRequest httpPost = null;
        InputStreamReader responseStream = null;
        URL url = new URL("http://www.napiprojekt.pl/users_add.php");
        conn = url.openConnection(Global.getProxy());
        httpPost = new ClientHttpRequest(conn);
        httpPost.setParameter("login", user);
        httpPost.setParameter("haslo", pass);
        httpPost.setParameter("mail", email);
        httpPost.setParameter("z_programu", "true");
        responseStream = new InputStreamReader(httpPost.post(), "Cp1250");
        BufferedReader responseReader = new BufferedReader(responseStream);
        String response = responseReader.readLine();
        if (response.indexOf("login już istnieje") != -1) {
            return AddUserResponse.NAPI_ADD_USER_LOGIN_EXISTS;
        }
        if (response.indexOf("na podany e-mail") != -1) {
            return AddUserResponse.NAPI_ADD_USER_EMAIL_EXISTS;
        }
        if (response.indexOf("NPc0") == 0) {
            return AddUserResponse.NAPI_ADD_USER_OK;
        }
        return AddUserResponse.NAPI_ADD_USER_BAD_UNKNOWN;
    }
public static void fileCopy(String src, String dst) {
        try {
            FileInputStream fis = new FileInputStream(src);
            FileOutputStream fos = new FileOutputStream(dst);
            int read = -1;
            byte[] buf = new byte[8192];
            while ((read = fis.read(buf)) != -1) {
                fos.write(buf, 0, read);
            }
            fos.flush();
            fos.close();
            fis.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
private static void findAllProviders() {
        try {
            ClassLoader loader = Thread.currentThread().getContextClassLoader();
            Enumeration<URL> resources = loader.getResources("META-INF/services/" + PersistenceProvider.class.getName());
            Set<String> names = new HashSet<String>();
            while (resources.hasMoreElements()) {
                URL url = resources.nextElement();
                InputStream is = url.openStream();
                try {
                    names.addAll(providerNamesFromReader(new BufferedReader(new InputStreamReader(is))));
                } finally {
                    is.close();
                }
            }
            for (String s : names) {
                Class providerClass = loader.loadClass(s);
                providers.add((PersistenceProvider) providerClass.newInstance());
            }
        } catch (IOException e) {
            throw new PersistenceException(e);
        } catch (InstantiationException e) {
            throw new PersistenceException(e);
        } catch (IllegalAccessException e) {
            throw new PersistenceException(e);
        } catch (ClassNotFoundException e) {
            throw new PersistenceException(e);
        }
    }
public static int proxy(java.net.URI uri, HttpServletRequest req, HttpServletResponse res) throws IOException {
        final HostConfiguration hostConfig = new HostConfiguration();
        hostConfig.setHost(uri.getHost());
        HttpMethodBase httpMethod = null;
        if (HttpRpcServer.METHOD_GET.equalsIgnoreCase(req.getMethod())) {
            httpMethod = new GetMethod(uri.toString());
            httpMethod.setFollowRedirects(true);
        } else if (HttpRpcServer.METHOD_POST.equalsIgnoreCase(req.getMethod())) {
            httpMethod = new PostMethod(uri.toString());
            final Enumeration parameterNames = req.getParameterNames();
            if (parameterNames != null) while (parameterNames.hasMoreElements()) {
                final String parameterName = (String) parameterNames.nextElement();
                for (String parameterValue : req.getParameterValues(parameterName)) ((PostMethod) httpMethod).addParameter(parameterName, parameterValue);
            }
            ((PostMethod) httpMethod).setRequestEntity(new InputStreamRequestEntity(req.getInputStream()));
        }
        if (httpMethod == null) throw new IllegalArgumentException("Unsupported http request method");
        final int responseCode;
        final Enumeration headers = req.getHeaderNames();
        if (headers != null) while (headers.hasMoreElements()) {
            final String headerName = (String) headers.nextElement();
            final Enumeration headerValues = req.getHeaders(headerName);
            while (headerValues.hasMoreElements()) {
                httpMethod.setRequestHeader(headerName, (String) headerValues.nextElement());
            }
        }
        final HttpState httpState = new HttpState();
        if (req.getCookies() != null) for (Cookie cookie : req.getCookies()) {
            String host = req.getHeader("Host");
            if (StringUtils.isEmpty(cookie.getDomain())) cookie.setDomain(StringUtils.isEmpty(host) ? req.getServerName() + ":" + req.getServerPort() : host);
            if (StringUtils.isEmpty(cookie.getPath())) cookie.setPath("/");
            httpState.addCookie(new org.apache.commons.httpclient.Cookie(cookie.getDomain(), cookie.getName(), cookie.getValue(), cookie.getPath(), cookie.getMaxAge(), cookie.getSecure()));
        }
        httpMethod.setQueryString(req.getQueryString());
        responseCode = (new HttpClient()).executeMethod(hostConfig, httpMethod, httpState);
        if (responseCode < 0) {
            httpMethod.releaseConnection();
            return responseCode;
        }
        if (httpMethod.getResponseHeaders() != null) for (Header header : httpMethod.getResponseHeaders()) res.setHeader(header.getName(), header.getValue());
        final InputStream in = httpMethod.getResponseBodyAsStream();
        final OutputStream out = res.getOutputStream();
        IOUtils.copy(in, out);
        out.flush();
        out.close();
        in.close();
        httpMethod.releaseConnection();
        return responseCode;
    }
protected URLConnection openConnection(URL url) throws IOException {
        if (url == null) return null;
        if (!url.getProtocol().equals("nntp")) return null;
        if (m_connection != null) {
            if (m_connection.getURL().getHost().equals(url.getHost()) && (m_connection.getURL().getPort() == url.getPort()) && (m_connection.getURL().getUserInfo().equals(url.getUserInfo()))) {
                return m_connection;
            }
        }
        m_connection = new NNTPConnection(url);
        return m_connection;
    }
public BufferedWriter createWriter(File outfile, String encoding) throws UnsupportedEncodingException, IOException {
        int k_blockSize = 1024;
        int byteCount;
        char[] buf = new char[k_blockSize];
        ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(outfile));
        zos.setMethod(ZipOutputStream.DEFLATED);
        OutputStreamWriter osw = new OutputStreamWriter(zos, "ISO-8859-1");
        BufferedWriter bw = new BufferedWriter(osw);
        ZipEntry zot;
        ZipInputStream zis = new ZipInputStream(new FileInputStream(infile));
        InputStreamReader isr = new InputStreamReader(zis, "ISO-8859-1");
        BufferedReader br = new BufferedReader(isr);
        ZipEntry zit;
        while ((zit = zis.getNextEntry()) != null) {
            if (zit.getName().equals("content.xml")) {
                continue;
            }
            zot = new ZipEntry(zit.getName());
            zos.putNextEntry(zot);
            while ((byteCount = br.read(buf, 0, k_blockSize)) >= 0) bw.write(buf, 0, byteCount);
            bw.flush();
            zos.closeEntry();
        }
        zos.putNextEntry(new ZipEntry("content.xml"));
        bw.flush();
        return new BufferedWriter(new OutputStreamWriter(zos, "UTF-8"));
    }
@Override
    public AC3DModel loadModel(URL url, String skin) throws IOException, IncorrectFormatException, ParsingErrorException {
        boolean baseURLWasNull = setBaseURLFromModelURL(url);
        AC3DModel model = loadModel(url.openStream(), skin);
        if (baseURLWasNull) {
            popBaseURL();
        }
        return (model);
    }
public WordEntry[] getVariants(String word) throws MatchPackException {
        String upperWord = word.toUpperCase();
        if (variantsDictionary == null) {
            try {
                long start = System.currentTimeMillis();
                URL url = this.getClass().getResource("varlex.dic");
                ObjectInputStream si = new ObjectInputStream(url.openStream());
                variantsDictionary = (Map) si.readObject();
                long end = System.currentTimeMillis();
                System.out.println("loaded " + (end - start) + "ms");
                si.close();
            } catch (Exception e) {
                throw new MatchPackException("cannot load: varlex.dic " + e.getMessage());
            }
        }
        List l = (List) variantsDictionary.get(upperWord);
        if (l == null) {
            return new WordEntry[0];
        }
        return (WordEntry[]) l.toArray(new WordEntry[0]);
    }
public static double getPrice(final String ticker) {
        try {
            final URL url = new URL("http://ichart.finance.yahoo.com/table.csv?s=" + ticker);
            final BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
            reader.readLine();
            final String data = reader.readLine();
            System.out.println("Results of data: " + data);
            final String[] dataItems = data.split(",");
            return Double.parseDouble(dataItems[dataItems.length - 1]);
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }
private void createJarArchive(File archiveFile, List<File> filesToBeJared, File base) throws Exception {
        FileOutputStream stream = new FileOutputStream(archiveFile);
        JarOutputStream out = new JarOutputStream(stream);
        for (File tobeJared : filesToBeJared) {
            if (tobeJared == null || !tobeJared.exists() || tobeJared.isDirectory()) continue;
            String entryName = tobeJared.getAbsolutePath().substring(base.getAbsolutePath().length() + 1).replace("\\", "/");
            JarEntry jarEntry = new JarEntry(entryName);
            jarEntry.setTime(tobeJared.lastModified());
            out.putNextEntry(jarEntry);
            FileInputStream in = new FileInputStream(tobeJared);
            IOUtils.copy(in, out);
            IOUtils.closeQuietly(in);
            out.closeEntry();
        }
        out.close();
        stream.close();
        System.out.println("Generated file: " + archiveFile);
    }
private void copyThemeProviderClass() throws Exception {
        InputStream is = getClass().getResourceAsStream("/zkthemer/ThemeProvider.class");
        if (is == null) throw new RuntimeException("Cannot find ThemeProvider.class");
        File outFile = new File(theme.getJarRootFile(), "zkthemer/ThemeProvider.class");
        outFile.getParentFile().mkdirs();
        FileOutputStream out = new FileOutputStream(outFile);
        IOUtils.copy(is, out);
        out.close();
        FileUtils.writeStringToFile(new File(theme.getJarRootFile(), "zkthemer.properties"), "theme=" + theme.getName() + "\r\nfileList=" + fileList.deleteCharAt(fileList.length() - 1).toString());
    }
private void loadMap() {
        final String wordList = "vietwordlist.txt";
        try {
            File dataFile = new File(supportDir, wordList);
            if (!dataFile.exists()) {
                final ReadableByteChannel input = Channels.newChannel(ClassLoader.getSystemResourceAsStream("dict/" + dataFile.getName()));
                final FileChannel output = new FileOutputStream(dataFile).getChannel();
                output.transferFrom(input, 0, 1000000L);
                input.close();
                output.close();
            }
            long fileLastModified = dataFile.lastModified();
            if (map == null) {
                map = new HashMap();
            } else {
                if (fileLastModified <= mapLastModified) {
                    return;
                }
                map.clear();
            }
            mapLastModified = fileLastModified;
            BufferedReader bs = new BufferedReader(new InputStreamReader(new FileInputStream(dataFile), "UTF-8"));
            String accented;
            while ((accented = bs.readLine()) != null) {
                String plain = VietUtilities.stripDiacritics(accented);
                map.put(plain.toLowerCase(), accented);
            }
            bs.close();
        } catch (IOException e) {
            map = null;
            e.printStackTrace();
            JOptionPane.showMessageDialog(this, myResources.getString("Cannot_find_\"") + wordList + myResources.getString("\"_in\n") + supportDir.toString(), VietPad.APP_NAME, JOptionPane.ERROR_MESSAGE);
        }
    }
public static final String hash(String data) {
        MessageDigest digest = null;
        if (digest == null) {
            try {
                digest = MessageDigest.getInstance("MD5");
            } catch (NoSuchAlgorithmException nsae) {
                System.err.println("Failed to load the MD5 MessageDigest. " + "Jive will be unable to function normally.");
                nsae.printStackTrace();
            }
        }
        digest.update(data.getBytes());
        return encodeHex(digest.digest());
    }
protected void doRequest(HttpServletRequest request, HttpServletResponse response, boolean inGet) throws ServletException, IOException {
        response.setHeader("Server", WebConsoleServlet.SERVER_STRING);
        try {
            String requestedFilename = request.getRequestURI().substring(1);
            URL url = new URL(getJarFileName() + "/");
            JarURLConnection jarConnection = (JarURLConnection) (url.openConnection());
            JarFile jarFile = jarConnection.getJarFile();
            String negotiatedFilename = null;
            ZipEntry zipEntry = null;
            zipEntry = negotiateImageFile(jarFile, requestedFilename, isIE6OrEarlier(request.getHeader("User-Agent")));
            if (zipEntry == null) {
                zipEntry = jarFile.getEntry(requestedFilename);
            } else {
                negotiatedFilename = zipEntry.getName();
            }
            if (zipEntry == null || zipEntry.isDirectory()) {
                handleFileNotFound(inGet, request, response);
                return;
            }
            int fileSize = (int) zipEntry.getSize();
            response.setContentLength(fileSize);
            if (negotiatedFilename != null) {
                response.setContentType(getContentType(negotiatedFilename));
            } else {
                response.setContentType(getContentType(request.getRequestURI()));
            }
            InputStream in = jarFile.getInputStream(zipEntry);
            BufferedInputStream bufferedInputStream = new BufferedInputStream(in);
            byte[] file = new byte[fileSize];
            int bytesRead = bufferedInputStream.read(file);
            bufferedInputStream.close();
            if (bytesRead == fileSize && cachingEnabled) {
                SimpleDateFormat formatter = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss z");
                java.util.Date today = new java.util.Date();
                String date = formatter.format(GenericUtils.addOrSubstractDaysFromDate(today, 365));
                response.setHeader("Expires", date);
            }
            OutputStream outputStream = response.getOutputStream();
            outputStream.write(file);
        } catch (FileNotFoundException e) {
            handleFileNotFound(inGet, request, response);
        } catch (IOException e) {
        } catch (Throwable t) {
            Application.getApplication().logExceptionEvent(EventLogMessage.EventType.WEB_ERROR, t);
        }
    }
public static URLConnection openRemoteDescriptionFile(String urlstr) throws MalformedURLException {
        URL url = new URL(urlstr);
        try {
            URLConnection conn = url.openConnection();
            conn.connect();
            return conn;
        } catch (Exception e) {
            Config conf = Config.getInstance();
            SimpleSocketAddress localServAddr = conf.getLocalProxyServerAddress();
            Proxy proxy = new Proxy(Type.HTTP, new InetSocketAddress(localServAddr.host, localServAddr.port));
            URLConnection conn;
            try {
                conn = url.openConnection(proxy);
                conn.connect();
                return conn;
            } catch (IOException e1) {
                logger.error("Failed to retrive desc file:" + url, e1);
            }
        }
        return null;
    }
protected InputStream getInputStream() throws IOException {
        if (source instanceof URL) {
            URL url = (URL) source;
            location = url.toString();
            return url.openStream();
        } else if (source instanceof File) {
            location = ((File) source).getAbsolutePath();
            return new FileInputStream((File) source);
        } else if (source instanceof String) {
            location = (String) source;
            return new FileInputStream((String) source);
        } else if (source instanceof InputStream) {
            return (InputStream) source;
        }
        return null;
    }
public static void copyFile(File src, File dst) throws IOException {
        FileChannel from = new FileInputStream(src).getChannel();
        FileChannel to = new FileOutputStream(dst).getChannel();
        from.transferTo(0, src.length(), to);
        from.close();
        to.close();
    }