semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
protected static final byte[] digest(String s) {
        byte[] ret = null;
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(s.getBytes());
            ret = md.digest();
        } catch (NoSuchAlgorithmException e) {
            System.err.println("no message digest algorithm available!");
            System.exit(1);
        }
        return ret;
    }
public static String fetchURL(final String u) {
        String retStr = "";
        try {
            final URL url = new URL(u);
            final BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
            String line;
            while ((line = reader.readLine()) != null) {
                retStr += line;
            }
            reader.close();
        } catch (final MalformedURLException e) {
            logger.severe("MalformedURLException calling url" + e.getMessage());
        } catch (final IOException e) {
            logger.severe("IOException calling url" + e.getMessage());
        }
        return retStr;
    }
private static Collection<String> crossCheckFromOBOFile(String category) throws Exception {
        Collection<String> miCol = new ArrayList<String>();
        String revision = "1.48";
        URL url = new URL(OboUtils.PSI_MI_OBO_LOCATION + "?revision=" + revision);
        log.debug("url " + url);
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        String inputLine;
        int termCounter = 0;
        int miCounter = 0;
        int obsoleteCounter = 0;
        int obsoleteCounterDef = 0;
        int typedefCounter = 0;
        int drugTerm = 0;
        int psiTerm = 0;
        String mi = null;
        while ((inputLine = in.readLine()) != null) {
            String temp;
            temp = inputLine;
            if (inputLine.startsWith("[Term]")) {
                termCounter++;
            } else if (inputLine.matches("id:\\s+(MI:.*)")) {
                mi = temp.split("\\s+")[1];
                miCounter++;
            } else if (inputLine.contains("is_obsolete: true")) {
                obsoleteCounter++;
            } else if (inputLine.matches("def:.*?OBSOLETE.*")) {
                obsoleteCounterDef++;
            } else if (inputLine.startsWith("[Typedef]")) {
                typedefCounter++;
            } else if (inputLine.matches("subset:\\s+PSI-MI\\s+slim")) {
                psiTerm++;
                if (category.equalsIgnoreCase(OboCategory.PSI_MI_SLIM)) miCol.add(mi);
            } else if (inputLine.matches("subset:\\s+Drugable")) {
                drugTerm++;
                if (category.equalsIgnoreCase(OboCategory.DRUGABLE)) miCol.add(mi);
            }
        }
        Assert.assertEquals(948, termCounter);
        Assert.assertEquals(948, miCounter);
        Assert.assertEquals(53, obsoleteCounter);
        Assert.assertEquals(53, obsoleteCounterDef);
        Assert.assertEquals(1, typedefCounter);
        Assert.assertEquals(844, psiTerm);
        Assert.assertEquals(124, drugTerm);
        in.close();
        return miCol;
    }
public static GenericDocumentTransformer<? extends GenericDocument> getTranformer(URL url) throws IOException {
        setDefaultImplementation();
        if ("text/xml".equals(url.openConnection().getContentType()) || "application/xml".equals(url.openConnection().getContentType())) {
            return null;
        } else if ("text/html".equals(url.openConnection().getContentType())) {
            return null;
        }
        return null;
    }
public static void main(String args[]) {
        int i, j, l;
        short NUMNUMBERS = 100;
        short numbers[] = new short[NUMNUMBERS];
        printIntro();
        int time = (int) System.currentTimeMillis();
        for (i = 0; i < NUMNUMBERS; i++) {
            numbers[i] = (short) (NUMNUMBERS - 1 - i);
        }
        for (i = 0; i < NUMNUMBERS; i++) {
            for (j = 0; j < NUMNUMBERS - i - 1; j++) {
                if (numbers[j] > numbers[j + 1]) {
                    short temp = numbers[j];
                    numbers[j] = numbers[j + 1];
                    numbers[j + 1] = temp;
                }
            }
            if (WANT_PROGRESS) {
                printProgress();
            }
        }
        time = (int) System.currentTimeMillis() - time;
        System.out.print(time);
        System.out.print("End\n");
    }
private static void loadMappings(Configuration cfg) {
        try {
            Enumeration en = LoadingUtils.getResources(MAPPINGS_FILE);
            while (en.hasMoreElements()) {
                URL url = (URL) en.nextElement();
                logger.info("Found mapping module " + url.toExternalForm());
                InputStream inputStream = null;
                try {
                    inputStream = url.openStream();
                    HibConfiguration hm = loadModuleMappings(inputStream);
                    configureModuleMappings(cfg, hm.getSessionFactory());
                } catch (IOException e) {
                    logger.warn("Could not load mappings file \"" + url.toExternalForm() + "\"", e);
                } catch (JAXBException e) {
                    logger.warn("Unable to instantiate JAXBContext ", e);
                } finally {
                    try {
                        if (inputStream != null) inputStream.close();
                    } catch (IOException e) {
                        logger.debug(e);
                    }
                }
            }
        } catch (IOException e) {
            logger.warn("Could not find any mappings file hibernate.mappings.xml", e);
        }
    }
public void _testConvertIntoOneFile() {
        File csvFile = new File("C:/DE311/solution_workspace/WorkbookTaglib/WorkbookTagDemoWebapp/src/main/resources/csv/google.csv");
        try {
            Charset guessedCharset = com.glaforge.i18n.io.CharsetToolkit.guessEncoding(csvFile, 4096);
            CSVReader reader = new CSVReader(new BufferedReader(new InputStreamReader(new FileInputStream(csvFile), guessedCharset)));
            Writer writer = new FileWriter("/temp/test.html");
            int nbLines = CsvConverterUtils.countLines(new BufferedReader(new FileReader(csvFile)));
            HtmlConverter conv = new HtmlConverter();
            conv.convert(reader, writer, nbLines);
        } catch (Exception e) {
            fail(e.getMessage());
        }
    }
private void copyfile(File srcFile, File dstDir) throws FileNotFoundException, IOException {
        if (srcFile.isDirectory()) {
            File newDestDir = new File(dstDir, srcFile.getName());
            newDestDir.mkdir();
            String fileNameList[] = srcFile.list();
            for (int i = 0; i < fileNameList.length; i++) {
                File newSouceFile = new File(srcFile, fileNameList[i]);
                copyfile(newSouceFile, newDestDir);
            }
        } else {
            File newDestFile = new File(dstDir, srcFile.getName());
            FileInputStream in = new FileInputStream(srcFile);
            FileOutputStream out = new FileOutputStream(newDestFile);
            FileChannel inChannel = in.getChannel();
            FileChannel outChannel = out.getChannel();
            long i;
            Logger.log("copyFile before- copiedSize = " + copiedSize);
            for (i = 0; i < srcFile.length() - BLOCK_LENGTH; i += BLOCK_LENGTH) {
                synchronized (this) {
                    inChannel.transferTo(i, BLOCK_LENGTH, outChannel);
                    copiedSize += BLOCK_LENGTH;
                }
            }
            synchronized (this) {
                inChannel.transferTo(i, srcFile.length() - i, outChannel);
                copiedSize += srcFile.length() - i;
            }
            Logger.log("copyFile after copy- copiedSize = " + copiedSize + "srcFile.length = " + srcFile.length() + "diff = " + (copiedSize - srcFile.length()));
            in.close();
            out.close();
            outChannel = null;
            Logger.log("File copied.");
        }
    }
private void Connect() throws NpsException {
        try {
            client = new FTPClient();
            client.connect(host.hostname, host.remoteport);
            int reply = client.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                client.disconnect();
                client = null;
                com.microfly.util.DefaultLog.error_noexception("FTP Server:" + host.hostname + "refused connection.");
                return;
            }
            client.login(host.uname, host.upasswd);
            client.enterLocalPassiveMode();
            client.setFileType(FTPClient.BINARY_FILE_TYPE);
            client.changeWorkingDirectory(host.remotedir);
        } catch (Exception e) {
            com.microfly.util.DefaultLog.error(e);
        }
    }
protected final void loadLogFile(String filename) throws IOException {
        cleanUp(true, false);
        InputStream is = null;
        OutputStream os = null;
        File f = File.createTempFile("log", null);
        try {
            is = getClass().getResourceAsStream(filename);
            Assert.isTrue(is != null, "File not found: " + filename);
            os = new FileOutputStream(f);
            IOUtils.copy(is, os);
            setLogFile(f);
        } finally {
            IOUtils.closeQuietly(is);
            IOUtils.closeQuietly(os);
        }
    }
private static String getTemplatePluginsXML(CommandLine commandLine) {
        String urlString = commandLine.getOptionValue(CMD_LINE_PLUGINSXMLTEMPLATE_OPTION);
        URL url = null;
        try {
            url = new URL(urlString);
        } catch (MalformedURLException ex) {
            throw new RuntimeException("Could not convert to URL: '" + urlString + "'", ex);
        }
        String templatePluginsXML = null;
        try {
            InputStream in = null;
            try {
                in = url.openStream();
                templatePluginsXML = IOUtils.toString(in);
            } finally {
                if (in != null) {
                    in.close();
                }
            }
        } catch (IOException ex) {
            throw new RuntimeException("Could not load plugins metadata from: " + url.toExternalForm(), ex);
        }
        if (templatePluginsXML == null || templatePluginsXML.trim().length() == 0) {
            throw new RuntimeException("Template plugins.xml has no content: " + url.toExternalForm());
        }
        System.out.println("Template plugins XML:\t" + url.toExternalForm());
        return templatePluginsXML;
    }
@TestTargetNew(level = TestLevel.ADDITIONAL, notes = "", method = "SecureCacheResponse", args = {  })
    public void test_additional() throws Exception {
        URL url = new URL("http://google.com");
        ResponseCache.setDefault(new TestResponseCache());
        HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
        httpCon.setUseCaches(true);
        httpCon.connect();
        try {
            Thread.sleep(5000);
        } catch (Exception e) {
        }
        httpCon.disconnect();
    }
public static InputStream getResponse(String pURL, String pUserName, String pPassword, OutputStream pResponseOutputStream, String pHttpMethodType) throws Exception {
        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;
        URL url = new URL(pURL);
        int port = url.getPort();
        if (-1 == port) {
            port = url.getDefaultPort();
        }
        if (url.getProtocol().equals(HTTPS_PROTOCOL)) {
            Protocol httpsProtocol = new Protocol(HTTPS_PROTOCOL, new EasySSLProtocolSocketFactory(), port);
            Protocol.registerProtocol(HTTPS_PROTOCOL, httpsProtocol);
        }
        HttpClient httpClient = new HttpClient();
        httpClient.getParams().setParameter("http.socket.timeout", HTTP_SOCKET_TIMEOUT);
        HttpMethod httpMethod = getHttpMethod(pHttpMethodType, pURL);
        if (null != pUserName && null != pPassword) {
            httpClient.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(pUserName, pPassword));
        }
        try {
            httpClient.executeMethod(httpMethod);
            if (null != pResponseOutputStream) {
                IOUtils.copy(httpMethod.getResponseBodyAsStream(), pResponseOutputStream);
            }
            return httpMethod.getResponseBodyAsStream();
        } catch (Exception e) {
            throw (e);
        } finally {
            httpMethod.releaseConnection();
        }
    }
@Test
    public void testCarResource() throws Exception {
        DefaultHttpClient client = new DefaultHttpClient();
        System.out.println("**** CarResource Via @MatrixParam ***");
        HttpGet get = new HttpGet("http://localhost:9095/cars/matrix/mercedes/e55;color=black/2006");
        HttpResponse response = client.execute(get);
        Assert.assertEquals(200, response.getStatusLine().getStatusCode());
        BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        String line = reader.readLine();
        while (line != null) {
            System.out.println(line);
            line = reader.readLine();
        }
        System.out.println("**** CarResource Via PathSegment ***");
        get = new HttpGet("http://localhost:9095/cars/segment/mercedes/e55;color=black/2006");
        response = client.execute(get);
        Assert.assertEquals(200, response.getStatusLine().getStatusCode());
        reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        line = reader.readLine();
        while (line != null) {
            System.out.println(line);
            line = reader.readLine();
        }
        System.out.println("**** CarResource Via PathSegments ***");
        get = new HttpGet("http://localhost:9095/cars/segments/mercedes/e55/amg/year/2006");
        response = client.execute(get);
        Assert.assertEquals(200, response.getStatusLine().getStatusCode());
        reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        line = reader.readLine();
        while (line != null) {
            System.out.println(line);
            line = reader.readLine();
        }
        System.out.println("**** CarResource Via PathSegment ***");
        get = new HttpGet("http://localhost:9095/cars/uriinfo/mercedes/e55;color=black/2006");
        response = client.execute(get);
        Assert.assertEquals(200, response.getStatusLine().getStatusCode());
        reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        line = reader.readLine();
        while (line != null) {
            System.out.println(line);
            line = reader.readLine();
        }
        System.out.println();
        System.out.println();
    }
@Test
    public void testCustomerResource() throws Exception {
        DefaultHttpClient client = new DefaultHttpClient();
        System.out.println("**** CustomerResource No Query params ***");
        HttpGet get = new HttpGet("http://localhost:9095/customers");
        HttpResponse response = client.execute(get);
        Assert.assertEquals(200, response.getStatusLine().getStatusCode());
        BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        String line = reader.readLine();
        while (line != null) {
            System.out.println(line);
            line = reader.readLine();
        }
        System.out.println("**** CustomerResource With Query params ***");
        get = new HttpGet("http://localhost:9095/customers?start=1&size=3");
        response = client.execute(get);
        Assert.assertEquals(200, response.getStatusLine().getStatusCode());
        reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        line = reader.readLine();
        while (line != null) {
            System.out.println(line);
            line = reader.readLine();
        }
        System.out.println("**** CustomerResource With UriInfo and Query params ***");
        get = new HttpGet("http://localhost:9095/customers/uriinfo?start=2&size=2");
        response = client.execute(get);
        Assert.assertEquals(200, response.getStatusLine().getStatusCode());
        reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        line = reader.readLine();
        while (line != null) {
            System.out.println(line);
            line = reader.readLine();
        }
    }
public static String digestMd5(String str) {
        if (str == null || str.length() == 0) {
            throw new IllegalArgumentException("文字列がNull、または空です。");
        }
        MessageDigest md5;
        byte[] enclyptedHash;
        try {
            md5 = MessageDigest.getInstance("MD5");
            md5.update(str.getBytes());
            enclyptedHash = md5.digest();
        } catch (NoSuchAlgorithmException ex) {
            ex.printStackTrace();
            return "";
        }
        return bytesToHexString(enclyptedHash);
    }
public static void main(String[] args) {
        int[] mas = { 5, 10, 20, -30, 55, -60, 9, -40, -20 };
        int next;
        for (int a = 0; a < mas.length; a++) {
            for (int i = 0; i < mas.length - 1; i++) {
                if (mas[i] > mas[i + 1]) {
                    next = mas[i];
                    mas[i] = mas[i + 1];
                    mas[i + 1] = next;
                }
            }
        }
        for (int i = 0; i < mas.length; i++) System.out.print(" " + mas[i]);
    }
private byte[] getResponseFromHttp(byte[] ocspPackage, URL url) throws IOException {
        HttpURLConnection con = (HttpURLConnection) url.openConnection();
        con.setDoOutput(true);
        try {
            con.setRequestMethod(OCSPLoginModule.POST);
        } catch (ProtocolException e) {
            throw new IOException(e.getMessage(), e);
        }
        con.setRequestProperty(OCSPLoginModule.CONTENT_TYPE, OCSPLoginModule.APPLICATION_OCSP_REQUEST);
        OutputStream os = null;
        try {
            os = con.getOutputStream();
            os.write(ocspPackage);
        } catch (IOException e) {
            logger.error(e.getMessage());
            throw e;
        } finally {
            os.close();
        }
        InputStream in = null;
        byte[] respBytes = null;
        ByteArrayOutputStream baos = null;
        try {
            baos = new ByteArrayOutputStream();
            in = con.getInputStream();
            int b = in.read();
            while (b != -1) {
                baos.write(b);
                b = in.read();
            }
            baos.flush();
        } finally {
            in.close();
            con.disconnect();
        }
        respBytes = baos.toByteArray();
        return respBytes;
    }
public static String deleteTag(String tag_id) {
        String so = OctopusErrorMessages.UNKNOWN_ERROR;
        if (tag_id == null || tag_id.trim().equals("")) {
            return OctopusErrorMessages.TAG_ID_CANT_BE_EMPTY;
        }
        DBConnection theConnection = null;
        try {
            theConnection = DBServiceManager.allocateConnection();
            theConnection.setAutoCommit(false);
            String query = "DELETE FROM tr_translation WHERE tr_translation_trtagid=?";
            PreparedStatement state = theConnection.prepareStatement(query);
            state.setString(1, tag_id);
            state.executeUpdate();
            String query2 = "DELETE FROM tr_tag WHERE tr_tag_id=? ";
            PreparedStatement state2 = theConnection.prepareStatement(query2);
            state2.setString(1, tag_id);
            state2.executeUpdate();
            theConnection.commit();
            so = OctopusErrorMessages.ACTION_DONE;
        } catch (SQLException e) {
            try {
                theConnection.rollback();
            } catch (SQLException ex) {
            }
            so = OctopusErrorMessages.ERROR_DATABASE;
        } finally {
            if (theConnection != null) {
                try {
                    theConnection.setAutoCommit(true);
                } catch (SQLException ex) {
                }
                theConnection.release();
            }
        }
        return so;
    }
private String getMd5(String base64image) {
        String token = null;
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(base64image.getBytes());
            BigInteger hash = new BigInteger(1, md5.digest());
            token = hash.toString(16);
        } catch (NoSuchAlgorithmException nsae) {
        }
        return token;
    }
protected int doExecuteUpdate(PreparedStatement statement) throws SQLException {
        connection.setAutoCommit(isAutoCommit());
        int rs = -1;
        try {
            lastError = null;
            rs = statement.executeUpdate();
            if (!isAutoCommit()) connection.commit();
        } catch (Exception ex) {
            if (!isAutoCommit()) {
                lastError = ex;
                connection.rollback();
                LogUtils.log(Level.SEVERE, "Transaction is being rollback. Error: " + ex.toString());
            }
        } finally {
            if (statement != null) statement.close();
        }
        return rs;
    }
protected int doExecuteInsert(PreparedStatement statement, Table data) throws SQLException {
        ResultSet rs = null;
        int result = -1;
        try {
            lastError = null;
            result = statement.executeUpdate();
            if (!isAutoCommit()) connection.commit();
            rs = statement.getGeneratedKeys();
            while (rs.next()) {
                FieldUtils.setValue(data, data.key, rs.getObject(1));
            }
        } catch (SQLException ex) {
            if (!isAutoCommit()) {
                lastError = ex;
                connection.rollback();
                LogUtils.log(Level.SEVERE, "Transaction is being rollback. Error: " + ex.toString());
            } else {
                throw ex;
            }
        } finally {
            if (statement != null) statement.close();
            if (rs != null) rs.close();
        }
        return result;
    }
public static String CreateHashValue(Connection dbConnection) throws Exception {
        String sResult = null;
        if (dbConnection == null) throw new Exception("Connection object is null...");
        HashDBState.m_oLogger.debug("Start creating hash from database object.");
        ArrayList aStatementList = new ArrayList();
        StringBuffer aResults = new StringBuffer();
        StringBuffer aHashValue = new StringBuffer();
        HashDBState.fillStatementList(aStatementList, dbConnection);
        if ((aStatementList != null) && (aStatementList.size() > 0)) {
            Iterator it = aStatementList.iterator();
            while (it.hasNext()) {
                String sCurStatement = (String) it.next();
                HashDBState.addTableContent(aResults, sCurStatement, dbConnection);
            }
        } else {
            throw new Exception("No statements generated... aborting hashing");
        }
        try {
            dbConnection.commit();
        } catch (SQLException e) {
            m_oLogger.error("Error while committing hash statements: " + e.getMessage(), e);
        }
        MessageDigest oSHA1 = MessageDigest.getInstance("SHA-1");
        oSHA1.reset();
        oSHA1.update(aResults.toString().getBytes());
        byte[] aMessageBytes = oSHA1.digest();
        if ((aMessageBytes != null) && (aMessageBytes.length > 0)) {
            for (int iCurByte = 0; iCurByte < aMessageBytes.length; iCurByte++) {
                aHashValue.append(HashDBState.toHexString(aMessageBytes[iCurByte]));
            }
        }
        sResult = aHashValue.toString();
        HashDBState.m_oLogger.debug("Hashvalue of database is: " + sResult);
        return sResult;
    }