semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private void copy(File fromFile, File toFile) throws IOException {
        String fromFileName = fromFile.getName();
        File tmpFile = new File(fromFileName);
        String toFileName = toFile.getName();
        if (!tmpFile.exists()) throw new IOException("FileCopy: " + "no such source file: " + fromFileName);
        if (!tmpFile.isFile()) throw new IOException("FileCopy: " + "can't copy directory: " + fromFileName);
        if (!tmpFile.canRead()) throw new IOException("FileCopy: " + "source file is unreadable: " + fromFileName);
        FileInputStream from = null;
        FileOutputStream to = null;
        try {
            from = new FileInputStream(tmpFile);
            File toF = new File(toFile.getCanonicalPath());
            if (!toF.exists()) ;
            toF.createNewFile();
            if (!SBCMain.DEBUG_MODE) to = new FileOutputStream(toFile); else to = new FileOutputStream(toF);
            byte[] buffer = new byte[4096];
            int bytesRead;
            while ((bytesRead = from.read(buffer)) != -1) to.write(buffer, 0, bytesRead);
        } finally {
            if (from != null) try {
                from.close();
            } catch (IOException e) {
                ;
            }
            if (to != null) try {
                to.close();
            } catch (IOException e) {
                ;
            }
        }
    }
private void loadDBpediaOntology() {
        try {
            URL url = new URL("http://downloads.dbpedia.org/3.6/dbpedia_3.6.owl.bz2");
            InputStream is = new BufferedInputStream(url.openStream());
            CompressorInputStream in = new CompressorStreamFactory().createCompressorInputStream("bzip2", is);
            dbPediaOntology = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(in);
            reasoner = PelletReasonerFactory.getInstance().createNonBufferingReasoner(dbPediaOntology);
            reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (CompressorException e) {
            e.printStackTrace();
        } catch (OWLOntologyCreationException e) {
            e.printStackTrace();
        }
    }
public static String SHA1(String string) throws XLWrapException {
        MessageDigest md;
        try {
            md = MessageDigest.getInstance("SHA-1");
        } catch (NoSuchAlgorithmException e) {
            throw new XLWrapException("SHA-1 message digest is not available.");
        }
        byte[] data = new byte[40];
        md.update(string.getBytes());
        data = md.digest();
        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < data.length; i++) {
            int halfbyte = (data[i] >>> 4) & 0x0F;
            int two_halfs = 0;
            do {
                if ((0 <= halfbyte) && (halfbyte <= 9)) buf.append((char) ('0' + halfbyte)); else buf.append((char) ('a' + (halfbyte - 10)));
                halfbyte = data[i] & 0x0F;
            } while (two_halfs++ < 1);
        }
        return buf.toString();
    }
public static void main(String[] args) throws Exception {
        FileChannel fc = new FileOutputStream("data.txt").getChannel();
        fc.write(ByteBuffer.wrap("some text ".getBytes()));
        fc.close();
        fc = new RandomAccessFile("data.txt", "rw").getChannel();
        fc.position(fc.size());
        fc.write(ByteBuffer.wrap("some more".getBytes()));
        fc.close();
        fc = new FileInputStream("data.txt").getChannel();
        ByteBuffer buff = ByteBuffer.allocate(BSIZE);
        fc.read(buff);
        buff.flip();
        while (buff.hasRemaining()) {
            PrintUtil.prt((char) buff.get());
        }
    }
public static void executeUpdate(Database db, String... statements) throws SQLException {
        Connection con = null;
        Statement stmt = null;
        try {
            con = getConnection(db);
            con.setAutoCommit(false);
            stmt = con.createStatement();
            for (String statement : statements) {
                stmt.executeUpdate(statement);
            }
            con.commit();
        } catch (SQLException e) {
            try {
                con.rollback();
            } catch (SQLException e1) {
            }
            throw e;
        } finally {
            closeStatement(stmt);
            closeConnection(con);
        }
    }
private void storeFieldMap(Content c, Connection conn) throws SQLException {
        SQLDialect dialect = getDatabase().getSQLDialect();
        if (TRANSACTIONS_ENABLED) {
            conn.setAutoCommit(false);
        }
        try {
            Object thisKey = c.getPrimaryKey();
            deleteFieldContent(thisKey, conn);
            PreparedStatement ps = null;
            StructureItem nextItem;
            Map fieldMap = c.getFieldMap();
            String type;
            Object value, siKey;
            for (Iterator i = c.getStructure().getStructureItems().iterator(); i.hasNext(); ) {
                nextItem = (StructureItem) i.next();
                type = nextItem.getDataType().toUpperCase();
                siKey = nextItem.getPrimaryKey();
                value = fieldMap.get(nextItem.getName());
                if (type.equals(StructureItem.DATE)) {
                    ps = conn.prepareStatement(sqlConstants.get("INSERT_DATE_FIELD"));
                    ps.setObject(1, thisKey);
                    ps.setObject(2, siKey);
                    dialect.setDate(ps, 3, (java.util.Date) value);
                    ps.executeUpdate();
                } else if (type.equals(StructureItem.INT) || type.equals(StructureItem.FLOAT) || type.equals(StructureItem.VARCHAR)) {
                    ps = conn.prepareStatement(sqlConstants.get("INSERT_" + type + "_FIELD"));
                    ps.setObject(1, thisKey);
                    ps.setObject(2, siKey);
                    if (value != null) {
                        ps.setObject(3, value);
                    } else {
                        int sqlType = Types.INTEGER;
                        if (type.equals(StructureItem.FLOAT)) {
                            sqlType = Types.FLOAT;
                        } else if (type.equals(StructureItem.VARCHAR)) {
                            sqlType = Types.VARCHAR;
                        }
                        ps.setNull(3, sqlType);
                    }
                    ps.executeUpdate();
                } else if (type.equals(StructureItem.TEXT)) {
                    setTextField(c, siKey, (String) value, conn);
                }
                if (ps != null) {
                    ps.close();
                    ps = null;
                }
            }
            if (TRANSACTIONS_ENABLED) {
                conn.commit();
            }
        } catch (SQLException e) {
            if (TRANSACTIONS_ENABLED) {
                conn.rollback();
            }
            throw e;
        } finally {
            if (TRANSACTIONS_ENABLED) {
                conn.setAutoCommit(true);
            }
        }
    }
private static String readJarURL(URL url) throws IOException {
        JarURLConnection juc = (JarURLConnection) url.openConnection();
        InputStream in = juc.getInputStream();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        int i = in.read();
        while (i != -1) {
            out.write(i);
            i = in.read();
        }
        return out.toString();
    }
public static String getMessageDigest(String input) {
        if (input == null) {
            log.warn("Returning SHA-1 null value for null input");
            return null;
        }
        try {
            MessageDigest md = MessageDigest.getInstance("SHA-1");
            md.update(input.getBytes("UTF-8"));
            byte[] bytes = md.digest();
            return new BASE64Encoder().encode(bytes);
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalStateException(e.getMessage());
        } catch (UnsupportedEncodingException e) {
            throw new IllegalStateException(e.getMessage());
        }
    }
public static String getMessageDigest(String[] inputs) {
        if (inputs.length == 0) return null;
        try {
            MessageDigest sha = MessageDigest.getInstance("SHA-1");
            for (String input : inputs) sha.update(input.getBytes());
            byte[] hash = sha.digest();
            String CPass = "";
            int h = 0;
            String s = "";
            for (int i = 0; i < 20; i++) {
                h = hash[i];
                if (h < 0) h += 256;
                s = Integer.toHexString(h);
                if (s.length() < 2) CPass = CPass.concat("0");
                CPass = CPass.concat(s);
            }
            CPass = CPass.toUpperCase();
            return CPass;
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalStateException(e.getMessage());
        }
    }
public String md5(String password) {
        MessageDigest m = null;
        try {
            m = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException ex) {
        }
        m.update(password.getBytes(), 0, password.length());
        return new BigInteger(1, m.digest()).toString(16);
    }
private static String executeQueryWithXbird(String queryFile, String replace) throws XQueryException, IOException, URISyntaxException {
        URL url = DocumentTableTest.class.getResource(queryFile);
        URI uri = url.toURI();
        String query = IOUtils.toString(url.openStream());
        XQueryProcessor processor = new XQueryProcessor();
        query = query.replace("fn:doc(\"auction.xml\")", replace);
        if (DEBUG_LIGHT) {
            System.err.println(query);
        }
        XQueryModule mod = processor.parse(query, uri);
        StringWriter res_sw = new StringWriter();
        Serializer ser = new SAXSerializer(new SAXWriter(res_sw), res_sw);
        processor.execute(mod, ser);
        String result = res_sw.toString();
        return result;
    }
private static String executeQueryWithSaxon(String queryFile) throws XPathException, FileNotFoundException, IOException, URISyntaxException {
        URL url = DocumentTableTest.class.getResource(queryFile);
        URI uri = url.toURI();
        String query = IOUtils.toString(url.openStream());
        Configuration config = new Configuration();
        config.setHostLanguage(Configuration.XQUERY);
        StaticQueryContext staticContext = new StaticQueryContext(config);
        staticContext.setBaseURI(uri.toString());
        XQueryExpression exp = staticContext.compileQuery(query);
        Properties props = new Properties();
        props.setProperty(SaxonOutputKeys.WRAP, "no");
        props.setProperty(OutputKeys.INDENT, "no");
        props.setProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        StringWriter res_sw = new StringWriter();
        DynamicQueryContext dynamicContext = new DynamicQueryContext(config);
        exp.run(dynamicContext, new StreamResult(res_sw), props);
        return res_sw.toString();
    }
Bitmap downloadImage(String uri) {
            try {
                mGetMethod.setURI(new URI(uri));
                HttpResponse resp = mClient.execute(mGetMethod);
                if (resp.getStatusLine().getStatusCode() < 400) {
                    InputStream is = resp.getEntity().getContent();
                    String tmp = convertStreamToString(is);
                    Log.d(TAG, "hoge" + tmp);
                    is.close();
                    return null;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }
public String kodetu(String testusoila) {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("SHA");
        } catch (NoSuchAlgorithmException e) {
            new MezuLeiho("Ez da zifraketa algoritmoa aurkitu", "Ados", "Zifraketa Arazoa", JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        }
        try {
            md.update(testusoila.getBytes("UTF-8"));
        } 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 execute(String file, String[] ebms, String[] eems, String[] ims, String[] efms) throws BuildException {
        if (verbose) {
            System.out.println("Preprocessing file " + file + " (type: " + type + ")");
        }
        try {
            File targetFile = new File(file);
            FileReader fr = new FileReader(targetFile);
            BufferedReader reader = new BufferedReader(fr);
            File preprocFile = File.createTempFile(targetFile.getName(), "tmp", targetFile.getParentFile());
            FileWriter fw = new FileWriter(preprocFile);
            BufferedWriter writer = new BufferedWriter(fw);
            int result = preprocess(reader, writer, ebms, eems, ims, efms);
            reader.close();
            writer.close();
            switch(result) {
                case OVERWRITE:
                    if (!targetFile.delete()) {
                        System.out.println("Can't overwrite target file with preprocessed file");
                        throw new BuildException("Can't overwrite target file " + target + " with preprocessed file");
                    }
                    preprocFile.renameTo(targetFile);
                    if (verbose) {
                        System.out.println("File " + preprocFile.getName() + " modified.");
                    }
                    modifiedCnt++;
                    break;
                case REMOVE:
                    if (!targetFile.delete()) {
                        System.out.println("Can't delete target file");
                        throw new BuildException("Can't delete target file " + target);
                    }
                    if (!preprocFile.delete()) {
                        System.out.println("Can't delete temporary preprocessed file " + preprocFile.getName());
                        throw new BuildException("Can't delete temporary preprocessed file " + preprocFile.getName());
                    }
                    if (verbose) {
                        System.out.println("File " + preprocFile.getName() + " removed.");
                    }
                    removedCnt++;
                    break;
                case KEEP:
                    if (!preprocFile.delete()) {
                        System.out.println("Can't delete temporary preprocessed file " + preprocFile.getName());
                        throw new BuildException("Can't delete temporary preprocessed file " + preprocFile.getName());
                    }
                    break;
                default:
                    throw new BuildException("Unexpected preprocessing result for file " + preprocFile.getName());
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new BuildException(e.getMessage());
        }
    }
public Bits write(Map data) throws IOException {
        String pictureurl = (String) data.get("pictureurl");
        URL url = new URL(pictureurl);
        InputStream is = url.openStream();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        int buf = is.read();
        while (buf >= 0) {
            baos.write(buf);
            buf = is.read();
        }
        return BitUtils._concat(BitUtils._bitsUI16(TypeUtils.toLong(data.get("shapeId"))), BitUtils._bytesToBits(baos.toByteArray()));
    }
public static String encryptePassword(String md5key, String passwordAccount, String encryptedPassword, int passwdenc) throws UnsupportedEncodingException, NoSuchAlgorithmException {
        MessageDigest md = MessageDigest.getInstance(Constants.ALGORITHM);
        switch(passwdenc) {
            case 1:
                md.update((md5key + encryptedPassword).getBytes("8859_1"));
                break;
            case 2:
                md.update((encryptedPassword + md5key).getBytes("8859_1"));
                break;
            default:
                return null;
        }
        return new String(md.digest());
    }
public static boolean checkEncryptedPassword(String md5key, String passwordAccount, String encryptedPassword, int passwdenc) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest md = MessageDigest.getInstance(Constants.ALGORITHM);
        switch(passwdenc) {
            case 1:
                md.update((md5key + encryptedPassword).getBytes("8859_1"));
                return md.digest().equals(passwordAccount.getBytes("8859_1"));
            case 2:
                md.update((encryptedPassword + md5key).getBytes("8859_1"));
                return md.digest().equals(passwordAccount.getBytes("8859_1"));
            default:
                return false;
        }
    }
public static byte[] getbytes(String host, int port, String cmd) {
        String result = "GetHtmlFromServer no answer";
        String tmp = "";
        result = "";
        try {
            tmp = "http://" + host + ":" + port + "/" + cmd;
            URL url = new URL(tmp);
            if (1 == 2) {
                BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
                String str;
                while ((str = in.readLine()) != null) {
                    result += str;
                }
                in.close();
                return result.getBytes();
            } else {
                HttpURLConnection c = (HttpURLConnection) url.openConnection();
                c.setConnectTimeout(2 * 1000);
                c.setRequestMethod("GET");
                c.connect();
                int amt = c.getContentLength();
                InputStream in = c.getInputStream();
                MojasiWriter writer = new MojasiWriter();
                byte[] buff = new byte[256];
                while (writer.size() < amt) {
                    int got = in.read(buff);
                    if (got < 0) break;
                    writer.pushBytes(buff, got);
                }
                in.close();
                c.disconnect();
                return writer.getBytes();
            }
        } catch (MalformedURLException e) {
            System.err.println(tmp + " " + e);
        } catch (IOException e) {
            ;
        }
        return null;
    }
public static byte[] excutePostRaw(String targetURL, byte[] postdata) {
        URL url;
        HttpURLConnection connection = null;
        try {
            url = new URL(targetURL);
            connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            connection.setRequestProperty("Content-Length", "" + Integer.toString(postdata.length));
            connection.setRequestProperty("Content-Language", "en-US");
            connection.setUseCaches(false);
            connection.setDoInput(true);
            connection.setDoOutput(true);
            DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
            wr.write(postdata);
            wr.flush();
            wr.close();
            int amt = connection.getContentLength();
            InputStream in = connection.getInputStream();
            MojasiWriter writer = new MojasiWriter();
            byte[] buff = new byte[256];
            while (writer.size() < amt) {
                int got = in.read(buff);
                if (got < 0) break;
                writer.pushBytes(buff, got);
                if (writer.size() > 1) System.out.println();
            }
            in.close();
            connection.disconnect();
            return writer.getBytes();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        } finally {
            if (connection != null) {
                connection.disconnect();
            }
        }
    }
private String getResourceAsString(final String name) throws IOException {
        final InputStream is = JiBXTestCase.class.getResourceAsStream(name);
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        IOUtils.copyAndClose(is, baos);
        return baos.toString();
    }
public static URLConnection getURLConnection(URL url, boolean ignoreBadCertificates) throws KeyManagementException, NoSuchAlgorithmException, UnknownHostException, IOException {
        SSLSocketFactory sslSocketFactory = null;
        if (ignoreBadCertificates) {
            SSLContext sslContext = SSLContext.getInstance("SSL");
            sslContext.init(null, getAllTrustingTrustManager(), new java.security.SecureRandom());
            sslSocketFactory = sslContext.getSocketFactory();
        } else {
            sslSocketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
        }
        HttpsURLConnection.setDefaultSSLSocketFactory(sslSocketFactory);
        return url.openConnection();
    }
public Object invoke(Invocation invocation) throws Throwable {
        SmartRef smartRef = (SmartRef) invocation.getValue(Invocation.SMARTREF);
        HttpURLConnection connection = null;
        ObjectOutputStream out = null;
        URL url = null;
        try {
            url = new URL(smartRef.getProperties().getProperty("org.smartcc.connector.url"));
            url = new URL(url, smartRef.getLookup());
            connection = (HttpURLConnection) url.openConnection();
            connection.setRequestProperty("Content-Type", "application/octet-stream");
            connection.setDoOutput(true);
            connection.setDoInput(true);
            connection.setUseCaches(false);
            out = new ObjectOutputStream(connection.getOutputStream());
            out.writeObject(invocation);
            out.flush();
        } catch (ObjectStreamException e) {
            System.err.println("error: during serialization");
            throw new EJBException("error: during serialization", e);
        } catch (IOException e) {
            System.err.println("error: could not connect to " + url);
            throw new ConnectIOException("could not connect to " + url, e);
        } finally {
            try {
                out.close();
            } catch (Exception e) {
            }
        }
        boolean isThrowable = false;
        Object result = null;
        ObjectInputStream in = null;
        try {
            in = new ObjectInputStream(connection.getInputStream());
            isThrowable = in.readBoolean();
            if (isThrowable || !invocation.getMethod().getReturnType().equals(void.class)) result = in.readObject();
        } catch (ObjectStreamException e) {
            System.err.println("error: during deserialization");
            throw new EJBException("error: during deserialization", e);
        } catch (IOException e) {
            System.err.println("error: could not connect to " + url);
            throw new ConnectIOException("could not connect to " + url, e);
        } finally {
            try {
                in.close();
            } catch (Exception e) {
            }
        }
        if (isThrowable) throw (Throwable) result;
        return result;
    }