semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private String postData(String requestUrl, String atom) throws AuthenticationException, IOException {
        URL url = new URL(requestUrl);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("POST");
        conn.setDoOutput(true);
        String header;
        try {
            header = oauthAuthenticator.getHttpAuthorizationHeader(url.toString(), "POST", profile.getOAuthToken(), profile.getOAuthTokenSecret());
        } catch (OAuthException e) {
            throw new AuthenticationException(e);
        }
        conn.setRequestProperty("Authorization", header);
        conn.setRequestProperty("Content-Type", "application/atom+xml");
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(conn.getOutputStream()));
        writer.write(atom);
        writer.close();
        if (conn.getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED) {
            throw new AuthenticationException();
        }
        InputStreamReader reader = new InputStreamReader(conn.getInputStream());
        char[] buffer = new char[1024];
        int bytesRead = 0;
        StringBuilder data = new StringBuilder();
        while ((bytesRead = reader.read(buffer)) != -1) {
            data.append(buffer, 0, bytesRead);
        }
        reader.close();
        if (conn.getResponseCode() != HttpURLConnection.HTTP_CREATED) {
            throw new IOException(conn.getResponseCode() + " " + conn.getResponseMessage() + "\n" + data);
        }
        return data.toString();
    }
public StringBuffer getReturn(String url_address) {
        StringBuffer message = new StringBuffer();
        try {
            URL url = new URL(url_address);
            try {
                HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection();
                httpConnection.connect();
                InputStreamReader insr = new InputStreamReader(httpConnection.getInputStream());
                BufferedReader in = new BufferedReader(insr);
                String temp = in.readLine();
                while (temp != null) {
                    message.append(temp + "\n");
                    temp = in.readLine();
                }
                in.close();
            } catch (IOException e) {
                System.out.println("httpConnecter:Error[" + e + "]");
                message.append("Connect error [" + url_address + "]");
            }
        } catch (MalformedURLException e) {
            message.append("Connect error [" + url_address + "]");
            System.out.println("httpConneter:Error[" + e.getMessage() + "]");
        } catch (Exception e) {
            message.append("Connect error [" + url_address + "]");
            System.out.println("httpConneter:Error[" + e.getMessage() + "]");
        }
        return message;
    }
public ODFSignatureService(TimeStampServiceValidator timeStampServiceValidator, RevocationDataService revocationDataService, SignatureFacet signatureFacet, InputStream documentInputStream, OutputStream documentOutputStream, TimeStampService timeStampService, String role, IdentityDTO identity, byte[] photo, DigestAlgo digestAlgo) throws Exception {
        super(digestAlgo);
        this.temporaryDataStorage = new HttpSessionTemporaryDataStorage();
        this.documentOutputStream = documentOutputStream;
        this.tmpFile = File.createTempFile("eid-dss-", ".odf");
        FileOutputStream fileOutputStream;
        fileOutputStream = new FileOutputStream(this.tmpFile);
        IOUtils.copy(documentInputStream, fileOutputStream);
        addSignatureFacet(new XAdESXLSignatureFacet(timeStampService, revocationDataService, getSignatureDigestAlgorithm()));
        addSignatureFacet(signatureFacet);
        XAdESSignatureFacet xadesSignatureFacet = super.getXAdESSignatureFacet();
        xadesSignatureFacet.setRole(role);
        if (null != identity) {
            IdentitySignatureFacet identitySignatureFacet = new IdentitySignatureFacet(identity, photo, getSignatureDigestAlgorithm());
            addSignatureFacet(identitySignatureFacet);
        }
    }
public URI normalize(final URI uri) {
        URI normalizedUri = super.normalize(uri);
        if (normalizedUri.equals(uri)) {
            String resourceName = uri.toString().replaceAll(".*(\\\\+|/)", "");
            if (!containsNormalizedUriKey(uri)) {
                for (Iterator<Path> iterator = this.iteratorModulePaths(); iterator.hasNext(); ) {
                    String searchPath = iterator.next().getPath();
                    String completePath = this.normalizePath(searchPath + '/' + resourceName);
                    try {
                        InputStream stream = null;
                        URL url = toURL(completePath);
                        if (url != null) {
                            try {
                                stream = url.openStream();
                                stream.close();
                            } catch (Exception exception) {
                                url = null;
                            } finally {
                                stream = null;
                            }
                            if (url != null) {
                                normalizedUri = URIUtil.createUri(url.toString());
                                this.putNormalizedUri(uri, normalizedUri);
                                break;
                            }
                        }
                    } catch (Exception exception) {
                    }
                }
            } else {
                normalizedUri = getNormalizedUri(uri);
            }
        }
        return normalizedUri;
    }
private SecretKey getSecretKey() {
        try {
            String path = "/org.dbreplicator/repconsole/secretKey.obj";
            java.net.URL url1 = getClass().getResource(path);
            ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(url1.openStream()));
            SecretKey sk = (SecretKey) ois.readObject();
            return sk;
        } catch (IOException ex) {
        } catch (ClassNotFoundException ex) {
        }
        return null;
    }
public void sendContent(OutputStream out, Range range, Map<String, String> params, String contentType) throws IOException {
        LOGGER.debug("GET REQUEST OR RESPONSE - Send content: " + file.getAbsolutePath());
        FileInputStream in = null;
        try {
            in = new FileInputStream(file);
            int bytes = IOUtils.copy(in, out);
            LOGGER.debug("wrote bytes:  " + bytes);
            out.flush();
        } finally {
            IOUtils.closeQuietly(in);
        }
    }
public void run() {
        BufferedReader inp = null;
        try {
            String urlString = "http://www.hubtracker.com/query.php?action=add&username=" + user + "&password=" + pass + "&email=" + e_mail + "&address=" + Vars.Hub_Host;
            URL url = new URL(urlString);
            URLConnection conn;
            if (!Vars.Proxy_Host.equals("")) conn = url.openConnection(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(Vars.Proxy_Host, Vars.Proxy_Port))); else conn = url.openConnection();
            conn.setDoInput(true);
            conn.setDoOutput(true);
            conn.connect();
            inp = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String xx;
            while ((xx = inp.readLine()) != null) PluginMain.result += "\n" + xx;
            if (curCmd != null) this.curCmd.cur_client.sendFromBot("[hubtracker:] " + PluginMain.result); else PluginMain.curFrame.showMsg();
            inp.close();
            inp = null;
        } catch (MalformedURLException ue) {
            PluginMain.result = ue.toString();
        } catch (Exception e) {
            PluginMain.result = e.toString();
        }
        done = true;
    }
public static void copiaAnexos(String from, String to, AnexoTO[] anexoTO) {
        FileChannel in = null, out = null;
        for (int i = 0; i < anexoTO.length; i++) {
            try {
                in = new FileInputStream(new File((uploadDiretorio.concat(from)).concat(File.separator + anexoTO[i].getNome()))).getChannel();
                out = new FileOutputStream(new File((uploadDiretorio.concat(to)).concat(File.separator + anexoTO[i].getNome()))).getChannel();
                long size = in.size();
                MappedByteBuffer buf = in.map(FileChannel.MapMode.READ_ONLY, 0, size);
                out.write(buf);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (in != null) try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (out != null) try {
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
public void upload(String ftpServer, String user, String password, String fileName, File source) throws MalformedURLException, IOException {
        if (ftpServer != null && fileName != null && source != null) {
            StringBuffer sb = new StringBuffer("ftp://");
            if (user != null && password != null) {
                sb.append(user);
                sb.append(':');
                sb.append(password);
                sb.append('@');
            }
            sb.append(ftpServer);
            sb.append('/');
            sb.append(fileName);
            sb.append(";type=i");
            BufferedInputStream bis = null;
            BufferedOutputStream bos = null;
            try {
                URL url = new URL(sb.toString());
                URLConnection urlc = url.openConnection();
                bos = new BufferedOutputStream(urlc.getOutputStream());
                bis = new BufferedInputStream(new FileInputStream(source));
                int i;
                while ((i = bis.read()) != -1) {
                    bos.write(i);
                }
            } finally {
                if (bis != null) try {
                    bis.close();
                } catch (IOException ioe) {
                    ioe.printStackTrace();
                }
                if (bos != null) try {
                    bos.close();
                } catch (IOException ioe) {
                    ioe.printStackTrace();
                }
            }
        } else {
            System.out.println("Input not available.");
        }
    }
public void download(String ftpServer, String user, String password, String fileName, File destination) throws MalformedURLException, IOException {
        if (ftpServer != null && fileName != null && destination != null) {
            StringBuffer sb = new StringBuffer("ftp://");
            if (user != null && password != null) {
                sb.append(user);
                sb.append(':');
                sb.append(password);
                sb.append('@');
            }
            sb.append(ftpServer);
            sb.append('/');
            sb.append(fileName);
            sb.append(";type=i");
            BufferedInputStream bis = null;
            BufferedOutputStream bos = null;
            try {
                URL url = new URL(sb.toString());
                URLConnection urlc = url.openConnection();
                bis = new BufferedInputStream(urlc.getInputStream());
                bos = new BufferedOutputStream(new FileOutputStream(destination));
                int i;
                while ((i = bis.read()) != -1) {
                    bos.write(i);
                }
            } finally {
                if (bis != null) try {
                    bis.close();
                } catch (IOException ioe) {
                    ioe.printStackTrace();
                }
                if (bos != null) try {
                    bos.close();
                } catch (IOException ioe) {
                    ioe.printStackTrace();
                }
            }
        } else {
            System.out.println("Input not available");
        }
    }
@Override
    public void copierPhotos(FileInputStream fichierACopier, FileOutputStream fichierDestination) {
        FileChannel in = null;
        FileChannel out = null;
        try {
            in = fichierACopier.getChannel();
            out = fichierDestination.getChannel();
            in.transferTo(0, in.size(), out);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                }
            }
            if (out != null) {
                try {
                    out.close();
                } catch (IOException e) {
                }
            }
        }
    }
public static String loadUrl(URL url, String charset) throws MyException {
        try {
            URLConnection conn = url.openConnection();
            InputStream urlin = conn.getInputStream();
            BufferedReader in = new BufferedReader(new InputStreamReader(urlin, charset));
            StringBuffer buff = new StringBuffer();
            char[] cbuf = new char[1028];
            int count;
            while ((count = in.read(cbuf)) != -1) {
                buff.append(new String(cbuf, 0, count));
            }
            return buff.toString();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            throw new MyException(MyException.ERROR_FILENOTFOUND, e.getMessage());
        } catch (IOException e) {
            e.printStackTrace();
            throw new MyException(MyException.ERROR_IO, e.getMessage());
        }
    }
public boolean check(String password) throws UnsupportedEncodingException, NoSuchAlgorithmException {
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(username.getBytes("ISO-8859-1"));
        md.update((byte) ':');
        md.update(realm.getBytes("ISO-8859-1"));
        md.update((byte) ':');
        md.update(password.getBytes("ISO-8859-1"));
        byte[] ha1 = md.digest();
        String hexHa1 = new String(Hex.encodeHex(ha1));
        md.reset();
        md.update(method.getBytes("ISO-8859-1"));
        md.update((byte) ':');
        md.update(uri.getBytes("ISO-8859-1"));
        byte[] ha2 = md.digest();
        String hexHa2 = new String(Hex.encodeHex(ha2));
        md.reset();
        md.update(hexHa1.getBytes("ISO-8859-1"));
        md.update((byte) ':');
        md.update(nonce.getBytes("ISO-8859-1"));
        md.update((byte) ':');
        md.update(nc.getBytes("ISO-8859-1"));
        md.update((byte) ':');
        md.update(cnonce.getBytes("ISO-8859-1"));
        md.update((byte) ':');
        md.update(qop.getBytes("ISO-8859-1"));
        md.update((byte) ':');
        md.update(hexHa2.getBytes("ISO-8859-1"));
        byte[] digest = md.digest();
        String hexDigest = new String(Hex.encodeHex(digest));
        return (hexDigest.equalsIgnoreCase(response));
    }
protected void copyFile(File src, File dest) throws Exception {
            FileChannel srcChannel = new FileInputStream(src).getChannel();
            FileChannel destChannel = new FileOutputStream(dest).getChannel();
            long transferred = destChannel.transferFrom(srcChannel, 0, srcChannel.size());
            if (transferred != srcChannel.size()) throw new Exception("Could not transfer entire file");
            srcChannel.close();
            destChannel.close();
        }
private static String md5(String pwd) {
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(pwd.getBytes(), 0, pwd.length());
            return new BigInteger(1, md5.digest()).toString(16);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            throw new Error();
        }
    }
public void insertJobLog(String userId, String[] checkId, String checkType, String objType) throws Exception {
        DBOperation dbo = null;
        Connection connection = null;
        PreparedStatement preStm = null;
        String sql = "insert into COFFICE_JOBLOG_CHECKAUTH (USER_ID,CHECK_ID,CHECK_TYPE,OBJ_TYPE) values (?,?,?,?)";
        String cleanSql = "delete from COFFICE_JOBLOG_CHECKAUTH where " + "user_id = '" + userId + "' and check_type = '" + checkType + "' and obj_type = '" + objType + "'";
        try {
            dbo = createDBOperation();
            connection = dbo.getConnection();
            connection.setAutoCommit(false);
            preStm = connection.prepareStatement(cleanSql);
            int dCount = preStm.executeUpdate();
            String sHaveIns = ",";
            preStm = connection.prepareStatement(sql);
            for (int j = 0; j < checkId.length; j++) {
                if (sHaveIns.indexOf("," + checkId[j] + ",") < 0) {
                    preStm.setInt(1, Integer.parseInt(userId));
                    preStm.setInt(2, Integer.parseInt(checkId[j]));
                    preStm.setInt(3, Integer.parseInt(checkType));
                    preStm.setInt(4, Integer.parseInt(objType));
                    preStm.executeUpdate();
                    sHaveIns += checkId[j] + ",";
                }
            }
            connection.commit();
        } catch (Exception ex) {
            log.debug((new Date().toString()) + " ������Ȩ��ʧ��! ");
            try {
                connection.rollback();
            } catch (SQLException e) {
                throw e;
            }
            throw ex;
        } finally {
            close(null, null, preStm, connection, dbo);
        }
    }
public void parse(ParserEvent event) {
        logger.debug("parse() called for link " + event.getLink().getURI());
        if (event.getLink().getURI().matches(itemFilter)) {
            logger.debug("Content " + event.getLink().getURI() + " matched");
            Statement stmt = null;
            ResultSet rs = null;
            long checksum1 = 0;
            try {
                URL url = new URL(event.getLink().getURI());
                checksum1 = url.openConnection().getLastModified();
            } catch (MalformedURLException mfe) {
                logger.error("Malformed url " + event.getLink().getURI() + " - " + mfe.getMessage());
                return;
            } catch (IOException ioe) {
                logger.error("Couldn't read " + event.getLink().getURI() + " - " + ioe.getMessage());
                return;
            }
            if ((checksum1 == 0) || (checksum1 == 1)) {
                Adler32 adler32 = new Adler32();
                NodeList nodes = (NodeList) event.getPageData().getData();
                adler32.update(nodes.toHtml().getBytes());
                checksum1 = adler32.getValue();
            }
            try {
                stmt = conn.createStatement();
                rs = stmt.executeQuery("SELECT * FROM documents WHERE url='" + event.getLink().getURI() + "'");
                if (rs.first()) {
                    long checksum2 = rs.getLong("checksum");
                    if (checksum1 == checksum2) {
                        stmt.executeUpdate("UPDATE documents SET checked=" + String.valueOf(System.currentTimeMillis()) + " WHERE id=" + rs.getString("id"));
                    } else {
                        stmt.executeUpdate("UPDATE documents SET checksum=" + checksum1 + ", checked=" + String.valueOf(System.currentTimeMillis()) + " WHERE id=" + rs.getString("id"));
                    }
                } else {
                    stmt.executeUpdate("INSERT INTO documents VALUES " + "(DEFAULT, '" + event.getLink().getURI() + "', " + checksum1 + ", '" + providerId + "', " + String.valueOf(System.currentTimeMillis()) + ")");
                }
            } catch (SQLException e) {
                logger.error("Could't perform database query or update - " + e.getMessage());
            } finally {
                if (rs != null) {
                    try {
                        rs.close();
                    } catch (SQLException sqlEx) {
                    }
                    rs = null;
                }
                if (stmt != null) {
                    try {
                        stmt.close();
                    } catch (SQLException sqlEx) {
                    }
                    stmt = null;
                }
            }
        }
    }
public void getHttpURL() throws Exception {
        boolean display = true;
        boolean allHeaders = false;
        String url = null;
        url = "http://localhost/cubigraf2";
        url = "http://www.accenture.com/NR/rdonlyres/971C4EEE-24E2-4BAA-8C7B-D5A5133D5968/0/en_sprout.jpg";
        url = "http://www.uni.pt/img/home-direito.gif";
        url = "http://www.google.com";
        URLConnection uc = new URL(url).openConnection();
        println("HEADERS:");
        if (allHeaders) {
            Iterator<Map.Entry<String, List<String>>> itHeaders = uc.getHeaderFields().entrySet().iterator();
            while (itHeaders.hasNext()) {
                Map.Entry<String, List<String>> e = itHeaders.next();
                Iterator<?> itValues = e.getValue().iterator();
                while (itValues.hasNext()) {
                    println(e.getKey() + ": " + itValues.next());
                }
            }
        } else {
            showObjectProperty(uc, "getContentEncoding");
            showObjectProperty(uc, "getContentLength");
            showObjectProperty(uc, "getContentType");
            showObjectProperty(uc, "getDate", FORMAT.TIMESTAMP);
            showObjectProperty(uc, "getExpiration", FORMAT.TIMESTAMP);
            showObjectProperty(uc, "getLastModified", FORMAT.TIMESTAMP);
        }
        ExtendedInputStream in = new ExtendedInputStream(uc.getInputStream(), url.toString());
        if (display) {
            println("BODY:");
            ExtendedReader reader = new ExtendedReader(in);
            for (String s = reader.readLine(); s != null; s = reader.readLine()) {
                println(s);
            }
        } else {
            println("(BODY saved to a file)");
            String contentType = uc.getContentType();
            StringBuilder filename = new StringBuilder("C:\\Documents and Settings\\Carlos_da_S_Pereira\\Desktop\\JAVA_NET_TESTS");
            filename.append(".");
            filename.append(contentType.substring(contentType.indexOf("/") + 1));
            File file = new File(filename.toString());
            ExtendedOutputStream out = new ExtendedOutputStream(new FileOutputStream(file), file.getAbsolutePath());
            Streams.copy(in, out);
            out.close();
        }
        in.close();
    }
@Test
    public void testWriteAndReadBigger() throws Exception {
        JCFSFileServer server = new JCFSFileServer(defaultTcpPort, defaultTcpAddress, defaultUdpPort, defaultUdpAddress, dir, 0, 0);
        JCFS.configureDiscovery(defaultUdpAddress, defaultUdpPort);
        try {
            server.start();
            RFile file = new RFile("testreadwrite.txt");
            RFileOutputStream out = new RFileOutputStream(file);
            String body = "";
            int size = 50 * 1024;
            for (int i = 0; i < size; i++) {
                body = body + "a";
            }
            out.write(body.getBytes("utf-8"));
            out.close();
            File expected = new File(dir, "testreadwrite.txt");
            assertTrue(expected.isFile());
            assertEquals(body.length(), expected.length());
            RFileInputStream in = new RFileInputStream(file);
            byte[] buffer = new byte[body.length()];
            int readCount = in.read(buffer);
            in.close();
            assertEquals(body.length(), readCount);
            String resultRead = new String(buffer, "utf-8");
            assertEquals(body, resultRead);
        } finally {
            server.stop();
        }
    }