semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
protected File getFile(NameCategory category) throws IOException {
        File home = new File(System.getProperty("user.dir"));
        String fileName = String.format("%s.txt", category);
        File file = new File(home, fileName);
        if (file.exists()) {
            return file;
        } else {
            URL url = LocalNameGenerator.class.getResource("/" + fileName);
            if (url == null) {
                throw new IllegalStateException(String.format("Cannot find resource at %s", fileName));
            } else {
                InputStream in = url.openStream();
                try {
                    BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
                    try {
                        IOUtils.copy(in, out);
                    } finally {
                        out.close();
                    }
                } finally {
                    in.close();
                }
                return file;
            }
        }
    }
public void updateSuccessStatus(ArrayList<THLEventStatus> succeededEvents, ArrayList<THLEventStatus> skippedEvents) throws THLException {
        Statement stmt = null;
        PreparedStatement pstmt = null;
        try {
            conn.setAutoCommit(false);
            if (succeededEvents != null && succeededEvents.size() > 0) {
                stmt = conn.createStatement();
                String seqnoList = buildCommaSeparatedList(succeededEvents);
                stmt.executeUpdate("UPDATE " + history + " SET status = " + THLEvent.COMPLETED + ", processed_tstamp = " + conn.getNowFunction() + " WHERE seqno in " + seqnoList);
            }
            if (skippedEvents != null && skippedEvents.size() > 0) {
                pstmt = conn.prepareStatement("UPDATE " + history + " SET status = ?, comments = ?," + " processed_tstamp = ? WHERE seqno = ?");
                Timestamp now = new Timestamp(System.currentTimeMillis());
                for (THLEventStatus event : skippedEvents) {
                    pstmt.setShort(1, THLEvent.SKIPPED);
                    pstmt.setString(2, truncate(event.getException() != null ? event.getException().getMessage() : "Unknown event failure", commentLength));
                    pstmt.setTimestamp(3, now);
                    pstmt.setLong(4, event.getSeqno());
                    pstmt.addBatch();
                }
                pstmt.executeBatch();
                pstmt.close();
            }
            conn.commit();
        } catch (SQLException e) {
            THLException exception = new THLException("Failed to update events status");
            exception.initCause(e);
            try {
                conn.rollback();
            } catch (SQLException e1) {
                THLException exception2 = new THLException("Failed to rollback after failure while updating events status");
                e1.initCause(exception);
                exception2.initCause(e1);
                exception = exception2;
            }
            throw exception;
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException ignore) {
                }
            }
            if (pstmt != null) {
                try {
                    pstmt.close();
                } catch (SQLException ignore) {
                }
            }
            try {
                conn.setAutoCommit(true);
            } catch (SQLException ignore) {
            }
        }
    }
public void updateFailedStatus(THLEventStatus failedEvent, ArrayList<THLEventStatus> events) throws THLException {
        Timestamp now = new Timestamp(System.currentTimeMillis());
        Statement stmt = null;
        PreparedStatement pstmt = null;
        try {
            conn.setAutoCommit(false);
            if (events != null && events.size() > 0) {
                String seqnoList = buildCommaSeparatedList(events);
                stmt = conn.createStatement();
                stmt.executeUpdate("UPDATE history SET status = " + THLEvent.FAILED + ", comments = 'Event was rollbacked due to failure while processing event#" + failedEvent.getSeqno() + "'" + ", processed_tstamp = " + conn.getNowFunction() + " WHERE seqno in " + seqnoList);
            }
            pstmt = conn.prepareStatement("UPDATE history SET status = ?" + ", comments = ?" + ", processed_tstamp = ?" + " WHERE seqno = ?");
            pstmt.setShort(1, THLEvent.FAILED);
            pstmt.setString(2, truncate(failedEvent.getException() != null ? failedEvent.getException().getMessage() : "Unknown failure", commentLength));
            pstmt.setTimestamp(3, now);
            pstmt.setLong(4, failedEvent.getSeqno());
            pstmt.executeUpdate();
            conn.commit();
        } catch (SQLException e) {
            THLException exception = new THLException("Failed to update events status");
            exception.initCause(e);
            try {
                conn.rollback();
            } catch (SQLException e1) {
                THLException exception2 = new THLException("Failed to rollback after failure while updating events status");
                e1.initCause(exception);
                exception2.initCause(e1);
                exception = exception2;
            }
            throw exception;
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException ignore) {
                }
            }
            if (pstmt != null) {
                try {
                    pstmt.close();
                } catch (SQLException ignore) {
                }
            }
            try {
                conn.setAutoCommit(true);
            } catch (SQLException ignore) {
            }
        }
    }
InputStream openURL(URL url) throws IOException, WrongMIMETypeException {
        InputStream is = null;
        if (url.getProtocol().equals("file")) {
            if (debug) {
                System.out.println("Using direct input stream on file url");
            }
            URLConnection urlc = url.openConnection();
            try {
                urlc.connect();
                is = new DataInputStream(urlc.getInputStream());
            } catch (FileNotFoundException e) {
            }
        } else {
            double start = 0;
            if (timing) {
                start = Time.getNow();
            }
            ContentNegotiator cn = null;
            cn = new ContentNegotiator(url);
            Object obj = null;
            obj = cn.getContent();
            if (obj != null) {
                byte[] buf = (byte[]) obj;
                is = new ByteArrayInputStream(buf);
            } else {
                System.err.println("Loader.openURL got null content");
                throw new IOException("Loader.openURL got null content");
            }
            if (timing) {
                double elapsed = Time.getNow() - start;
                System.out.println("Loader: open and buffer URL in: " + numFormat.format(elapsed, 2) + " seconds");
            }
        }
        return is;
    }
public static Document tidyHTML(URL url) throws XMLHelperException {
        try {
            URLConnection inConnection = url.openConnection();
            if (inConnection.getContentType().startsWith("text/xml") || inConnection.getContentType().startsWith("text/xhtml")) {
                return parseXMLFromURL(url);
            } else if (inConnection.getContentType().startsWith("text/html")) {
                InputStream is = inConnection.getInputStream();
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                int totalBytes = 0;
                byte[] buffer = new byte[65536];
                while (true) {
                    int bytesRead = is.read(buffer, 0, buffer.length);
                    if (bytesRead < 0) break;
                    for (int i = 0; i < bytesRead; i++) {
                        byte b = buffer[i];
                        if (b < 32 && b != 10 && b != 13 && b != 9) b = 32;
                        buffer[i] = b;
                    }
                    out.write(buffer, 0, bytesRead);
                    totalBytes += bytesRead;
                }
                is.close();
                out.close();
                String outContent = out.toString();
                InputStream in = new ByteArrayInputStream(out.toByteArray());
                Tidy tidy = new Tidy();
                tidy.setShowWarnings(false);
                tidy.setXmlOut(true);
                tidy.setXmlPi(false);
                tidy.setDocType("omit");
                tidy.setXHTML(false);
                tidy.setRawOut(true);
                tidy.setNumEntities(true);
                tidy.setQuiet(true);
                tidy.setFixComments(true);
                tidy.setIndentContent(true);
                tidy.setCharEncoding(org.w3c.tidy.Configuration.ASCII);
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                org.w3c.dom.Document tNode = (org.w3c.dom.Document) tidy.parseDOM(in, baos);
                String result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + baos.toString();
                int startIndex = 0;
                int endIndex = 0;
                if ((startIndex = result.indexOf("<!DOCTYPE")) >= 0) {
                    endIndex = result.indexOf(">", startIndex);
                    result = result.substring(0, startIndex) + result.substring(endIndex + 1, result.length());
                }
                while ((startIndex = result.indexOf("<script")) >= 0) {
                    endIndex = result.indexOf("</script>");
                    result = result.substring(0, startIndex) + result.substring(endIndex + 9, result.length());
                }
                in.close();
                baos.close();
                return parseXMLFromString(result);
            } else {
                throw new XMLHelperException("Unable to tidy content type: " + inConnection.getContentType());
            }
        } catch (IOException ioe) {
            throw new XMLHelperException("Unable to perform input/output", ioe);
        }
    }
public String buscaCDA() {
        Properties prop = new CargaProperties().Carga();
        URL url;
        BufferedReader in;
        String inputLine;
        String miLinea = null;
        try {
            url = new URL(prop.getProperty("CDA"));
            in = new BufferedReader(new InputStreamReader(url.openStream()));
            while ((inputLine = in.readLine()) != null) {
                if (inputLine.contains("cda-TRUNK-")) {
                    miLinea = inputLine;
                    miLinea = miLinea.substring(miLinea.indexOf("lastSuccessfulBuild/artifact/dist/cda-TRUNK"));
                    miLinea = miLinea.substring(0, miLinea.indexOf("\">"));
                    miLinea = url + miLinea;
                }
            }
        } catch (Throwable t) {
        }
        log.debug("Detetectado last build CDA: " + miLinea);
        return miLinea;
    }
public String buscaCDE() {
        URL url;
        Properties prop = new CargaProperties().Carga();
        BufferedReader in;
        String inputLine;
        String miLinea = null;
        try {
            url = new URL(prop.getProperty("CDE"));
            in = new BufferedReader(new InputStreamReader(url.openStream()));
            while ((inputLine = in.readLine()) != null) {
                if (inputLine.contains("lastSuccessfulBuild/artifact/server/plugin/dist/pentaho-cdf-dd-TRUNK")) {
                    miLinea = inputLine;
                    miLinea = miLinea.substring(miLinea.indexOf("lastSuccessfulBuild/artifact/server/plugin/dist/pentaho-cdf-dd-TRUNK"));
                    miLinea = miLinea.substring(0, miLinea.indexOf("\">"));
                    miLinea = url + miLinea;
                }
            }
        } catch (Throwable t) {
        }
        log.debug("Detetectado last build CDE: " + miLinea);
        return miLinea;
    }
public String buscaSAIKU() {
        URL url;
        Properties prop = new CargaProperties().Carga();
        BufferedReader in;
        String inputLine;
        String miLinea = null;
        try {
            url = new URL(prop.getProperty("SAIKU"));
            in = new BufferedReader(new InputStreamReader(url.openStream()));
            while ((inputLine = in.readLine()) != null) {
                if (inputLine.contains("lastSuccessfulBuild/artifact/saiku-bi-platform-plugin/target")) {
                    miLinea = inputLine;
                    log.debug(miLinea);
                    miLinea = miLinea.substring(miLinea.indexOf("lastSuccessfulBuild/artifact/saiku-bi-platform-plugin/target"));
                    miLinea = miLinea.substring(0, miLinea.indexOf("\">"));
                    miLinea = url + miLinea;
                }
            }
        } catch (Throwable t) {
        }
        log.debug("Detetectado last build SAIKU: " + miLinea);
        return miLinea;
    }
public static byte[] SHA1(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest md;
        md = MessageDigest.getInstance("SHA-1");
        byte[] sha1hash = new byte[40];
        md.update(text.getBytes("iso-8859-1"), 0, text.length());
        sha1hash = md.digest();
        return sha1hash;
    }
public synchronized String encrypt(String password) {
        try {
            MessageDigest md = null;
            md = MessageDigest.getInstance("SHA-1");
            md.update(password.getBytes("UTF-8"));
            byte raw[] = md.digest();
            byte[] hash = (new Base64()).encode(raw);
            return new String(hash);
        } catch (NoSuchAlgorithmException e) {
            System.out.println("Algorithm SHA-1 is not supported");
            return null;
        } catch (UnsupportedEncodingException e) {
            System.out.println("UTF-8 encoding is not supported");
            return null;
        }
    }
@Override
    public String encode(String password) {
        String hash = null;
        MessageDigest m;
        try {
            m = MessageDigest.getInstance("MD5");
            m.update(password.getBytes(), 0, password.length());
            hash = String.format("%1$032X", new BigInteger(1, m.digest()));
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return hash;
    }
private static File copyFileTo(File file, File directory) throws IOException {
        File newFile = new File(directory, file.getName());
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            fis = new FileInputStream(file);
            fos = new FileOutputStream(newFile);
            byte buff[] = new byte[1024];
            int val;
            while ((val = fis.read(buff)) > 0) fos.write(buff, 0, val);
        } finally {
            if (fis != null) fis.close();
            if (fos != null) fos.close();
        }
        return newFile;
    }
private ArrayList loadResults(String text, String index, int from) {
        loadingMore = true;
        JSONObject job = new JSONObject();
        ArrayList al = new ArrayList();
        try {
            String req = job.put("OperationId", "2").toString();
            InputStream is = null;
            String result = "";
            JSONObject jArray = null;
            try {
                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost("http://192.168.1.4:8080/newgenlibctxt/CarbonServlet");
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
                nameValuePairs.add(new BasicNameValuePair("OperationId", "2"));
                nameValuePairs.add(new BasicNameValuePair("Text", text));
                nameValuePairs.add(new BasicNameValuePair("Index", index));
                nameValuePairs.add(new BasicNameValuePair("From", from + ""));
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                HttpResponse response = httpclient.execute(httppost);
                HttpEntity entity = response.getEntity();
                is = entity.getContent();
            } catch (Exception e) {
                e.printStackTrace();
            }
            try {
                BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8);
                StringBuilder sb = new StringBuilder();
                String line = null;
                while ((line = reader.readLine()) != null) {
                    sb.append(line + "\n");
                }
                is.close();
                result = sb.toString();
            } catch (Exception e) {
                e.printStackTrace();
            }
            try {
                JSONObject jobres = new JSONObject(result);
                JSONArray jarr = jobres.getJSONArray("Records");
                for (int i = 0; i < jarr.length(); i++) {
                    String title = jarr.getJSONObject(i).getString("title");
                    String author = jarr.getJSONObject(i).getString("author");
                    String[] id = new String[2];
                    id[0] = jarr.getJSONObject(i).getString("cataloguerecordid");
                    id[1] = jarr.getJSONObject(i).getString("ownerlibraryid");
                    alOnlyIds.add(id);
                    al.add(Html.fromHtml("<html><body><b>" + title + "</b><br>by " + author + "</body></html>"));
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        } catch (Exception exp) {
            exp.printStackTrace();
        }
        loadingMore = false;
        return al;
    }
public static String hash(String in, String algorithm) {
        if (StringUtils.isBlank(algorithm)) algorithm = DEFAULT_ALGORITHM;
        try {
            md = MessageDigest.getInstance(algorithm);
        } catch (NoSuchAlgorithmException nsae) {
            logger.error("No such algorithm exception", nsae);
        }
        md.reset();
        md.update(in.getBytes());
        String out = null;
        try {
            out = Base64Encoder.encode(md.digest());
        } catch (IOException e) {
            logger.error("Error converting to Base64 ", e);
        }
        if (out.endsWith("\n")) out = out.substring(0, out.length() - 1);
        return out;
    }
private void testURL(String urlStr) throws MalformedURLException, IOException {
        HttpURLConnection conn = null;
        try {
            URL url = new URL(urlStr);
            conn = (HttpURLConnection) url.openConnection();
            int code = conn.getResponseCode();
            assertEquals(HttpURLConnection.HTTP_OK, code);
        } finally {
            if (conn != null) {
                conn.disconnect();
            }
        }
    }
public static String generate(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest md;
        md = MessageDigest.getInstance("SHA-1");
        byte[] sha1hash = new byte[40];
        md.update(text.getBytes("iso-8859-1"), 0, text.length());
        sha1hash = md.digest();
        return convertToHex(sha1hash);
    }
private String calculateHash(String s) {
        if (s == null) {
            return null;
        }
        MessageDigest messageDigest;
        try {
            messageDigest = MessageDigest.getInstance("SHA");
        } catch (NoSuchAlgorithmException e) {
            logger.error("Could not find a message digest algorithm.");
            return null;
        }
        messageDigest.update(s.getBytes());
        byte[] hash = messageDigest.digest();
        StringBuilder sb = new StringBuilder();
        for (byte b : hash) {
            sb.append(String.format("%02x", b));
        }
        return sb.toString();
    }
private String createHash() {
        String hash = "";
        try {
            final java.util.Calendar c = java.util.Calendar.getInstance();
            String day = "" + c.get(java.util.Calendar.DATE);
            day = (day.length() == 1) ? '0' + day : day;
            String month = "" + (c.get(java.util.Calendar.MONTH) + 1);
            month = (month.length() == 1) ? '0' + month : month;
            final String hashString = getStringProperty("hashkey") + day + "." + month + "." + c.get(java.util.Calendar.YEAR);
            final MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(hashString.getBytes());
            final byte digest[] = md.digest();
            hash = "";
            for (int i = 0; i < digest.length; i++) {
                final String s = Integer.toHexString(digest[i] & 0xFF);
                hash += ((s.length() == 1) ? "0" + s : s);
            }
        } catch (final NoSuchAlgorithmException e) {
            bot.getLogger().log(e);
        }
        return hash;
    }
public void testAuthentication() throws Exception {
        String host = "localhost";
        int port = DEFAULT_PORT;
        URL url = new URL("http://" + host + ":" + port + "/");
        URLConnection connection = url.openConnection();
        InputStream in = connection.getInputStream();
        in.close();
        waitToStop();
        server.setAttribute(name, new Attribute("AuthenticationMethod", "basic"));
        server.invoke(name, "addAuthorization", new Object[] { "mx4j", "mx4j" }, new String[] { "java.lang.String", "java.lang.String" });
        server.invoke(name, "start", null, null);
        url = new URL("http://" + host + ":" + port + "/");
        connection = url.openConnection();
        try {
            in = connection.getInputStream();
        } catch (Exception e) {
        } finally {
            in.close();
        }
        assertEquals(((HttpURLConnection) connection).getResponseCode(), 401);
        url = new URL("http://" + host + ":" + port + "/");
        connection = url.openConnection();
        connection.setRequestProperty("Authorization", "basic bXg0ajpteDRq");
        in = connection.getInputStream();
        in.close();
        waitToStop();
        server.setAttribute(name, new Attribute("AuthenticationMethod", "none"));
    }
public void testAddCommandProcessor() throws Exception {
        String host = "localhost";
        int port = DEFAULT_PORT;
        URLConnection connection = null;
        URL url = new URL("http://" + host + ":" + port + "/nonexistant");
        server.invoke(name, "addCommandProcessor", new Object[] { "nonexistant", new DummyCommandProcessor() }, new String[] { "java.lang.String", "mx4j.tools.adaptor.http.HttpCommandProcessor" });
        connection = url.openConnection();
        assertEquals(200, ((HttpURLConnection) connection).getResponseCode());
        server.invoke(name, "removeCommandProcessor", new Object[] { "nonexistant" }, new String[] { "java.lang.String" });
        connection = url.openConnection();
        assertEquals(404, ((HttpURLConnection) connection).getResponseCode());
        server.invoke(name, "addCommandProcessor", new Object[] { "nonexistant", "test.mx4j.tools.adaptor.http.HttpAdaptorTest$DummyCommandProcessor" }, new String[] { "java.lang.String", "java.lang.String" });
        connection = url.openConnection();
        assertEquals(200, ((HttpURLConnection) connection).getResponseCode());
    }