semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static InputStream executePost(String path, Map<String, String> params) throws Exception {
		HttpPost httpPost = new HttpPost(path);
		List<NameValuePair> postParams = new ArrayList<NameValuePair>();
		for (Map.Entry<String, String> param : params.entrySet()) {
			postParams.add(new BasicNameValuePair(param.getKey(), param.getValue()));
		}
		HttpEntity entity = new UrlEncodedFormEntity(postParams, "UTF-8");
		httpPost.setEntity(entity);

		HttpResponse httpResponse = sClient.execute(httpPost);
		if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
			return httpResponse.getEntity().getContent();
		} else {
			return null;
		}
	}
public CountModel(URL url) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        String line;
        list = new ArrayList<CountModelItem>();
        map = new HashMap<String, CountModelItem>();
        line = in.readLine();
        int n = 1;
        String[] rowAttrib;
        CountModelItem item;
        while ((line = in.readLine()) != null) {
            rowAttrib = line.split(";");
            item = new CountModelItem(n, Integer.valueOf(rowAttrib[1]).intValue(), Integer.valueOf(rowAttrib[2]).intValue(), Integer.valueOf(rowAttrib[3]).intValue(), rowAttrib[0]);
            list.add(item);
            map.put(item.getHash(), item);
            n++;
        }
        in.close();
    }
public void testGet() throws Exception {
        HttpGet request = new HttpGet(baseUri + "/test");
        HttpResponse response = client.execute(request);
        assertEquals(200, response.getStatusLine().getStatusCode());
        assertEquals("test", TestUtil.getResponseAsString(response));
    }
public void testPost() throws Exception {
        HttpPost request = new HttpPost(baseUri + "/echo");
        request.setEntity(new StringEntity("test"));
        HttpResponse response = client.execute(request);
        assertEquals(200, response.getStatusLine().getStatusCode());
        assertEquals("test", TestUtil.getResponseAsString(response));
    }
public void testPostWithGzip() throws Exception {
        HttpPost request = new HttpPost(baseUri + "/echo");
        request.setEntity(new GZIPCompressedEntity(new StringEntity("test")));
        HttpResponse response = client.execute(request);
        assertEquals(200, response.getStatusLine().getStatusCode());
        assertEquals("test", TestUtil.getResponseAsString(response));
    }
public void testGetWithKeepAlive() throws Exception {
        HttpGet request = new HttpGet(baseUri + "/test");
        HttpResponse response = client.execute(request);
        assertEquals(200, response.getStatusLine().getStatusCode());
        assertEquals("test", TestUtil.getResponseAsString(response));
        response = client.execute(request);
        assertEquals(200, response.getStatusLine().getStatusCode());
        assertEquals("test", TestUtil.getResponseAsString(response));
    }
public static void zipMapBos(DitaBoundedObjectSet mapBos, File outputZipFile, MapBosProcessorOptions options) throws Exception {
        log.debug("Determining zip file organization...");
        BosVisitor visitor = new DxpFileOrganizingBosVisitor();
        visitor.visit(mapBos);
        if (!options.isQuiet()) log.info("Creating DXP package \"" + outputZipFile.getAbsolutePath() + "\"...");
        OutputStream outStream = new FileOutputStream(outputZipFile);
        ZipOutputStream zipOutStream = new ZipOutputStream(outStream);
        ZipEntry entry = null;
        URI rootMapUri = mapBos.getRoot().getEffectiveUri();
        URI baseUri = null;
        try {
            baseUri = AddressingUtil.getParent(rootMapUri);
        } catch (URISyntaxException e) {
            throw new BosException("URI syntax exception getting parent URI: " + e.getMessage());
        }
        Set<String> dirs = new HashSet<String>();
        if (!options.isQuiet()) log.info("Constructing DXP package...");
        for (BosMember member : mapBos.getMembers()) {
            if (!options.isQuiet()) log.info("Adding member " + member + " to zip...");
            URI relativeUri = baseUri.relativize(member.getEffectiveUri());
            File temp = new File(relativeUri.getPath());
            String parentPath = temp.getParent();
            if (parentPath != null && !"".equals(parentPath) && !parentPath.endsWith("/")) {
                parentPath += "/";
            }
            log.debug("parentPath=\"" + parentPath + "\"");
            if (!"".equals(parentPath) && parentPath != null && !dirs.contains(parentPath)) {
                entry = new ZipEntry(parentPath);
                zipOutStream.putNextEntry(entry);
                zipOutStream.closeEntry();
                dirs.add(parentPath);
            }
            entry = new ZipEntry(relativeUri.getPath());
            zipOutStream.putNextEntry(entry);
            IOUtils.copy(member.getInputStream(), zipOutStream);
            zipOutStream.closeEntry();
        }
        zipOutStream.close();
        if (!options.isQuiet()) log.info("DXP package \"" + outputZipFile.getAbsolutePath() + "\" created.");
    }
private void copyFile(File dir, File fileToAdd) {
        try {
            byte[] readBuffer = new byte[1024];
            File file = new File(dir.getCanonicalPath() + File.separatorChar + fileToAdd.getName());
            if (file.createNewFile()) {
                FileInputStream fis = new FileInputStream(fileToAdd);
                FileOutputStream fos = new FileOutputStream(file);
                int bytesRead;
                do {
                    bytesRead = fis.read(readBuffer);
                    fos.write(readBuffer, 0, bytesRead);
                } while (bytesRead == 0);
                fos.flush();
                fos.close();
                fis.close();
            } else {
                logger.severe("unable to create file:" + file.getAbsolutePath());
            }
        } catch (IOException ioe) {
            logger.severe("unable to create file:" + ioe);
        }
    }
private MailBox authenticate() throws Exception {
        String line = "POP3 Server Ready" + ((mChallenge == null) ? "" : (" " + mChallenge));
        MailBox mailbox = null;
        mStream.writeOk(line);
        while (mailbox == null) {
            line = mStream.readLine();
            if (isQuit(line)) break;
            String body;
            if ((body = isCommand(line, "USER")) != null) {
                String user = body;
                MailBox mb = mRepository.getMailBox(user);
                if (mb == null) mStream.writeErr("No mailbox for: " + line); else {
                    mStream.writeOk();
                    String pswd, line2 = mStream.readLine();
                    if (isQuit(line2)) break;
                    if ((pswd = isCommand(line2, "PASS")) == null) mStream.writeErr("Expected PASS but got {" + line2 + "}"); else {
                        String realPswd = mb.getPassword();
                        if ((realPswd != null) ? pswd.equals(realPswd) : mb.checkPassword(pswd)) {
                            mailbox = mb;
                            mStream.writeOk();
                        } else mStream.writeErr("Bad password for " + user);
                    }
                }
            } else if ((body = isCommand(line, "APOP")) != null) {
                if (mChallenge == null) mStream.writeErr("APOP Not Supported"); else {
                    int space = body.indexOf(' ');
                    if (space < 0) mStream.writeErr("Bad APOP command {" + line + "}"); else {
                        String user = body.substring(0, space);
                        String hash = body.substring(space + 1);
                        MailBox mb = mRepository.getMailBox(user);
                        if (mb == null) mStream.writeErr("No mailbox for: " + line); else if (mb.getPassword() == null) mStream.writeErr("User(" + user + ") cannot login using APOP"); else {
                            String secret = mChallenge + mb.getPassword();
                            MessageDigest md5 = MessageDigest.getInstance("MD5");
                            md5.update(secret.getBytes("UTF-8"));
                            byte[] digest = md5.digest();
                            String digestStr = new String(Hex.encodeHex(digest));
                            if (hash.equalsIgnoreCase(digestStr)) {
                                mailbox = mb;
                                mStream.writeOk();
                            } else mStream.writeErr("Bad password for " + user);
                        }
                    }
                }
            } else mStream.writeErr("Authentication required (got '" + line + "')");
        }
        return mailbox;
    }
public int download(String fileName) {
        OutputStream out = null;
        URLConnection conn = null;
        InputStream in = null;
        int numRead = 0;
        int totalRead = 0;
        try {
            URL url = new URL(URL);
            out = new BufferedOutputStream(new FileOutputStream(fileName));
            conn = url.openConnection();
            in = conn.getInputStream();
            byte[] buffer = new byte[1024];
            while ((numRead = in.read(buffer)) != -1) {
                out.write(buffer, 0, numRead);
                totalRead += numRead;
            }
        } catch (IOException exception) {
            totalRead = 0;
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
                if (out != null) {
                    out.close();
                }
            } catch (IOException ioe) {
            }
            return totalRead;
        }
    }
private static String doGetForSessionKey(String authCode) throws Exception {
        String sessionKey = "";
        HttpClient hc = new DefaultHttpClient();
        HttpGet hg = new HttpGet(Common.TEST_SESSION_HOST + Common.TEST_SESSION_PARAM + authCode);
        HttpResponse hr = hc.execute(hg);
        BufferedReader br = new BufferedReader(new InputStreamReader(hr.getEntity().getContent()));
        StringBuilder sb = new StringBuilder();
        String line;
        while ((line = br.readLine()) != null) {
            sb.append(line);
        }
        String result = sb.toString();
        Log.i("sessionKeyMessages", result);
        Map<String, String> map = Util.handleURLParameters(result);
        sessionKey = map.get(Common.TOP_SESSION);
        String topParameters = map.get(Common.TOP_PARAMETERS);
        String decTopParameters = Util.decodeBase64(topParameters);
        Log.i("base64", decTopParameters);
        map = Util.handleURLParameters(decTopParameters);
        Log.i("nick", map.get(Common.VISITOR_NICK));
        CachePool.put(Common.VISITOR_NICK, map.get(Common.VISITOR_NICK));
        return sessionKey;
    }
private String getEncoding() throws IOException {
        BufferedReader reader = null;
        String encoding = null;
        try {
            URLConnection connection = url.openConnection();
            Map<String, List<String>> header = connection.getHeaderFields();
            for (Map.Entry<String, List<String>> entry : header.entrySet()) {
                if (entry.getKey().toLowerCase().equals("content-type")) {
                    String item = entry.getValue().toString().toLowerCase();
                    if (item.contains("charset")) {
                        encoding = extractEncoding(item);
                        if (encoding != null && !encoding.isEmpty()) return encoding;
                    }
                }
            }
            reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String line;
            while ((line = reader.readLine()) != null) {
                line = line.toLowerCase();
                if (line.contains("charset") || line.contains("encoding")) {
                    encoding = extractEncoding(line);
                    if (encoding != null && !encoding.isEmpty()) return encoding;
                }
            }
            return STANDARDENCODING;
        } finally {
            if (reader != null) reader.close();
        }
    }
public void testRegister() throws IOException {
        User newUser = new User(false, "testregUser", "regUser");
        newUser.setEmail("eagle-r@gmx.de");
        newUser.setUniversity("uni");
        newUser.setFirstName("first");
        newUser.setLastName("last");
        User regUser = null;
        try {
            regUser = (User) getJdbcTemplate().queryForObject("select id, login, password, email, hash, REGISTRATION_DATE, university, FORUM_ID from USER where login = ?", new Object[] { newUser.getUsername() }, new UserMapper());
        } catch (EmptyResultDataAccessException e) {
        }
        assertNull("This test user already exists! Abort test", regUser);
        userServiceRemote.registrate(newUser);
        setComplete();
        endTransaction();
        regUser = (User) getJdbcTemplate().queryForObject("select id, login, password, email, hash, REGISTRATION_DATE, university, FORUM_ID from USER where login = ?", new Object[] { newUser.getUsername() }, new UserMapper());
        assertNotNull(regUser);
        assertNotNull(regUser.getId());
        assertNotNull(regUser.getHash());
        assertFalse(regUser.getHash().isEmpty());
        assertEquals(regUser.getLogin(), newUser.getLogin());
        assertEquals(regUser.getPassword(), newUser.getPassword());
        assertEquals(regUser.getUniversity(), newUser.getUniversity());
        assertEquals(regUser.getEmail(), newUser.getEmail());
        Integer id = newUser.getId();
        getJdbcTemplate().execute("DELETE FROM USER_AUTHORITIES WHERE USER_ID =" + id);
        getJdbcTemplate().execute("DELETE FROM USER WHERE ID = " + id);
        StringBuilder urlString = new StringBuilder(userService.getForumUrl());
        urlString.append("phpBB.php?action=remove").append("&id=").append(newUser.getForumID()).append("&mode=remove");
        logger.debug("Connecting to URL: " + urlString.toString());
        URL url = new URL(urlString.toString());
        URLConnection con = url.openConnection();
        BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String inputLine;
        while ((inputLine = in.readLine()) != null) logger.debug("Response: " + inputLine);
        in.close();
    }
public void putFile(CompoundName file, FileInputStream fileInput) throws IOException {
        File fullDir = new File(REMOTE_BASE_DIR.getCanonicalPath());
        for (int i = 0; i < file.size() - 1; i++) fullDir = new File(fullDir, file.get(i));
        fullDir.mkdirs();
        File outputFile = new File(fullDir, file.get(file.size() - 1));
        FileOutputStream outStream = new FileOutputStream(outputFile);
        for (int byteIn = fileInput.read(); byteIn != -1; byteIn = fileInput.read()) outStream.write(byteIn);
        fileInput.close();
        outStream.close();
    }
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        InstanciaDelegate delegate = RegistroManager.recuperarInstancia(request);
        if (delegate == null) {
            ActionErrors errors = new ActionErrors();
            errors.add(null, new ActionError("errors.session"));
            saveErrors(request, errors);
            return mapping.findForward("fail");
        }
        AyudaPantalla ayudaPantalla = delegate.obtenerAyudaPantalla();
        TraAyudaPantalla traAyudaPantalla = (TraAyudaPantalla) ayudaPantalla.getTraduccion();
        String urlSonido = traAyudaPantalla.getUrlSonido();
        if (urlSonido == null) {
            return null;
        }
        URL url = new URL(urlSonido);
        URLConnection urlConnection = url.openConnection();
        urlConnection.connect();
        String tipoMime = urlConnection.getContentType();
        log.debug("Tipo Mime: " + tipoMime);
        Map audioOptions = new HashMap();
        if (tipoMime.indexOf("audio") != -1 || tipoMime.indexOf("asf") != -1 || tipoMime.equals("unknown/unknown")) {
            audioOptions.put("id", "MediaPlayer");
            audioOptions.put("codeBase", "http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112");
            audioOptions.put("classId", "CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95");
            audioOptions.put("mimeType", "application/x-mplayer2");
            audioOptions.put("urlSonido", urlSonido);
            audioOptions.put("pluginSpage", "http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/");
        } else if (tipoMime.indexOf("real") != -1) {
            audioOptions.put("id", "RVOCX");
            audioOptions.put("codeBase", "");
            audioOptions.put("classId", "clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA");
            audioOptions.put("mimeType", "audio/x-pn-realaudio-plugin");
            audioOptions.put("urlSonido", urlSonido);
            audioOptions.put("pluginSpage", "");
        }
        request.setAttribute("audioOptions", audioOptions);
        log.debug("entra success");
        return mapping.findForward("success");
    }
void readFileHeader(DmgConfigDMO config, ConfigLocation sl) throws IOException {
        fileHeader = "";
        if (config.getGeneratedFileHeader() != null) {
            StringBuffer sb = new StringBuffer();
            if (sl.getJarFilename() != null) {
                URL url = new URL("jar:file:" + sl.getJarFilename() + "!/" + sl.getJarDirectory() + "/" + config.getGeneratedFileHeader());
                LineNumberReader in = new LineNumberReader(new InputStreamReader(url.openStream()));
                String str;
                while ((str = in.readLine()) != null) {
                    sb.append(str + "\n");
                }
                in.close();
            } else {
                LineNumberReader in = new LineNumberReader(new FileReader(sl.getDirectory() + File.separator + config.getGeneratedFileHeader()));
                String str;
                while ((str = in.readLine()) != null) {
                    sb.append(str + "\n");
                }
                in.close();
            }
            fileHeader = sb.toString();
        }
    }
public Vector Get() throws Exception {
        String query_str = BuildYahooQueryString();
        if (query_str == null) return null;
        Vector result = new Vector();
        HttpURLConnection urlc = null;
        try {
            URL url = new URL(URL_YAHOO_QUOTE + "?" + query_str + "&" + FORMAT);
            urlc = (HttpURLConnection) url.openConnection();
            urlc.setRequestMethod("GET");
            urlc.setDoOutput(true);
            urlc.setDoInput(true);
            urlc.setUseCaches(false);
            urlc.setAllowUserInteraction(false);
            urlc.setRequestProperty("Content-type", "text/html;charset=UTF-8");
            if (urlc.getResponseCode() == 200) {
                InputStream in = urlc.getInputStream();
                BufferedReader reader = null;
                try {
                    reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
                    String msg = null;
                    while ((msg = reader.readLine()) != null) {
                        ExchangeRate rate = ParseYahooData(msg);
                        if (rate != null) result.add(rate);
                    }
                } finally {
                    if (reader != null) try {
                        reader.close();
                    } catch (Exception e1) {
                    }
                    if (in != null) try {
                        in.close();
                    } catch (Exception e1) {
                    }
                }
                return result;
            }
        } finally {
            if (urlc != null) try {
                urlc.disconnect();
            } catch (Exception e) {
            }
        }
        return null;
    }
protected void downloadCacheFile(File file) throws Exception {
        ApplicationProperties app = ApplicationProperties.getInstance();
        String address = app.getProperty(JabberConstants.PROPERTY_JABBER_SERVERLIST, DEFAULT_SERVER_URL);
        URL url = new URL(address);
        file.createNewFile();
        OutputStream cache = new FileOutputStream(file);
        InputStream input = url.openStream();
        byte buffer[] = new byte[1024];
        int bytesRead = 0;
        while ((bytesRead = input.read(buffer)) >= 0) cache.write(buffer, 0, bytesRead);
        input.close();
        cache.close();
    }
public void copyFile(String oldPath, String newPath) {
        try {
            int bytesum = 0;
            int byteread = 0;
            File oldfile = new File(oldPath);
            if (oldfile.exists()) {
                InputStream inStream = new FileInputStream(oldPath);
                FileOutputStream fs = new FileOutputStream(newPath);
                byte[] buffer = new byte[1444];
                while ((byteread = inStream.read(buffer)) != -1) {
                    bytesum += byteread;
                    fs.write(buffer, 0, byteread);
                }
                inStream.close();
                fs.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
private void getEventHeapsFromWeb() {
        try {
            URL url = getServersURL();
            InputStream in = url.openStream();
            Document doc = factory.newDocumentBuilder().parse(in);
            readFromDocument(doc);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession(false);
        if (session == null) {
            log.warn("HttpProxyServlet: no session");
            response.setStatus(404);
            return;
        }
        User user = (User) session.getAttribute("user");
        if (user == null) {
            log.warn("HttpProxyServlet: user not logged in");
            response.setStatus(404);
            return;
        }
        String target = null;
        if (request.getPathInfo() != null && !request.getPathInfo().equals("")) {
            target = "http:/" + request.getPathInfo() + "?" + request.getQueryString();
            log.info("HttpProxyServlet: target=" + target);
        } else {
            log.warn("HttpProxyServlet: missing pathInfo");
            response.setStatus(404);
            return;
        }
        InputStream is = null;
        ServletOutputStream out = null;
        try {
            URL url = new URL(target);
            URLConnection uc = url.openConnection();
            response.setContentType(uc.getContentType());
            is = uc.getInputStream();
            out = response.getOutputStream();
            byte[] buf = new byte[4096];
            int bytesRead;
            while ((bytesRead = is.read(buf)) != -1) {
                out.write(buf, 0, bytesRead);
            }
        } catch (MalformedURLException e) {
            log.warn("HttpProxyServlet: malformed URL");
            response.setStatus(404);
        } catch (IOException e) {
            log.warn("HttpProxyServlet: I/O exception");
            response.setStatus(404);
        } finally {
            if (is != null) {
                is.close();
            }
            if (out != null) {
                out.close();
            }
        }
    }
public static String upload(File tmpFile, URL url) throws IOException {
        StringBuffer reply = new StringBuffer();
        URLConnection uc = url.openConnection();
        ClientHttpRequest request = new ClientHttpRequest(uc);
        String file = "file";
        String filename = tmpFile.getName();
        InputStream fileinput = new FileInputStream(tmpFile);
        request.setParameter(file, filename, fileinput);
        InputStream serverInput = request.post();
        BufferedReader in = new BufferedReader(new InputStreamReader(serverInput));
        String line = in.readLine();
        while (line != null) {
            reply.append(line + "\n");
            line = in.readLine();
        }
        in.close();
        return reply.toString();
    }