semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
protected void processAddByURLSubmit(URL url, String invalidUrlMsg) {
            if (!this.hasError()) {
                try {
                    StringWriter xmlSourceWriter = new StringWriter();
                    IOUtils.copy(url.openStream(), xmlSourceWriter);
                    processSubmittedDoap(xmlSourceWriter.toString());
                } catch (FileNotFoundException e) {
                    Session.get().error(invalidUrlMsg);
                    logger.warn("Error processing URL: " + invalidUrlMsg);
                } catch (IOException e) {
                    setResponsePage(new ErrorReportPage(new UserReportableException("Unable to add doap using RDF supplied", DoapFormPage.class, e)));
                    logger.warn("Error processing URL: " + url + "; " + e.getMessage(), e);
                }
            }
        }
public String kodetu(String testusoila) {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("SHA");
            md.update(testusoila.getBytes("UTF-8"));
        } catch (NoSuchAlgorithmException e) {
            new MezuLeiho("Ez da zifraketa algoritmoa aurkitu", "Ados", "Zifraketa Arazoa", JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            new MezuLeiho("Errorea kodetzerakoan", "Ados", "Kodeketa Errorea", JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        }
        byte raw[] = md.digest();
        String hash = (new BASE64Encoder()).encode(raw);
        return hash;
    }
private void transform(CommandLine commandLine) throws IOException {
        Reader reader;
        if (commandLine.hasOption('i')) {
            reader = createFileReader(commandLine.getOptionValue('i'));
        } else {
            reader = createStandardInputReader();
        }
        Writer writer;
        if (commandLine.hasOption('o')) {
            writer = createFileWriter(commandLine.getOptionValue('o'));
        } else {
            writer = createStandardOutputWriter();
        }
        String mapRule = commandLine.getOptionValue("m");
        try {
            SrxTransformer transformer = new SrxAnyTransformer();
            Map<String, Object> parameterMap = new HashMap<String, Object>();
            if (mapRule != null) {
                parameterMap.put(Srx1Transformer.MAP_RULE_NAME, mapRule);
            }
            transformer.transform(reader, writer, parameterMap);
        } finally {
            cleanupReader(reader);
            cleanupWriter(writer);
        }
    }
public void testTransactions() throws Exception {
        con = TestUtil.openDB();
        Statement st;
        ResultSet rs;
        con.setAutoCommit(false);
        assertTrue(!con.getAutoCommit());
        con.setAutoCommit(true);
        assertTrue(con.getAutoCommit());
        st = con.createStatement();
        st.executeUpdate("insert into test_a (imagename,image,id) values ('comttest',1234,5678)");
        con.setAutoCommit(false);
        st.executeUpdate("update test_a set image=9876 where id=5678");
        con.commit();
        rs = st.executeQuery("select image from test_a where id=5678");
        assertTrue(rs.next());
        assertEquals(9876, rs.getInt(1));
        rs.close();
        st.executeUpdate("update test_a set image=1111 where id=5678");
        con.rollback();
        rs = st.executeQuery("select image from test_a where id=5678");
        assertTrue(rs.next());
        assertEquals(9876, rs.getInt(1));
        rs.close();
        TestUtil.closeDB(con);
    }
public boolean isPasswordValid(String encPass, String rawPass, Object salt) throws DataAccessException {
        boolean bMatch = false;
        try {
            String strSalt = (String) salt;
            byte[] baSalt = Hex.decodeHex(strSalt.toCharArray());
            MessageDigest md = MessageDigest.getInstance(HASH_ALGORITHM);
            md.update(rawPass.getBytes(CHAR_ENCODING));
            md.update(baSalt);
            byte[] baCalculatedHash = md.digest();
            byte[] baStoredHash = Hex.decodeHex(encPass.toCharArray());
            bMatch = MessageDigest.isEqual(baCalculatedHash, baStoredHash);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return bMatch;
    }
protected boolean checkResource(final String resourceName) {
        boolean isValid = true;
        HttpURLConnection.setFollowRedirects(false);
        try {
            final URL url = new URL(buildUrl(new Resource(resourceName).getName()));
            logger.debug("check url: " + url.toString());
            final HttpURLConnection headConnection = (HttpURLConnection) url.openConnection();
            addHeaders(headConnection);
            headConnection.setRequestMethod("HEAD");
            headConnection.setDoOutput(true);
            int statusCode = headConnection.getResponseCode();
            if (statusCode == HttpURLConnection.HTTP_MOVED_PERM) {
                isValid = false;
                logger.debug("responseCode: " + statusCode);
            } else {
                logger.debug("responseCode: " + statusCode);
            }
        } catch (MalformedURLException e) {
            logger.error(e.toString());
            isValid = false;
        } catch (ProtocolException e) {
            logger.error(e.toString());
            isValid = false;
        } catch (IOException e) {
            logger.error(e.toString());
            isValid = false;
        }
        HttpURLConnection.setFollowRedirects(true);
        return isValid;
    }
public APIResponse create(Application application) throws Exception {
        APIResponse response = new APIResponse();
        connection = (HttpURLConnection) new URL(url + "/api/application/create").openConnection();
        connection.setDoOutput(true);
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Content-Type", "application/json; charset=utf-8");
        connection.setUseCaches(false);
        connection.setConnectTimeout(TIMEOUT);
        connection.connect();
        marshaller.marshal(application, 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("Create Application Error Code: Http (" + connection.getResponseCode() + ")");
        }
        connection.disconnect();
        return response;
    }
public APIResponse delete(String id) throws Exception {
        APIResponse response = new APIResponse();
        connection = (HttpURLConnection) new URL(url + "/api/application/delete/" + id).openConnection();
        connection.setRequestMethod("DELETE");
        connection.setConnectTimeout(TIMEOUT);
        connection.connect();
        if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
            response.setDone(true);
            response.setMessage("Application Deleted!");
        } else {
            response.setDone(false);
            response.setMessage("Delete Application Error Code: Http (" + connection.getResponseCode() + ")");
        }
        connection.disconnect();
        return response;
    }
public APIResponse update(Application application) throws Exception {
        APIResponse response = new APIResponse();
        connection = (HttpURLConnection) new URL(url + "/api/application/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(application, 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 Application Error Code: Http (" + connection.getResponseCode() + ")");
        }
        connection.disconnect();
        return response;
    }
private String readLine(final String urlStr) {
        BufferedReader reader;
        String line = null;
        try {
            URL url = new URL(urlStr);
            reader = new BufferedReader(new InputStreamReader(url.openStream()));
            line = reader.readLine();
        } catch (MalformedURLException e) {
            log.error(e, e);
        } catch (IOException e) {
            log.error(e, e);
        }
        return line;
    }
protected void copyFile(final File in, final File out) throws IOException {
        final FileChannel inChannel = new FileInputStream(in).getChannel();
        final FileChannel outChannel = new FileOutputStream(out).getChannel();
        try {
            inChannel.transferTo(0, inChannel.size(), outChannel);
        } catch (final IOException e) {
            throw e;
        } finally {
            if (inChannel != null) {
                inChannel.close();
            }
            if (outChannel != null) {
                outChannel.close();
            }
        }
    }
public static void replaceAll(File file, String substitute, String substituteReplacement) throws IOException {
        log.debug("Replace " + substitute + " by " + substituteReplacement);
        Pattern pattern = Pattern.compile(substitute);
        FileInputStream fis = new FileInputStream(file);
        FileChannel fc = fis.getChannel();
        int sz = (int) fc.size();
        MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, sz);
        Charset charset = Charset.forName("ISO-8859-15");
        CharsetDecoder decoder = charset.newDecoder();
        CharBuffer cb = decoder.decode(bb);
        Matcher matcher = pattern.matcher(cb);
        String outString = matcher.replaceAll(substituteReplacement);
        log.debug(outString);
        FileOutputStream fos = new FileOutputStream(file.getAbsolutePath());
        PrintStream ps = new PrintStream(fos);
        ps.print(outString);
        ps.close();
        fos.close();
    }
public void writeToStream(OutputStream out) throws IOException {
        InputStream result = null;
        if (tempFile != null) {
            InputStream input = new BufferedInputStream(new FileInputStream(tempFile));
            IOUtils.copy(input, out);
            IOUtils.closeQuietly(input);
        } else if (tempBuffer != null) {
            out.write(tempBuffer);
        }
    }
private void initializeTree() {
        InputStreamReader reader = null;
        BufferedReader buffReader = null;
        try {
            for (int i = 0; i < ORDER.length; i++) {
                int index = ORDER[i];
                String indexName = index < 10 ? "0" + index : (index > 20 ? "big" : "" + index);
                URL url = EmptyClass.class.getResource("engchar" + indexName + ".dic");
                logger.info("... Loading: " + "engchar" + indexName + ".dic = {" + url + "}");
                reader = new InputStreamReader(url.openStream());
                buffReader = new BufferedReader(reader);
                String line = null;
                String word = null;
                do {
                    line = buffReader.readLine();
                    if (line != null) {
                        boolean plural = line.endsWith("/S");
                        boolean forbidden = line.endsWith("/X");
                        if (plural) {
                            int stringIndex = line.indexOf("/S");
                            word = new String(line.substring(0, stringIndex));
                        } else if (forbidden) {
                            int stringIndex = line.indexOf("/X");
                            word = new String(line.substring(0, stringIndex));
                        } else {
                            word = line.toString();
                        }
                        if (tree == null) {
                            tree = new BKTree();
                        }
                        tree.insertDictionaryWord(word, plural, forbidden);
                    }
                } while (line != null);
            }
            logger.debug("Loading supplemental dictionary...");
            List<String> listOfWords = KSupplementalDictionaryUtil.getWords();
            for (String word : listOfWords) {
                tree.insertDictionaryWord(word, false, false);
            }
            initialized = true;
        } catch (Exception exception) {
            logger.error("Error", exception);
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (Exception ex) {
                }
            }
            if (buffReader != null) {
                try {
                    buffReader.close();
                } catch (Exception ex) {
                }
            }
        }
    }
public void writeToFile(File file, File source) throws IOException {
        BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(file));
        BufferedInputStream bin = new BufferedInputStream(new FileInputStream(source));
        bin.skip(header.getHeaderEndingOffset());
        for (long i = 0; i < this.streamLength; i++) {
            bout.write(bin.read());
        }
        bin.close();
        bout.close();
    }
protected void readInput(String filename, List<String> list) throws IOException {
        URL url = GeneratorBase.class.getResource(filename);
        if (url == null) {
            throw new FileNotFoundException("specified file not available - " + filename);
        }
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new InputStreamReader(url.openStream()));
            String line;
            while ((line = reader.readLine()) != null) {
                list.add(line.trim());
            }
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                }
            }
        }
    }
public String call() throws Exception {
        InputStream stream = url.openStream();
        StringBuffer sb = new StringBuffer();
        BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line);
        }
        return sb.toString();
    }
@Test
    public void test20_badSmtp() throws Exception {
        Db db = DbConnection.defaultCieDbRW();
        try {
            db.begin();
            oldSmtp = Config.getProperty(db, "com.entelience.mail.MailHelper.hostName", "localhost");
            oldSupport = Config.getProperty(db, "com.entelience.esis.feature.SupportNotifier", false);
            Config.setProperty(db, "com.entelience.mail.MailHelper.hostName", "127.0.10.1", 1);
            Config.setProperty(db, "com.entelience.esis.feature.SupportNotifier", "true", 1);
            PreparedStatement pst = db.prepareStatement("DELETE FROM t_client_errors");
            db.executeUpdate(pst);
            db.commit();
        } catch (Exception e) {
            db.rollback();
        } finally {
            db.safeClose();
        }
    }
@Test
    public void test30_passwordAging() throws Exception {
        Db db = DbConnection.defaultCieDbRW();
        try {
            db.begin();
            Config.setProperty(db, "com.entelience.esis.security.passwordAge", "5", 1);
            PreparedStatement pst = db.prepareStatement("UPDATE e_people SET last_passwd_change = '2006-07-01' WHERE user_name = ?");
            pst.setString(1, "esis");
            db.executeUpdate(pst);
            db.commit();
            p_logout();
            t30login1();
            assertTrue(isPasswordExpired());
            PeopleInfoLine me = getCurrentPeople();
            assertNotNull(me.getPasswordExpirationDate());
            assertTrue(me.getPasswordExpirationDate().before(DateHelper.now()));
            t30chgpasswd();
            assertFalse(isPasswordExpired());
            me = getCurrentPeople();
            assertNotNull(me.getPasswordExpirationDate());
            assertTrue(me.getPasswordExpirationDate().after(DateHelper.now()));
            p_logout();
            t30login2();
            assertFalse(isPasswordExpired());
            t30chgpasswd2();
            db.begin();
            Config.setProperty(db, "com.entelience.esis.security.passwordAge", "0", 1);
            db.commit();
        } catch (Exception e) {
            e.printStackTrace();
            db.rollback();
        } finally {
            db.safeClose();
        }
    }
private static String encryptSHA1URL(String x) throws Exception {
        java.security.MessageDigest d = null;
        d = java.security.MessageDigest.getInstance("SHA-1");
        d.reset();
        d.update(x.getBytes());
        String passwd = "";
        passwd = URLEncoder.encode(new String(d.digest()), "ISO-8859-1");
        return passwd;
    }
public String getSHA1(String input) {
        byte[] output = null;
        try {
            MessageDigest md = MessageDigest.getInstance("SHA1");
            md.update(input.getBytes());
            output = md.digest();
        } catch (Exception e) {
            System.out.println("Exception: " + e);
        }
        return StringUtils.byte2hex(output);
    }
public boolean load() {
        if (getFilename() != null && getFilename().length() > 0) {
            try {
                File file = new File(PreferencesManager.getDirectoryLocation("macros") + File.separator + getFilename());
                URL url = file.toURL();
                InputStreamReader isr = new InputStreamReader(url.openStream());
                BufferedReader br = new BufferedReader(isr);
                String line = br.readLine();
                String macro_text = "";
                while (line != null) {
                    macro_text = macro_text.concat(line);
                    line = br.readLine();
                    if (line != null) {
                        macro_text = macro_text.concat(System.getProperty("line.separator"));
                    }
                }
                code = macro_text;
            } catch (Exception e) {
                System.err.println("Exception at StoredMacro.load(): " + e.toString());
                return false;
            }
        }
        return true;
    }
private static byte[] getHashBytes(String data, String algorithm) {
        MessageDigest md;
        byte[] digest = null;
        try {
            md = MessageDigest.getInstance(algorithm);
            md.update(data.getBytes("UTF-8"), 0, data.length());
            digest = md.digest();
        } catch (NoSuchAlgorithmException e) {
        } catch (UnsupportedEncodingException e) {
        }
        return digest;
    }
private URLConnection openConnection(URL url) throws MalformedURLException, IOException {
        URLConnection connection = url.openConnection();
        if (connection instanceof HttpURLConnection) ((HttpURLConnection) connection).setInstanceFollowRedirects(false);
        connection.setUseCaches(false);
        return connection;
    }
private static void copyFile(File in, File out) {
        try {
            FileChannel sourceChannel = new FileInputStream(in).getChannel();
            FileChannel destinationChannel = new FileOutputStream(out).getChannel();
            sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
            sourceChannel.close();
            destinationChannel.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
public String parse(String queryText) throws ParseException {
        try {
            StringBuilder sb = new StringBuilder();
            queryText = Val.chkStr(queryText);
            if (queryText.length() > 0) {
                URL url = new URL(getUrl(queryText));
                InputStream in = url.openStream();
                BufferedReader reader = new BufferedReader(new InputStreamReader(in));
                String line = null;
                while ((line = reader.readLine()) != null) {
                    if (sb.length() > 0) {
                        sb.append("\r\n");
                    }
                    sb.append(line);
                }
            }
            return sb.toString();
        } catch (IOException ex) {
            throw new ParseException("Ontology parser is unable to parse term: \"" + queryText + "\" due to internal error: " + ex.getMessage());
        }
    }
private HttpURLConnection setUpHttpConnection(URL url, int length) throws IOException, ProtocolException {
        URLConnection connection = url.openConnection();
        HttpURLConnection httpConn = (HttpURLConnection) connection;
        httpConn.setRequestProperty("Content-Length", String.valueOf(length));
        httpConn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
        httpConn.setRequestProperty("SOAPAction", "\"http://www.webserviceX.NET/GetQuote\"");
        httpConn.setRequestMethod("POST");
        httpConn.setDoOutput(true);
        httpConn.setDoInput(true);
        return httpConn;
    }
public static String get(String u, String usr, String pwd) {
        String response = "";
        logger.debug("Attempting to call: " + u);
        logger.debug("Creating Authenticator: usr=" + usr + ", pwd=" + pwd);
        Authenticator.setDefault(new CustomAuthenticator(usr, pwd));
        try {
            URL url = new URL(u);
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            StringBuffer sb = new StringBuffer(0);
            String str;
            while ((str = in.readLine()) != null) {
                sb.append(str);
            }
            in.close();
            logger.debug("Response: " + sb.toString());
            response = sb.toString();
        } catch (MalformedURLException e) {
            logger.error(e);
            logger.trace(e, e);
        } catch (IOException e) {
            logger.error(e);
            logger.trace(e, e);
        }
        return response;
    }
public static Vector getVectorForm(String u, String usr, String pwd) {
        Vector response = new Vector();
        logger.debug("Attempting to call: " + u);
        logger.debug("Creating Authenticator: usr=" + usr + ", pwd=" + pwd);
        Authenticator.setDefault(new CustomAuthenticator(usr, pwd));
        try {
            URL url = new URL(u);
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String str;
            while ((str = in.readLine()) != null) {
                response.add(str);
            }
            in.close();
            logger.debug("Response: " + response.toString());
        } catch (MalformedURLException e) {
            logger.error(e);
            logger.trace(e, e);
        } catch (IOException e) {
            logger.error(e);
            logger.trace(e, e);
        }
        return response;
    }