semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static List<String> unTar(File tarFile, File directory) throws IOException {
        List<String> result = new ArrayList<String>();
        InputStream inputStream = new FileInputStream(tarFile);
        TarArchiveInputStream in = new TarArchiveInputStream(inputStream);
        TarArchiveEntry entry = in.getNextTarEntry();
        while (entry != null) {
            OutputStream out = new FileOutputStream(new File(directory, entry.getName()));
            IOUtils.copy(in, out);
            out.close();
            result.add(entry.getName());
            entry = in.getNextTarEntry();
        }
        in.close();
        return result;
    }
private String generateUniqueIdMD5(Run run, HttpServletRequest request, String groupIdString) {
        String portalUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();
        String uniqueportalUrl = portalUrl + "run:" + run.getId().toString() + "group:" + groupIdString;
        MessageDigest m = null;
        try {
            m = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        m.update(uniqueportalUrl.getBytes(), 0, uniqueportalUrl.length());
        String uniqueIdMD5 = new BigInteger(1, m.digest()).toString(16);
        return uniqueIdMD5;
    }
public static String getMD5(String s) {
        try {
            MessageDigest m = MessageDigest.getInstance("MD5");
            m.update(s.getBytes(), 0, s.length());
            s = new BigInteger(1, m.digest()).toString(16);
        } catch (NoSuchAlgorithmException ex) {
            ex.printStackTrace();
        }
        return s;
    }
public static String getMd5(String str) {
        try {
            final MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(str.getBytes());
            final byte b[] = md.digest();
            int i;
            final StringBuffer buf = new StringBuffer("");
            for (int offset = 0; offset < b.length; offset++) {
                i = b[offset];
                if (i < 0) {
                    i += 256;
                }
                if (i < 16) {
                    buf.append("0");
                }
                buf.append(Integer.toHexString(i));
            }
            return buf.toString();
        } catch (final NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";
    }
public CopyAllDataToOtherFolderResponse CopyAllDataToOtherFolder(DPWSContext context, CopyAllDataToOtherFolder CopyAllDataInps) throws DPWSException {
        CopyAllDataToOtherFolderResponse cpyRp = new CopyAllDataToOtherFolderResponseImpl();
        int hany = 0;
        String errorMsg = null;
        try {
            if ((rootDir == null) || (rootDir.length() == (-1))) {
                errorMsg = LocalStorVerify.ISNT_ROOTFLD;
            } else {
                String sourceN = CopyAllDataInps.getSourceName();
                String targetN = CopyAllDataInps.getTargetName();
                if (LocalStorVerify.isValid(sourceN) && LocalStorVerify.isValid(targetN)) {
                    String srcDir = rootDir + File.separator + sourceN;
                    String trgDir = rootDir + File.separator + targetN;
                    if (LocalStorVerify.isLength(srcDir) && LocalStorVerify.isLength(trgDir)) {
                        for (File fs : new File(srcDir).listFiles()) {
                            File ft = new File(trgDir + '\\' + fs.getName());
                            FileChannel in = null, out = null;
                            try {
                                in = new FileInputStream(fs).getChannel();
                                out = new FileOutputStream(ft).getChannel();
                                long size = in.size();
                                MappedByteBuffer buf = in.map(FileChannel.MapMode.READ_ONLY, 0, size);
                                out.write(buf);
                            } finally {
                                if (in != null) in.close();
                                if (out != null) out.close();
                                hany++;
                            }
                        }
                    } else {
                        errorMsg = LocalStorVerify.FLD_TOOLNG;
                    }
                } else {
                    errorMsg = LocalStorVerify.ISNT_VALID;
                }
            }
        } catch (Throwable tr) {
            tr.printStackTrace();
            errorMsg = tr.getMessage();
            hany = (-1);
        }
        if (errorMsg != null) {
        }
        cpyRp.setNum(hany);
        return cpyRp;
    }
@Override
    public void run() {
        while (run) {
            try {
                URL url = new URL("http://" + server.getIp() + "/" + tomcat.getName() + "/ui/pva/version.jsp?RT=" + System.currentTimeMillis());
                BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream(), Charset.forName("UTF-8")));
                String inputLine;
                while ((inputLine = in.readLine()) != null) {
                    if (inputLine.contains("currentversion")) {
                        String s = inputLine.substring(inputLine.indexOf("=") + 1, inputLine.length());
                        tomcat.setDetailInfo(s.trim());
                    }
                }
                in.close();
                tomcat.setIsAlive(true);
            } catch (Exception e) {
                tomcat.setIsAlive(false);
            }
            try {
                Thread.sleep(60000);
            } catch (InterruptedException e) {
            }
        }
    }
@Test
    public void testLargePut() throws Throwable {
        int size = CommonParameters.BLOCK_SIZE;
        InputStream is = new FileInputStream(_fileName);
        RepositoryFileOutputStream ostream = new RepositoryFileOutputStream(_nodeName, _putHandle, CommonParameters.local);
        int readLen = 0;
        int writeLen = 0;
        byte[] buffer = new byte[CommonParameters.BLOCK_SIZE];
        while ((readLen = is.read(buffer, 0, size)) != -1) {
            ostream.write(buffer, 0, readLen);
            writeLen += readLen;
        }
        ostream.close();
        CCNStats stats = _putHandle.getNetworkManager().getStats();
        Assert.assertEquals(0, stats.getCounter("DeliverInterestFailed"));
    }
public MotixFileItem(final InputStream is, final String name, final String contentType, final int index) throws IOException {
        this.name = name;
        this.contentType = contentType;
        this.index = index;
        this.extension = FilenameUtils.getExtension(this.name);
        this.isImage = ImageUtils.isImage(name);
        ArrayInputStream isAux = null;
        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        try {
            IOUtils.copy(is, out);
            isAux = new ArrayInputStream(out.toByteArray());
            if (this.isImage) {
                this.bufferedImage = imaging.read(isAux);
            }
        } finally {
            IOUtils.closeQuietly(out);
            IOUtils.closeQuietly(isAux);
        }
        this.inputStream = new ArrayInputStream(out.toByteArray());
    }
public java.security.cert.X509Certificate[] getServerCerts() throws IOException {
        String callURL = theURL;
        callURL += "?method=test";
        java.net.HttpURLConnection conn;
        java.net.URL url = new java.net.URL(callURL);
        conn = (java.net.HttpURLConnection) url.openConnection();
        if (isFollowingRedirects != null) conn.setInstanceFollowRedirects(isFollowingRedirects.booleanValue());
        if (theConnectTimeout >= 0) conn.setConnectTimeout(theConnectTimeout);
        if (theReadTimeout >= 0) conn.setReadTimeout(theReadTimeout);
        if (conn instanceof javax.net.ssl.HttpsURLConnection) {
            SecurityRetriever retriever = new SecurityRetriever();
            javax.net.ssl.SSLContext sc;
            try {
                sc = javax.net.ssl.SSLContext.getInstance("SSL");
                sc.init(theKeyManagers, new javax.net.ssl.TrustManager[] { retriever }, new java.security.SecureRandom());
            } catch (java.security.GeneralSecurityException e) {
                log.error("Could not initialize SSL context", e);
                IOException toThrow = new IOException("Could not initialize SSL context: " + e.getMessage());
                toThrow.setStackTrace(e.getStackTrace());
                throw toThrow;
            }
            javax.net.ssl.HttpsURLConnection sConn = (javax.net.ssl.HttpsURLConnection) conn;
            sConn.setSSLSocketFactory(sc.getSocketFactory());
            sConn.setHostnameVerifier(new javax.net.ssl.HostnameVerifier() {

                public boolean verify(String hostname, javax.net.ssl.SSLSession session) {
                    return true;
                }
            });
            try {
                conn.connect();
            } catch (IOException e) {
                if (retriever.getCerts() == null) throw e;
            }
            return retriever.getCerts();
        } else return null;
    }
private static void copyFile(String src, String dst) throws InvocationTargetException {
        try {
            FileChannel srcChannel;
            srcChannel = new FileInputStream(src).getChannel();
            FileChannel dstChannel = new FileOutputStream(dst).getChannel();
            dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
            srcChannel.close();
            dstChannel.close();
        } catch (FileNotFoundException e) {
            throw new InvocationTargetException(e, Messages.ALFWizardCreationAction_errorSourceFilesNotFound);
        } catch (IOException e) {
            throw new InvocationTargetException(e, Messages.ALFWizardCreationAction_errorCopyingFiles);
        }
    }
private void googleImageSearch() {
        bottomShowing = true;
        googleSearched = true;
        googleImageLocation = 0;
        googleImages = new Vector<String>();
        custom = "";
        int r = JOptionPane.showConfirmDialog(this, "Customize google search?", "Google Search", JOptionPane.YES_NO_OPTION);
        if (r == JOptionPane.YES_OPTION) {
            custom = JOptionPane.showInputDialog("Custom Search", "");
        } else {
            custom = artist;
        }
        try {
            String u = "http://images.google.com/images?q=" + custom;
            if (u.contains(" ")) {
                u = u.replace(" ", "+");
            }
            URL url = new URL(u);
            HttpURLConnection httpcon = (HttpURLConnection) url.openConnection();
            httpcon.addRequestProperty("User-Agent", "Mozilla/4.76");
            BufferedReader readIn = new BufferedReader(new InputStreamReader(httpcon.getInputStream()));
            googleImages.clear();
            String lin = new String();
            while ((lin = readIn.readLine()) != null) {
                while (lin.contains("href=\"/imgres?imgurl=")) {
                    while (!lin.contains(">")) {
                        lin += readIn.readLine();
                    }
                    String s = lin.substring(lin.indexOf("href=\"/imgres?imgurl="), lin.indexOf(">", lin.indexOf("href=\"/imgres?imgurl=")));
                    lin = lin.substring(lin.indexOf(">", lin.indexOf("href=\"/imgres?imgurl=")));
                    if (s.contains("&amp;") && s.indexOf("http://") < s.indexOf("&amp;")) {
                        s = s.substring(s.indexOf("http://"), s.indexOf("&amp;"));
                    } else {
                        s = s.substring(s.indexOf("http://"), s.length());
                    }
                    googleImages.add(s);
                }
            }
            readIn.close();
        } catch (Exception ex4) {
            MusicBoxView.showErrorDialog(ex4);
        }
        jButton1.setEnabled(false);
        getContentPane().remove(jLabel1);
        ImageIcon icon;
        try {
            icon = new ImageIcon(new URL(googleImages.elementAt(googleImageLocation)));
            int h = icon.getIconHeight();
            int w = icon.getIconWidth();
            jLabel1.setSize(w, h);
            jLabel1.setIcon(icon);
            add(jLabel1, BorderLayout.CENTER);
        } catch (MalformedURLException ex) {
            MusicBoxView.showErrorDialog(ex);
            jLabel1.setIcon(MusicBoxView.noImage);
        }
        add(jPanel1, BorderLayout.PAGE_END);
        pack();
    }
public void googleImageSearch(String start) {
        try {
            String u = "http://images.google.com/images?q=" + custom + start;
            if (u.contains(" ")) {
                u = u.replace(" ", "+");
            }
            URL url = new URL(u);
            HttpURLConnection httpcon = (HttpURLConnection) url.openConnection();
            httpcon.addRequestProperty("User-Agent", "Mozilla/4.76");
            BufferedReader readIn = new BufferedReader(new InputStreamReader(httpcon.getInputStream()));
            googleImages.clear();
            String text = "";
            String lin = "";
            while ((lin = readIn.readLine()) != null) {
                text += lin;
            }
            readIn.close();
            if (text.contains("\n")) {
                text = text.replace("\n", "");
            }
            String[] array = text.split("\\Qhref=\"/imgres?imgurl=\\E");
            for (String s : array) {
                if (s.startsWith("http://") || s.startsWith("https://") && s.contains("&amp;")) {
                    String s1 = s.substring(0, s.indexOf("&amp;"));
                    googleImages.add(s1);
                }
            }
        } catch (Exception ex4) {
            MusicBoxView.showErrorDialog(ex4);
        }
        jButton4.setEnabled(true);
        jButton2.setEnabled(true);
        getContentPane().remove(jLabel1);
        ImageIcon icon;
        try {
            icon = new ImageIcon(new URL(googleImages.elementAt(googleImageLocation)));
            int h = icon.getIconHeight();
            int w = icon.getIconWidth();
            jLabel1.setSize(w, h);
            jLabel1.setIcon(icon);
            add(jLabel1, BorderLayout.CENTER);
        } catch (MalformedURLException ex) {
            MusicBoxView.showErrorDialog(ex);
            jLabel1.setIcon(MusicBoxView.noImage);
        }
        add(jPanel1, BorderLayout.PAGE_END);
        pack();
    }
public long add(T t) throws BaseException {
        Connection conn = null;
        PreparedStatement pstmt = null;
        long result = -1L;
        boolean flag = false;
        try {
            conn = getConnection();
            if (conn != null) {
                flag = true;
            } else {
                conn = ConnectionManager.getConn(getStrConnection());
                conn.setAutoCommit(false);
            }
            pstmt = getAdd(conn, t, this.getTableName());
            pstmt.executeUpdate();
            result = t.getId();
        } catch (SQLException e) {
            try {
                if (!flag) {
                    conn.rollback();
                }
            } catch (Exception ex) {
                log.error("add(T " + t.toString() + ")回滚出错，错误信息：" + ex.getMessage());
            }
            log.error("add(T " + t.toString() + ")方法出错:" + e.getMessage());
        } catch (BaseException e) {
            throw e;
        } finally {
            try {
                if (!flag) {
                    conn.setAutoCommit(true);
                }
            } catch (Exception e) {
                log.error("add(T " + t.toString() + ")方法设置自动提交出错，信息为:" + e.getMessage());
            }
            ConnectionManager.closePreparedStatement(pstmt);
            if (!flag) {
                ConnectionManager.closeConn(conn);
            }
        }
        return result;
    }
public void fetchDataByID(String id) throws IOException, SAXException {
        URL url = new URL(urlHistoryStockPrice + id);
        URLConnection con = url.openConnection();
        con.setConnectTimeout(20000);
        InputStream is = con.getInputStream();
        byte[] bs = new byte[1024];
        int len;
        OutputStream os = new FileOutputStream(dataPath + id + ".csv");
        while ((len = is.read(bs)) != -1) {
            os.write(bs, 0, len);
        }
        os.flush();
        os.close();
        is.close();
        con = null;
        url = null;
    }
public String fetchDataDailyByStockId(String StockId, String market) throws IOException {
        URL url = new URL(urlDailyStockPrice.replace("{0}", StockId + "." + market));
        URLConnection con = url.openConnection();
        con.setConnectTimeout(20000);
        InputStream is = con.getInputStream();
        byte[] bs = new byte[1024];
        int len;
        OutputStream os = new FileOutputStream(dailyStockPriceList, true);
        while ((len = is.read(bs)) != -1) {
            os.write(bs, 0, len);
        }
        os.flush();
        os.close();
        is.close();
        con = null;
        url = null;
        return null;
    }
private void validate(String id, WriteToWebServerFile writeFile, char[][] charData) throws Exception {
        for (int i = 0; i < charData.length; i++) {
            assertTrue("There is a URL for input " + i, writeFile.hasNextURL());
            URL url = writeFile.nextURL();
            String path = url.getPath();
            assertTrue("URL " + url + " contains request resource ID", path.indexOf(id) != -1);
            URLConnection connection = url.openConnection();
            Reader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            int value;
            int index = 0;
            while (((value = reader.read()) != -1) && (index < charData[i].length)) {
                assertEquals("Character data " + i + " : " + index, (int) charData[i][index], value);
                index++;
            }
        }
    }
public static String remove_tag(String sessionid, String absolutePathForTheSpesificTag) {
        String resultJsonString = "some problem existed inside the create_new_tag() function if you see this string";
        try {
            Log.d("current running function name:", "remove_tag");
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("https://mt0-app.cloud.cm/rpc/json");
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
            nameValuePairs.add(new BasicNameValuePair("c", "Storage"));
            nameValuePairs.add(new BasicNameValuePair("m", "remove_tag"));
            nameValuePairs.add(new BasicNameValuePair("absolute_tags", absolutePathForTheSpesificTag));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            httppost.setHeader("Cookie", "PHPSESSID=" + sessionid);
            HttpResponse response = httpclient.execute(httppost);
            resultJsonString = EntityUtils.toString(response.getEntity());
            Log.d("jsonStringReturned:", resultJsonString);
            return resultJsonString;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return resultJsonString;
    }
public static String remove_file(String sessionid, String key) {
        String resultJsonString = "some problem existed inside the create_new_tag() function if you see this string";
        try {
            Log.d("current running function name:", "remove_file");
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("https://mt0-app.cloud.cm/rpc/json");
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
            nameValuePairs.add(new BasicNameValuePair("c", "Storage"));
            nameValuePairs.add(new BasicNameValuePair("m", "remove_file"));
            nameValuePairs.add(new BasicNameValuePair("keys", key));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            httppost.setHeader("Cookie", "PHPSESSID=" + sessionid);
            HttpResponse response = httpclient.execute(httppost);
            resultJsonString = EntityUtils.toString(response.getEntity());
            Log.d("jsonStringReturned:", resultJsonString);
            return resultJsonString;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return resultJsonString;
    }
public static InputStream download_file(String sessionid, String key) {
        String urlString = "https://s2.cloud.cm/rpc/raw?c=Storage&m=download_file&key=" + key;
        try {
            URL url = new URL(urlString);
            Log.d("current running function name:", "download_file");
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestProperty("Cookie", "PHPSESSID=" + sessionid);
            conn.setRequestMethod("POST");
            conn.setDoInput(true);
            InputStream is = conn.getInputStream();
            Log.d("size of the picture file", "" + is.available());
            return is;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
public APIResponse delete(String id) throws Exception {
        APIResponse response = new APIResponse();
        connection = (HttpURLConnection) new URL(url + "/api/transaction/delete/" + id).openConnection();
        connection.setRequestMethod("DELETE");
        connection.setConnectTimeout(TIMEOUT);
        connection.connect();
        if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
            response.setDone(true);
            response.setMessage("Transaction Deleted!");
        } else {
            response.setDone(false);
            response.setMessage("Delete Transaction Error Code: Http (" + connection.getResponseCode() + ")");
        }
        connection.disconnect();
        return response;
    }
public APIResponse update(Transaction transaction) throws Exception {
        APIResponse response = new APIResponse();
        connection = (HttpURLConnection) new URL(url + "/api/transaction/update").openConnection();
        connection.setDoOutput(true);
        connection.setRequestMethod("PUT");
        connection.setRequestProperty("Content-Type", "application/json; charset=utf-8");
        connection.setUseCaches(false);
        connection.setConnectTimeout(TIMEOUT);
        connection.connect();
        marshaller.marshal(transaction, new MappedXMLStreamWriter(new MappedNamespaceConvention(new Configuration()), new OutputStreamWriter(connection.getOutputStream(), "utf-8")));
        connection.getOutputStream().flush();
        connection.getOutputStream().close();
        if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
            JSONObject obj = new JSONObject(new String(new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8")).readLine()));
            response.setDone(true);
            response.setMessage(unmarshaller.unmarshal(new MappedXMLStreamReader(obj, new MappedNamespaceConvention(new Configuration()))));
            connection.getInputStream().close();
        } else {
            response.setDone(false);
            response.setMessage("Update Transaction Error Code: Http (" + connection.getResponseCode() + ")");
        }
        connection.disconnect();
        return response;
    }
public void deleteScript(Integer id) {
        InputStream is = null;
        try {
            URL url = new URL(strServlet + getSessionIDSuffix() + "?deleteScript=" + id);
            System.out.println("requesting: " + url);
            is = url.openStream();
            while (is.read() != -1) ;
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                is.close();
            } catch (Exception e) {
            }
        }
    }