semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public boolean deleteByQuery(String query, int coreId) {
        try {
            URL url = new URL(solrUrl + "/core" + coreId + "/update");
            URLConnection conn = url.openConnection();
            conn.setDoOutput(true);
            conn.setRequestProperty("Content-type", "text/xml");
            conn.setRequestProperty("charset", "utf-8");
            OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
            System.out.println("******************" + query);
            wr.write("<delete><query>" + query + "</query></delete>");
            wr.flush();
            BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String line;
            while ((line = rd.readLine()) != null) {
                System.out.println(line);
            }
            wr.close();
            rd.close();
            conn = url.openConnection();
            conn.setDoOutput(true);
            conn.setRequestProperty("Content-type", "text/xml");
            conn.setRequestProperty("charset", "utf-8");
            wr = new OutputStreamWriter(conn.getOutputStream());
            wr.write("<commit/>");
            wr.flush();
            rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            while ((line = rd.readLine()) != null) {
                System.out.println(line);
            }
            wr.close();
            rd.close();
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
public boolean optimize(int coreId) {
        try {
            URL url = new URL(solrUrl + "/core" + coreId + "/update");
            URLConnection conn = url.openConnection();
            conn.setDoOutput(true);
            conn.setRequestProperty("Content-type", "text/xml");
            conn.setRequestProperty("charset", "utf-8");
            OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
            System.out.println("******************optimizing");
            wr.write("<optimize/>");
            wr.flush();
            BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String line;
            while ((line = rd.readLine()) != null) {
                System.out.println(line);
            }
            wr.close();
            rd.close();
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
public static void copyFile(File src, File dst) throws IOException {
        FileInputStream fis = null;
        FileOutputStream fos = null;
        fis = new FileInputStream(src);
        fos = new FileOutputStream(dst);
        byte[] buffer = new byte[16384];
        int read = 0;
        while ((read = fis.read(buffer)) != -1) {
            fos.write(buffer, 0, read);
        }
        fis.close();
        fos.flush();
        fos.close();
    }
public void serialize(OutputStream out) throws IOException, BadIMSCPException {
        ensureParsed();
        ZipFilePackageParser parser = utils.getIMSCPParserFactory().createParser();
        parser.setContentPackage(cp);
        if (on_disk != null) on_disk.delete();
        on_disk = createTemporaryFile();
        parser.serialize(on_disk);
        InputStream in = new FileInputStream(on_disk);
        IOUtils.copy(in, out);
    }
private synchronized void ensureParsed() throws IOException, BadIMSCPException {
        if (cp != null) return;
        if (on_disk == null) {
            on_disk = createTemporaryFile();
            OutputStream to_disk = new FileOutputStream(on_disk);
            IOUtils.copy(in.getInputStream(), to_disk);
            to_disk.close();
        }
        try {
            ZipFilePackageParser parser = utils.getIMSCPParserFactory().createParser();
            parser.parse(on_disk);
            cp = parser.getPackage();
        } catch (BadParseException x) {
            throw new BadIMSCPException("Cannot parse content package", x);
        }
    }
public String connectToServlet() {
        URL urlStory = null;
        BufferedReader brStory;
        String result = "";
        try {
            urlStory = new URL(getCodeBase(), "http://localhost:8080/javawebconsole/ToApplet");
        } catch (MalformedURLException MUE) {
            MUE.printStackTrace();
        }
        try {
            brStory = new BufferedReader(new InputStreamReader(urlStory.openStream()));
            while (brStory.ready()) {
                result += brStory.readLine();
            }
        } catch (IOException IOE) {
            IOE.printStackTrace();
        }
        return result;
    }
@Override
    protected String doInBackground(String... params) {
        Bitmap bm = null;
        if (params.length == 0) return null;
        String urlStr = params[0];
        url = urlStr;
        String md5 = "";
        try {
            md5 = md5(urlStr);
            File f = context.getFileStreamPath(md5 + FILE_EXT);
            if (f.exists()) {
                return f.getAbsolutePath();
            }
        } catch (FileNotFoundException fnf) {
        } catch (Exception e1) {
        }
        InputStream is = null;
        try {
            if (urlStr != null && url.indexOf("http://{HOST}:{PORT}") != -1) {
                urlStr = urlStr.replace("{HOST}", ConnectionHandler.host);
                urlStr = urlStr.replace("{PORT}", ConnectionHandler.port + "");
            }
            URL url = new URL(urlStr);
            URLConnection conn = url.openConnection();
            conn.connect();
            is = conn.getInputStream();
            bm = BitmapFactory.decodeStream(is);
        } catch (IOException e) {
            Log.i(TAG, "Download of image failed: " + e.getMessage());
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                }
            }
        }
        if (bm != null) {
            FileOutputStream fos = null;
            try {
                fos = context.openFileOutput(md5 + FILE_EXT, Context.MODE_WORLD_READABLE);
                bm.compress(CompressFormat.JPEG, 90, fos);
            } catch (Exception e) {
                Log.e(TAG, "Storage of image failed: " + e.getMessage());
            } finally {
                if (fos != null) {
                    try {
                        fos.flush();
                        fos.close();
                    } catch (IOException e) {
                    }
                }
                if (bm != null) {
                    bm.recycle();
                }
            }
        }
        File f = context.getFileStreamPath(md5 + FILE_EXT);
        if (f.exists()) {
            return f.getAbsolutePath();
        }
        return null;
    }
protected static String md5(String s) throws Exception {
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(s.getBytes());
        byte digest[] = md.digest();
        StringBuffer result = new StringBuffer();
        for (int i = 0; i < digest.length; i++) {
            result.append(Integer.toHexString(0xFF & digest[i]));
        }
        return result.toString();
    }
public URLConnection makeURLConnection(String server) throws IOException {
        if (server == null) {
            connection = null;
        } else {
            URL url = new URL("http://" + server + "/Bob/QueryXindice");
            connection = url.openConnection();
            connection.setDoOutput(true);
        }
        return connection;
    }
public void connect() throws FTPException {
        try {
            ftp = new FTPClient();
            ftp.connect(host);
            if (FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
                ftp.login(this.username, this.password);
            } else {
                ftp.disconnect();
                throw new FTPException("Não foi possivel se conectar no servidor FTP");
            }
            isConnected = true;
        } catch (Exception ex) {
            throw new FTPException(ex);
        }
    }
public static String post(String strUrl, String strPostString) {
        try {
            URL url = new URL(strUrl);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("POST");
            conn.setDoInput(true);
            conn.setDoOutput(true);
            conn.setUseCaches(true);
            conn.setAllowUserInteraction(true);
            conn.setFollowRedirects(true);
            conn.setInstanceFollowRedirects(true);
            conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            DataOutputStream out = new DataOutputStream(conn.getOutputStream());
            out.writeBytes(strPostString);
            out.flush();
            out.close();
            BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String s = "";
            String sRet = "";
            while ((s = in.readLine()) != null) {
                sRet += s;
            }
            in.close();
            return sRet;
        } catch (MalformedURLException e) {
            System.out.println("Internal Error. Malformed URL.");
            e.printStackTrace();
        } catch (IOException e) {
            System.out.println("Internal I/O Error.");
            e.printStackTrace();
        }
        return "";
    }
public static String get(String strUrl) {
        try {
            URL url = new URL(strUrl);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setDoInput(true);
            conn.setDoOutput(true);
            conn.setUseCaches(true);
            conn.setAllowUserInteraction(true);
            conn.setFollowRedirects(true);
            conn.setInstanceFollowRedirects(true);
            conn.setRequestProperty("User-Agent:", "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; de-de) AppleWebKit/523.12.2 (KHTML, like Gecko) Version/3.0.4 Safari/523.12.2");
            BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String s = "";
            String sRet = "";
            while ((s = in.readLine()) != null) {
                sRet += '\n' + s;
            }
            return sRet;
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
public HttpURLConnection getConnection(String urlString) throws IOException {
        URL url = new URL(urlString);
        HttpURLConnection connection = null;
        if (_proxy == null) {
            connection = (HttpURLConnection) url.openConnection();
        } else {
            URLConnection con = url.openConnection(_proxy);
            String encodedUserPwd = new String(Base64.encodeBase64((_username + ":" + _password).getBytes()));
            con.setRequestProperty("Proxy-Authorization", "Basic " + encodedUserPwd);
            connection = (HttpURLConnection) con;
        }
        return connection;
    }
public static void sendSimpleHTMLMessage(Map<String, String> recipients, String object, String htmlContent, String from) {
        String message;
        try {
            File webinfDir = ClasspathUtils.getClassesDir().getParentFile();
            File mailDir = new File(webinfDir, "mail");
            File templateFile = new File(mailDir, "HtmlMessageTemplate.html");
            StringWriter sw = new StringWriter();
            Reader r = new BufferedReader(new FileReader(templateFile));
            IOUtils.copy(r, sw);
            sw.close();
            message = sw.getBuffer().toString();
            message = message.replaceAll("%MESSAGE_HTML%", htmlContent).replaceAll("%APPLICATION_URL%", FGDSpringUtils.getExternalServerURL());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        Properties prop = getRealSMTPServerProperties();
        if (prop != null) {
            try {
                MimeMultipart multipart = new MimeMultipart("related");
                BodyPart messageBodyPart = new MimeBodyPart();
                messageBodyPart.setContent(message, "text/html");
                multipart.addBodyPart(messageBodyPart);
                sendHTML(recipients, object, multipart, from);
            } catch (MessagingException e) {
                throw new RuntimeException(e);
            }
        } else {
            StringBuffer contenuCourriel = new StringBuffer();
            for (Entry<String, String> recipient : recipients.entrySet()) {
                if (recipient.getValue() == null) {
                    contenuCourriel.append("À : " + recipient.getKey());
                } else {
                    contenuCourriel.append("À : " + recipient.getValue() + "<" + recipient.getKey() + ">");
                }
                contenuCourriel.append("\n");
            }
            contenuCourriel.append("Sujet : " + object);
            contenuCourriel.append("\n");
            contenuCourriel.append("Message : ");
            contenuCourriel.append("\n");
            contenuCourriel.append(message);
        }
    }
public static void copyFile(File in, File out) throws IOException {
        FileChannel inChannel = new FileInputStream(in).getChannel();
        FileChannel outChannel = new FileOutputStream(out).getChannel();
        try {
            inChannel.transferTo(0, inChannel.size(), outChannel);
        } finally {
            if (inChannel != null) inChannel.close();
            if (outChannel != null) outChannel.close();
        }
    }
public static TestResponse post(String urlString, byte[] data, String contentType, String accept) throws IOException {
        HttpURLConnection httpCon = null;
        byte[] result = null;
        byte[] errorResult = null;
        try {
            URL url = new URL(urlString);
            httpCon = (HttpURLConnection) url.openConnection();
            httpCon.setDoOutput(true);
            httpCon.setRequestMethod("POST");
            httpCon.setRequestProperty("Content-Type", contentType);
            httpCon.setRequestProperty("Accept", accept);
            if (data != null) {
                OutputStream output = httpCon.getOutputStream();
                output.write(data);
                output.close();
            }
            BufferedInputStream in = new BufferedInputStream(httpCon.getInputStream());
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            int next = in.read();
            while (next > -1) {
                os.write(next);
                next = in.read();
            }
            os.flush();
            result = os.toByteArray();
            os.close();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            InputStream errorStream = httpCon.getErrorStream();
            if (errorStream != null) {
                BufferedInputStream errorIn = new BufferedInputStream(errorStream);
                ByteArrayOutputStream errorOs = new ByteArrayOutputStream();
                int errorNext = errorIn.read();
                while (errorNext > -1) {
                    errorOs.write(errorNext);
                    errorNext = errorIn.read();
                }
                errorOs.flush();
                errorResult = errorOs.toByteArray();
                errorOs.close();
            }
            return new TestResponse(httpCon.getResponseCode(), errorResult, result);
        }
    }
public static TestResponse get(String urlString, String accept) throws IOException {
        HttpURLConnection httpCon = null;
        byte[] result = null;
        byte[] errorResult = null;
        try {
            URL url = new URL(urlString);
            httpCon = (HttpURLConnection) url.openConnection();
            httpCon.setRequestMethod("GET");
            httpCon.setRequestProperty("Accept", accept);
            BufferedInputStream in = new BufferedInputStream(httpCon.getInputStream());
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            int next = in.read();
            while (next > -1) {
                os.write(next);
                next = in.read();
            }
            os.flush();
            result = os.toByteArray();
            os.close();
        } catch (IOException e) {
        } finally {
            InputStream errorStream = httpCon.getErrorStream();
            if (errorStream != null) {
                BufferedInputStream errorIn = new BufferedInputStream(errorStream);
                ByteArrayOutputStream errorOs = new ByteArrayOutputStream();
                int errorNext = errorIn.read();
                while (errorNext > -1) {
                    errorOs.write(errorNext);
                    errorNext = errorIn.read();
                }
                errorOs.flush();
                errorResult = errorOs.toByteArray();
                errorOs.close();
            }
            return new TestResponse(httpCon.getResponseCode(), errorResult, result);
        }
    }
public static void copyFile(File in, File out) throws FileNotFoundException, IOException {
        FileChannel sourceChannel = null;
        FileChannel destinationChannel = null;
        try {
            sourceChannel = new FileInputStream(in).getChannel();
            destinationChannel = new FileOutputStream(out).getChannel();
            sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
        } finally {
            try {
                sourceChannel.close();
            } catch (Exception ex) {
            }
            try {
                destinationChannel.close();
            } catch (Exception ex) {
            }
        }
    }
public static int copyFile(File src, File dest) throws IOException {
        FileChannel in = null, out = null;
        try {
            in = new FileInputStream(src).getChannel();
            out = new FileOutputStream(dest).getChannel();
            in.transferTo(0, in.size(), out);
        } finally {
            if (in != null) in.close();
            if (out != null) out.close();
        }
        return 1;
    }
private void copyResource() throws Exception {
        URL url = getResource(source);
        InputStream input;
        if (url != null) {
            input = url.openStream();
        } else if (new File(source).exists()) {
            input = new FileInputStream(source);
        } else {
            throw new Exception("Could not load resource: " + source);
        }
        OutputStream output = new FileOutputStream(destinationFile());
        int b;
        while ((b = input.read()) != -1) output.write(b);
        input.close();
        output.close();
    }
public static void copy(FileInputStream from, FileOutputStream to) throws IOException {
        FileChannel fromChannel = from.getChannel();
        FileChannel toChannel = to.getChannel();
        copy(fromChannel, toChannel);
        fromChannel.close();
        toChannel.close();
    }
private static void init(String url) throws Exception {
        XMLReader reader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
        reader.setContentHandler(new ConfigurationHandler());
        InputSource isource = new InputSource((new URL(url)).openStream());
        isource.setSystemId(url);
        reader.parse(isource);
    }
public void delUser(User user) throws SQLException, IOException, ClassNotFoundException {
        String dbUserID;
        String stockSymbol;
        Statement stmt = con.createStatement();
        try {
            con.setAutoCommit(false);
            dbUserID = user.getUserID();
            if (getUser(dbUserID) != null) {
                ResultSet rs1 = stmt.executeQuery("SELECT userID, symbol " + "FROM UserStocks WHERE userID = '" + dbUserID + "'");
                while (rs1.next()) {
                    try {
                        stockSymbol = rs1.getString("symbol");
                        delUserStocks(dbUserID, stockSymbol);
                    } catch (SQLException ex) {
                        throw new SQLException("Deletion of user stock holding failed: " + ex.getMessage());
                    }
                }
                try {
                    stmt.executeUpdate("DELETE FROM Users WHERE " + "userID = '" + dbUserID + "'");
                } catch (SQLException ex) {
                    throw new SQLException("User deletion failed: " + ex.getMessage());
                }
            } else throw new IOException("User not found in database - cannot delete.");
            try {
                con.commit();
            } catch (SQLException ex) {
                throw new SQLException("Transaction commit failed: " + ex.getMessage());
            }
        } catch (SQLException ex) {
            try {
                con.rollback();
            } catch (SQLException sqx) {
                throw new SQLException("Transaction failed then rollback failed: " + sqx.getMessage());
            }
            throw new SQLException("Transaction failed; was rolled back: " + ex.getMessage());
        }
        stmt.close();
    }
public void covertFile(File file) throws IOException {
        if (!file.isFile()) {
            return;
        }
        Reader reader = null;
        OutputStream os = null;
        File newfile = null;
        String filename = file.getName();
        boolean succeed = false;
        try {
            newfile = new File(file.getParentFile(), filename + ".bak");
            reader = new InputStreamReader(new FileInputStream(file), fromEncoding);
            os = new FileOutputStream(newfile);
            IOUtils.copy(reader, os, toEncoding);
        } catch (Exception e) {
            e.printStackTrace();
            throw new IOException("Encoding error for file [" + file.getAbsolutePath() + "]");
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (os != null) {
                try {
                    os.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        try {
            file.delete();
            succeed = newfile.renameTo(file);
        } catch (Exception e) {
            throw new IOException("Clear bak error for file [" + file.getAbsolutePath() + "]");
        }
        if (succeed) {
            System.out.println("Changed encoding for file [" + file.getAbsolutePath() + "]");
        }
    }
public static String[] check() throws Exception {
        if (currentVersion == null) throw new Exception();
        URL url = new URL(versionURL);
        HttpURLConnection con = (HttpURLConnection) url.openConnection();
        String str = "";
        BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
        while (br.ready()) {
            str = str + br.readLine();
        }
        br.close();
        Document document = DocumentHelper.parseText(str);
        Node node = document.selectSingleNode("//root/version");
        String latestVersion = node.valueOf("@id");
        Double latest = Double.parseDouble(latestVersion);
        Double current = Double.parseDouble(currentVersion.substring(0, currentVersion.indexOf("-")));
        if (latest > current) {
            String[] a = { latestVersion, node.valueOf("@url"), node.valueOf("@description") };
            return a;
        }
        return null;
    }
public Boolean connect() throws Exception {
        try {
            _ftpClient = new FTPClient();
            _ftpClient.connect(_url);
            _ftpClient.login(_username, _password);
            _rootPath = _ftpClient.printWorkingDirectory();
            return true;
        } catch (Exception ex) {
            throw new Exception("Cannot connect to server.");
        }
    }