semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public ResponseStatus nowPlaying(String artist, String track, String album, int length, int tracknumber) throws IOException {
        if (sessionId == null) throw new IllegalStateException("Perform successful handshake first.");
        String b = album != null ? encode(album) : "";
        String l = length == -1 ? "" : String.valueOf(length);
        String n = tracknumber == -1 ? "" : String.valueOf(tracknumber);
        String body = String.format("s=%s&a=%s&t=%s&b=%s&l=%s&n=%s&m=", sessionId, encode(artist), encode(track), b, l, n);
        if (Caller.getInstance().isDebugMode()) System.out.println("now playing: " + body);
        Proxy proxy = Caller.getInstance().getProxy();
        HttpURLConnection urlConnection = Caller.getInstance().openConnection(nowPlayingUrl);
        urlConnection.setRequestMethod("POST");
        urlConnection.setDoOutput(true);
        OutputStream outputStream = urlConnection.getOutputStream();
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream));
        writer.write(body);
        writer.close();
        InputStream is = urlConnection.getInputStream();
        BufferedReader r = new BufferedReader(new InputStreamReader(is));
        String status = r.readLine();
        r.close();
        return new ResponseStatus(ResponseStatus.codeForStatus(status));
    }
public ResponseStatus submit(Collection<SubmissionData> data) throws IOException {
        if (sessionId == null) throw new IllegalStateException("Perform successful handshake first.");
        if (data.size() > 50) throw new IllegalArgumentException("Max 50 submissions at once");
        StringBuilder builder = new StringBuilder(data.size() * 100);
        int index = 0;
        for (SubmissionData submissionData : data) {
            builder.append(submissionData.toString(sessionId, index));
            builder.append('\n');
            index++;
        }
        String body = builder.toString();
        if (Caller.getInstance().isDebugMode()) System.out.println("submit: " + body);
        HttpURLConnection urlConnection = Caller.getInstance().openConnection(submissionUrl);
        urlConnection.setRequestMethod("POST");
        urlConnection.setDoOutput(true);
        OutputStream outputStream = urlConnection.getOutputStream();
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream));
        writer.write(body);
        writer.close();
        InputStream is = urlConnection.getInputStream();
        BufferedReader r = new BufferedReader(new InputStreamReader(is));
        String status = r.readLine();
        r.close();
        int statusCode = ResponseStatus.codeForStatus(status);
        if (statusCode == ResponseStatus.FAILED) {
            return new ResponseStatus(statusCode, status.substring(status.indexOf(' ') + 1));
        }
        return new ResponseStatus(statusCode);
    }
protected String readUrl(String svnUrl) throws IOException {
        URL url = new URL(svnUrl);
        URLConnection uc = url.openConnection();
        if (url.getProtocol().equals("https")) {
            String userPassword = user + ":" + password;
            String encoding = new sun.misc.BASE64Encoder().encode(userPassword.getBytes());
            uc.setRequestProperty("Authorization", "Basic " + encoding);
        }
        InputStream is = null;
        String in = null;
        try {
            is = uc.getInputStream();
            in = read(is);
        } finally {
            try {
                is.close();
            } catch (Exception e) {
            }
        }
        return in;
    }
public InputStream getInputStream() throws ResourceLoadException {
        logger.info("loading: " + url.toString() + ", Thread: " + Thread.currentThread().getName());
        tryCount = 0;
        while (true) {
            HttpURLConnection httpConnection = null;
            try {
                connection = url.openConnection();
            } catch (IOException e) {
                throw new ResourceLoadException("Error opening connection", this, e, false);
            }
            connection.setRequestProperty("Accept", "application/xml");
            connection.setRequestProperty("Accept-Encoding", "gzip");
            try {
                connection.connect();
            } catch (IOException e) {
                failed(e, "Error connecting", false);
                continue;
            }
            if (connection instanceof HttpURLConnection) {
                httpConnection = (HttpURLConnection) connection;
                try {
                    responseCode = httpConnection.getResponseCode();
                } catch (IOException e) {
                    failed(e, "Error getting response code", true);
                    continue;
                }
                if ((responseCode / 100) != 2) {
                    failed(null, "Non 2XX response code: " + responseCode, true);
                    continue;
                }
            }
            try {
                urlInputStream = connection.getInputStream();
            } catch (IOException e) {
                failed(e, "Error opening input stream", true);
                continue;
            }
            String encoding = connection.getContentEncoding();
            if (encoding != null && encoding.toLowerCase().equals("gzip")) {
                try {
                    urlInputStream = new GZIPInputStream(urlInputStream);
                } catch (IOException e) {
                    failed(e, "Error ungzipping", true);
                    continue;
                }
            }
            lastModified = connection.getLastModified();
            contentLength = connection.getContentLength();
            eTag = connection.getHeaderField("ETag");
            logger.finer("RequiredResourceLoader - Done.");
            return urlInputStream;
        }
    }
private String endcodePassword(String password) throws UnsupportedEncodingException, NoSuchAlgorithmException {
        MessageDigest md = MessageDigest.getInstance("SHA");
        md.update(password.getBytes("UTF-8"));
        byte raw[] = md.digest();
        Base64 base64 = new Base64();
        String hash = new String(base64.encode(raw));
        return hash;
    }
public String getRssFeedUrl(boolean searchWeb) {
        String rssFeedUrl = null;
        if (entity.getNewsFeedUrl() != null & !entity.getUrl().equals("")) {
            return entity.getNewsFeedUrl();
        } else if (entity.getUrl() == null || entity.getUrl().equals("")) {
            return entity.getNewsFeedUrl();
        } else if (searchWeb) {
            HttpURLConnection con = null;
            InputStream is = null;
            try {
                URL url = new URL(entity.getUrl());
                con = (HttpURLConnection) url.openConnection();
                con.connect();
                is = con.getInputStream();
                InputStreamReader sr = new InputStreamReader(is);
                BufferedReader br = new BufferedReader(sr);
                String ln;
                StringBuffer sb = new StringBuffer();
                while ((ln = br.readLine()) != null) {
                    sb.append(ln + "\n");
                }
                rssFeedUrl = extractRssFeedUrl(sb.toString());
            } catch (Exception e) {
                log.error(e);
            } finally {
                if (is != null) {
                    try {
                        is.close();
                    } catch (IOException e) {
                        log.error(e);
                    }
                }
                if (con != null) {
                    con.disconnect();
                }
            }
        }
        return rssFeedUrl;
    }
public static File downloadFile(URL url, String filePath) throws IOException, ConnectException, UnknownHostException {
        File f = null;
        long t1 = System.currentTimeMillis();
        try {
            long t3 = System.currentTimeMillis();
            File tempDirectory = new File(tempDirectoryPath);
            if (!tempDirectory.exists()) {
                tempDirectory.mkdir();
            }
            String fName = normalizeFileName(filePath);
            f = new File(tempDirectoryPath + "/" + fName);
            logger.info("downloading '" + url.toString() + "' to: " + f.getAbsolutePath());
            f.deleteOnExit();
            DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(f)));
            byte[] buffer = new byte[1024 * 256];
            InputStream is = url.openStream();
            long readed = 0;
            for (int i = is.read(buffer); i > 0; i = is.read(buffer)) {
                dos.write(buffer, 0, i);
                readed += i;
            }
            dos.close();
            long t4 = System.currentTimeMillis();
            logger.debug("Download time: " + (t4 - t3));
        } catch (IOException io) {
            io.printStackTrace();
        }
        long t2 = System.currentTimeMillis();
        logger.debug("Total download method time: " + (t2 - t1));
        return f;
    }
public static File doRequestPost(URL url, String req, String fName, boolean override) throws ArcImsException {
        File f = null;
        URL virtualUrl = getVirtualRequestUrlFromUrlAndRequest(url, req);
        if ((f = getPreviousDownloadedURL(virtualUrl, override)) == null) {
            File tempDirectory = new File(tempDirectoryPath);
            if (!tempDirectory.exists()) {
                tempDirectory.mkdir();
            }
            String nfName = normalizeFileName(fName);
            f = new File(tempDirectoryPath + "/" + nfName);
            f.deleteOnExit();
            logger.info("downloading '" + url.toString() + "' to: " + f.getAbsolutePath());
            try {
                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                conn.setDoOutput(true);
                conn.setRequestMethod("POST");
                conn.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
                conn.setRequestProperty("Content-length", "" + req.length());
                OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
                wr.write(req);
                wr.flush();
                DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(f)));
                byte[] buffer = new byte[1024 * 256];
                InputStream is = conn.getInputStream();
                long readed = 0;
                for (int i = is.read(buffer); i > 0; i = is.read(buffer)) {
                    dos.write(buffer, 0, i);
                    readed += i;
                }
                dos.close();
                is.close();
                wr.close();
                addDownloadedURL(virtualUrl, f.getAbsolutePath());
            } catch (ConnectException ce) {
                logger.error("Timed out error", ce);
                throw new ArcImsException("arcims_server_timeout");
            } catch (FileNotFoundException fe) {
                logger.error("FileNotFound Error", fe);
                throw new ArcImsException("arcims_server_error");
            } catch (IOException e) {
                logger.error("IO Error", e);
                throw new ArcImsException("arcims_server_error");
            }
        }
        if (!f.exists()) {
            downloadedFiles.remove(virtualUrl);
            f = doRequestPost(url, req, fName, override);
        }
        return f;
    }
public static InputStream getRemoteIS(URL url, String post) throws ArcImsException {
        InputStream lector = null;
        try {
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setDoOutput(true);
            conn.setRequestMethod("POST");
            conn.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
            conn.setRequestProperty("Content-length", "" + post.length());
            OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
            wr.write(post);
            wr.flush();
            logger.info("downloading '" + url.toString());
            lector = conn.getInputStream();
        } catch (ConnectException e) {
            logger.error("Timed out error", e);
            throw new ArcImsException("arcims_server_timeout");
        } catch (ProtocolException e) {
            logger.error(e.getMessage(), e);
            throw new ArcImsException("arcims_server_error");
        } catch (IOException e) {
            logger.error(e.getMessage(), e);
            throw new ArcImsException("arcims_server_error");
        }
        return lector;
    }
public static String urlPost(Map<String, String> paraMap, String urlStr) throws IOException {
        String strParam = "";
        for (Map.Entry<String, String> entry : paraMap.entrySet()) {
            strParam = strParam + (entry.getKey() + "=" + entry.getValue()) + "&";
        }
        URL url = new URL(urlStr);
        URLConnection connection = url.openConnection();
        connection.setDoOutput(true);
        OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "utf-8");
        out.write(strParam);
        out.flush();
        out.close();
        String sCurrentLine;
        String sTotalString;
        sCurrentLine = "";
        sTotalString = "";
        InputStream l_urlStream;
        l_urlStream = connection.getInputStream();
        BufferedReader l_reader = new BufferedReader(new InputStreamReader(l_urlStream));
        while ((sCurrentLine = l_reader.readLine()) != null) {
            sTotalString += sCurrentLine + "\r\n";
        }
        System.out.println(sTotalString);
        return sTotalString;
    }
private static void unpackEntry(File destinationFile, ZipInputStream zin, ZipEntry entry) throws Exception {
        if (!entry.isDirectory()) {
            createFolders(destinationFile.getParentFile());
            FileOutputStream fis = new FileOutputStream(destinationFile);
            try {
                IOUtils.copy(zin, fis);
            } finally {
                zin.closeEntry();
                fis.close();
            }
        } else {
            createFolders(destinationFile);
        }
    }
@Override
        protected void copyContent(String filename) throws IOException {
            InputStream in = null;
            try {
                in = LOADER.getResourceAsStream(RES_PKG + filename);
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                IOUtils.copy(in, out);
                setResponseData(out.toByteArray());
            } finally {
                if (in != null) {
                    in.close();
                }
            }
        }
@Override
        protected void copyContent(String filename) throws IOException {
            InputStream in = null;
            try {
                String resourceDir = System.getProperty("resourceDir");
                File resource = new File(resourceDir, filename);
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                if (resource.exists()) {
                    in = new FileInputStream(resource);
                } else {
                    in = LOADER.getResourceAsStream(RES_PKG + filename);
                }
                IOUtils.copy(in, out);
                setResponseData(out.toByteArray());
            } finally {
                if (in != null) {
                    in.close();
                }
            }
        }
public void execute(File sourceFile, File destinationFile, Properties htmlCleanerConfig) {
        FileReader reader = null;
        Writer writer = null;
        try {
            reader = new FileReader(sourceFile);
            logger.info("Using source file: " + trimPath(userDir, sourceFile));
            if (!destinationFile.getParentFile().exists()) {
                createDirectory(destinationFile.getParentFile());
            }
            writer = new FileWriter(destinationFile);
            logger.info("Destination file:  " + trimPath(userDir, destinationFile));
            execute(reader, writer, htmlCleanerConfig);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (writer != null) {
                try {
                    writer.close();
                    writer = null;
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (reader != null) {
                try {
                    reader.close();
                    reader = null;
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
public static final void zip(final ZipOutputStream out, final File f, String base) throws Exception {
        if (f.isDirectory()) {
            final File[] fl = f.listFiles();
            base = base.length() == 0 ? "" : base + File.separator;
            for (final File element : fl) {
                zip(out, element, base + element.getName());
            }
        } else {
            out.putNextEntry(new org.apache.tools.zip.ZipEntry(base));
            final FileInputStream in = new FileInputStream(f);
            IOUtils.copyStream(in, out);
            in.close();
        }
        Thread.sleep(10);
    }
public void login(String username, String key) {
        if (isLogged()) {
            return;
        }
        if (null == this.username || null == this.key) {
            this.username = username;
            this.key = key;
        }
        final ProgressHandle handle = ProgressHandleFactory.createHandle("Logining into DreamHost");
        handle.start();
        working = true;
        fireChangeEvent();
        RequestProcessor.getDefault().post(new Runnable() {

            public void run() {
                try {
                    HttpsURLConnection connection = (HttpsURLConnection) urlGenerator(DreamHostCommands.CMD_DOMAIN_LIST_DOMAINS, null).openConnection();
                    String response = getResponse(connection);
                    Document document = builder.parse(new ByteArrayInputStream(response.getBytes()));
                    String result = document.getElementsByTagName("result").item(0).getTextContent();
                    logged = result.equals("success");
                } catch (SAXException ex) {
                    Logger.getLogger(DreamHostConnector.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                    Logger.getLogger(DreamHostConnector.class.getName()).log(Level.SEVERE, null, ex);
                } finally {
                    if (isLogged()) {
                        NbPreferences.forModule(DreamHostConnector.class).put("username", getUsername());
                        NbPreferences.forModule(DreamHostConnector.class).put("key", getKey());
                    }
                    handle.finish();
                    working = false;
                    fireChangeEvent();
                }
            }
        });
    }
public static String httpGetJson(final List<NameValuePair> nameValuePairs) {
        HttpClient httpclient = null;
        String data = "";
        URI uri = null;
        try {
            final String paramString = URLEncodedUtils.format(nameValuePairs, "utf-8");
            if (HTTPS) {
                final SchemeRegistry schemeRegistry = new SchemeRegistry();
                schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
                final HttpParams params = new BasicHttpParams();
                final SingleClientConnManager mgr = new SingleClientConnManager(params, schemeRegistry);
                httpclient = new DefaultHttpClient(mgr, params);
                uri = new URI(DEADDROPS_SERVER_URL_HTTPS + "?" + paramString);
            } else {
                httpclient = new DefaultHttpClient();
                uri = new URI(DEADDROPS_SERVER_URL + "?" + paramString);
            }
            final HttpGet request = new HttpGet();
            request.setURI(uri);
            final HttpResponse response = httpclient.execute(request);
            final BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
            String inputLine;
            while ((inputLine = in.readLine()) != null) data += inputLine;
            in.close();
        } catch (final URISyntaxException e) {
            e.printStackTrace();
            return null;
        } catch (final ClientProtocolException e) {
            e.printStackTrace();
            return null;
        } catch (final IOException e) {
            e.printStackTrace();
            return null;
        }
        return data;
    }
public boolean crear() {
        int result = 0;
        String sql = "insert into divisionxTorneo" + "(torneo_idTorneo, tipoTorneo_idTipoTorneo, nombreDivision, descripcion, numJugadores, numFechas, terminado, tipoDesempate, rondaActual, ptosxbye)" + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
        try {
            connection = conexionBD.getConnection();
            connection.setAutoCommit(false);
            ps = connection.prepareStatement(sql);
            populatePreparedStatement();
            result = ps.executeUpdate();
            connection.commit();
        } catch (SQLException ex) {
            ex.printStackTrace();
            try {
                connection.rollback();
            } catch (SQLException exe) {
                exe.printStackTrace();
            }
        } finally {
            conexionBD.close(ps);
            conexionBD.close(connection);
        }
        return (result > 0);
    }
public boolean actualizarDivisionActual(division div) {
        int intResult = 0;
        String sql = "UPDATE divisionxTorneo " + " SET tipoTorneo_idTipoTorneo = " + div.getidTipoTorneo() + " , nombreDivision = '" + div.getnombreDivision() + "', " + " descripcion = '" + div.getDescripcion() + "', tipoDesempate = " + div.getDesempate() + ", " + " numFechas = " + div.getnumFechas() + " , ptosxbye = " + div.getPtosxBye() + " WHERE idDivisionxTorneo = " + div.getidDivision();
        try {
            connection = conexionBD.getConnection();
            connection.setAutoCommit(false);
            ps = connection.prepareStatement(sql);
            intResult = ps.executeUpdate();
            connection.commit();
        } catch (SQLException ex) {
            ex.printStackTrace();
            try {
                connection.rollback();
            } catch (SQLException exe) {
                exe.printStackTrace();
            }
        } finally {
            conexionBD.close(ps);
            conexionBD.close(connection);
        }
        return (intResult > 0);
    }
public boolean actualizarEstadoDivision(division div) {
        int intResult = 0;
        String sql = "UPDATE divisionxTorneo " + " SET terminado = '1' " + " WHERE idDivisionxTorneo = " + div.getidDivision();
        try {
            connection = conexionBD.getConnection();
            connection.setAutoCommit(false);
            ps = connection.prepareStatement(sql);
            intResult = ps.executeUpdate();
            connection.commit();
        } catch (SQLException ex) {
            ex.printStackTrace();
            try {
                connection.rollback();
            } catch (SQLException exe) {
                exe.printStackTrace();
            }
        } finally {
            conexionBD.close(ps);
            conexionBD.close(connection);
        }
        return (intResult > 0);
    }