semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
protected static String readAFewChars(URL url) throws IOException {
        StringBuffer buf = new StringBuffer(10);
        Reader reader = new InputStreamReader(url.openStream());
        for (int i = 0; i < 10; i++) {
            int c = reader.read();
            if (c == -1) {
                break;
            }
            buf.append((char) c);
        }
        reader.close();
        return buf.toString();
    }
public static void main(String[] args) {
        try {
            int encodeFlag = 0;
            if (args[0].equals("-e")) {
                encodeFlag = Base64.ENCODE;
            } else if (args[0].equals("-d")) {
                encodeFlag = Base64.DECODE;
            }
            String infile = args[1];
            String outfile = args[2];
            File fin = new File(infile);
            FileInputStream fis = new FileInputStream(fin);
            BufferedInputStream bis = new BufferedInputStream(fis);
            Base64.InputStream b64in = new Base64.InputStream(bis, encodeFlag | Base64.DO_BREAK_LINES);
            File fout = new File(outfile);
            FileOutputStream fos = new FileOutputStream(fout);
            BufferedOutputStream bos = new BufferedOutputStream(fos);
            byte[] buff = new byte[1024];
            int read = -1;
            while ((read = b64in.read(buff)) >= 0) {
                bos.write(buff, 0, read);
            }
            bos.close();
            b64in.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
protected Scanner loadSource(String country) {
        if (httpProxy != null && httpProxy.isEnabled()) {
            System.setProperty("proxySet", "true");
            System.setProperty("http.proxyHost", httpProxy.getUrl());
            System.setProperty("http.proxyPort", Integer.toString(httpProxy.getPort()));
        }
        try {
            URL url = new URL(this.url + country);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("GET");
            connection.setUseCaches(false);
            return new Scanner(connection.getInputStream());
        } catch (MalformedURLException e) {
            return null;
        } catch (ProtocolException e) {
            return null;
        } catch (IOException e) {
            return null;
        }
    }
public static String encryptMD5(String str) {
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(str.getBytes());
            byte[] hash = md5.digest();
            md5.reset();
            return Format.hashToHex(hash);
        } catch (java.security.NoSuchAlgorithmException nsae0) {
            return null;
        }
    }
public void addBySiteChannelPath(String siteChannelPath, String[] docTypePaths, String[] showTemplateIds) throws Exception {
        DBOperation dbo = null;
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        try {
            dbo = createDBOperation();
            connection = dbo.getConnection();
            connection.setAutoCommit(false);
            String sql = "delete from t_ip_doctype_channel where chan_path='" + siteChannelPath + "'";
            connection.createStatement().executeUpdate(sql);
            sql = "insert into t_ip_doctype_channel(doctype_path,chan_path,show_template_id) values(?,'" + siteChannelPath + "',?)";
            preparedStatement = connection.prepareStatement(sql);
            for (int i = 0; i < docTypePaths.length; i++) {
                preparedStatement.setString(1, docTypePaths[i]);
                String temp = showTemplateIds != null && i < showTemplateIds.length ? showTemplateIds[i] : "null";
                if (temp == null || temp.trim().equals("") || temp.trim().equalsIgnoreCase("null")) {
                    preparedStatement.setInt(2, Types.NULL);
                } else {
                    preparedStatement.setInt(2, Integer.parseInt(temp));
                }
                preparedStatement.executeUpdate();
            }
            connection.commit();
        } catch (Exception ex) {
            connection.rollback();
            ex.printStackTrace();
            throw ex;
        } finally {
            connection.setAutoCommit(true);
            close(resultSet, null, preparedStatement, connection, dbo);
        }
    }
private static String encodeMd5(String key) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.reset();
            md.update(key.getBytes());
            byte[] bytes = md.digest();
            String result = toHexString(bytes);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
@Override
    public EntrySet read(EntrySet set) throws ReadFailedException {
        if (!SourceCache.contains(url)) {
            SSL.certify(url);
            try {
                super.setParser(Parser.detectParser(url.openStream()));
                final PipedInputStream in = new PipedInputStream();
                final PipedOutputStream forParser = new PipedOutputStream(in);
                new Thread(new Runnable() {

                    public void run() {
                        try {
                            OutputStream out = SourceCache.startCaching(url);
                            InputStream is = url.openStream();
                            byte[] buffer = new byte[100000];
                            while (true) {
                                int amountRead = is.read(buffer);
                                if (amountRead == -1) {
                                    break;
                                }
                                forParser.write(buffer, 0, amountRead);
                                out.write(buffer, 0, amountRead);
                            }
                            forParser.close();
                            out.close();
                            SourceCache.finish(url);
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }).start();
                super.setIos(in);
            } catch (Exception e) {
                throw new ReadFailedException(e);
            }
            return super.read(set);
        } else {
            try {
                return SourceCache.get(url).read(set);
            } catch (IOException e) {
                throw new ReadFailedException(e);
            }
        }
    }
public void run() {
                        try {
                            OutputStream out = SourceCache.startCaching(url);
                            InputStream is = url.openStream();
                            byte[] buffer = new byte[100000];
                            while (true) {
                                int amountRead = is.read(buffer);
                                if (amountRead == -1) {
                                    break;
                                }
                                forParser.write(buffer, 0, amountRead);
                                out.write(buffer, 0, amountRead);
                            }
                            forParser.close();
                            out.close();
                            SourceCache.finish(url);
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
public static void sort(float norm_abst[]) {
        float temp;
        for (int i = 0; i < 7; i++) {
            for (int j = 0; j < 7; j++) {
                if (norm_abst[j] > norm_abst[j + 1]) {
                    temp = norm_abst[j];
                    norm_abst[j] = norm_abst[j + 1];
                    norm_abst[j + 1] = temp;
                }
            }
        }
        printFixed(norm_abst[0]);
        print(" ");
        printFixed(norm_abst[1]);
        print(" ");
        printFixed(norm_abst[2]);
        print(" ");
        printFixed(norm_abst[3]);
        print(" ");
        printFixed(norm_abst[4]);
        print(" ");
        printFixed(norm_abst[5]);
        print(" ");
        printFixed(norm_abst[6]);
        print(" ");
        printFixed(norm_abst[7]);
        print("\n");
    }
public FTPManager(URL location) throws IOException {
        this.client = new FTPClient();
        String host = location.getHost();
        int port = location.getPort();
        if (port < 0) {
            this.client.connect(host);
        } else {
            this.client.connect(host, port);
        }
        String[] login = StringUtils.split(location.getUserInfo(), ':');
        this.client.login(login[0], login.length > 1 ? login[1] : "");
        if (!this.client.setFileType(FTP.BINARY_FILE_TYPE)) throw new IOException("Unable to set the transfert mode");
    }
private void populateJarsFromManifest(Set<String> jars, ClassLoader loader) {
        BufferedReader reader = null;
        try {
            Enumeration<URL> e = loader.getResources("META-INF/MANIFEST.MF");
            while (e.hasMoreElements()) {
                URL url = e.nextElement();
                if (url.getPath().contains(SURE_FIRE_BOOTER_JAR)) {
                    reader = new BufferedReader(new InputStreamReader(url.openStream()));
                    String line = null;
                    StringBuffer content = new StringBuffer();
                    while ((line = reader.readLine()) != null) {
                        content.append(line.trim());
                    }
                    String cont = content.toString().replaceAll("Manifest-Version: 1.0Class-Path: ", "").replaceAll("Main-Class: org.apache.maven.surefire.booter.SurefireBooter", "");
                    for (String file : cont.split(" ")) {
                        if (file.contains("file")) {
                            jars.add(file.replaceAll("file:", ""));
                        }
                    }
                    break;
                }
            }
        } catch (IOException e) {
            log.error("", e);
        } finally {
            try {
                if (reader != null) {
                    reader.close();
                }
            } catch (Exception e) {
                log.error("", e);
            }
        }
    }
public InputSource resolveEntity(String publicId, String systemId) {
        allowXMLCatalogPI = false;
        String resolved = catalogResolver.getResolvedEntity(publicId, systemId);
        if (resolved == null && piCatalogResolver != null) {
            resolved = piCatalogResolver.getResolvedEntity(publicId, systemId);
        }
        if (resolved != null) {
            try {
                InputSource iSource = new InputSource(resolved);
                iSource.setPublicId(publicId);
                URL url = new URL(resolved);
                InputStream iStream = url.openStream();
                iSource.setByteStream(iStream);
                return iSource;
            } catch (Exception e) {
                catalogManager.debug.message(1, "Failed to create InputSource", resolved);
                return null;
            }
        } else {
            return null;
        }
    }
public void copyFile() throws Exception {
        SmbFile file = new SmbFile("smb://elsa:elsa@elsa/Elsa/Desktop/Ficheiros2/04-04-2066/How To Make a Flash Preloader.doc");
        println("length: " + file.length());
        SmbFileInputStream in = new SmbFileInputStream(file);
        println("available: " + in.available());
        File dest = new File("C:\\Documents and Settings\\Carlos\\Desktop\\Flash Preloader.doc");
        FileOutputStream out = new FileOutputStream(dest);
        int buffer_length = 1024;
        byte[] buffer = new byte[buffer_length];
        while (true) {
            int bytes_read = in.read(buffer, 0, buffer_length);
            if (bytes_read <= 0) {
                break;
            }
            out.write(buffer, 0, bytes_read);
        }
        in.close();
        out.close();
        println("done.");
    }
public void onMessage(Message message) {
        LOG.debug("onMessage");
        DownloadMessage downloadMessage;
        try {
            downloadMessage = new DownloadMessage(message);
        } catch (JMSException e) {
            LOG.error("JMS error: " + e.getMessage(), e);
            return;
        }
        String caName = downloadMessage.getCaName();
        boolean update = downloadMessage.isUpdate();
        LOG.debug("issuer: " + caName);
        CertificateAuthorityEntity certificateAuthority = this.certificateAuthorityDAO.findCertificateAuthority(caName);
        if (null == certificateAuthority) {
            LOG.error("unknown certificate authority: " + caName);
            return;
        }
        if (!update && Status.PROCESSING != certificateAuthority.getStatus()) {
            LOG.debug("CA status not marked for processing");
            return;
        }
        String crlUrl = certificateAuthority.getCrlUrl();
        if (null == crlUrl) {
            LOG.warn("No CRL url for CA " + certificateAuthority.getName());
            certificateAuthority.setStatus(Status.NONE);
            return;
        }
        NetworkConfig networkConfig = this.configurationDAO.getNetworkConfig();
        HttpClient httpClient = new HttpClient();
        if (null != networkConfig) {
            httpClient.getHostConfiguration().setProxy(networkConfig.getProxyHost(), networkConfig.getProxyPort());
        }
        HttpClientParams httpClientParams = httpClient.getParams();
        httpClientParams.setParameter("http.socket.timeout", new Integer(1000 * 20));
        LOG.debug("downloading CRL from: " + crlUrl);
        GetMethod getMethod = new GetMethod(crlUrl);
        getMethod.addRequestHeader("User-Agent", "jTrust CRL Client");
        int statusCode;
        try {
            statusCode = httpClient.executeMethod(getMethod);
        } catch (Exception e) {
            downloadFailed(caName, crlUrl);
            throw new RuntimeException();
        }
        if (HttpURLConnection.HTTP_OK != statusCode) {
            LOG.debug("HTTP status code: " + statusCode);
            downloadFailed(caName, crlUrl);
            throw new RuntimeException();
        }
        String crlFilePath;
        File crlFile = null;
        try {
            crlFile = File.createTempFile("crl-", ".der");
            InputStream crlInputStream = getMethod.getResponseBodyAsStream();
            OutputStream crlOutputStream = new FileOutputStream(crlFile);
            IOUtils.copy(crlInputStream, crlOutputStream);
            IOUtils.closeQuietly(crlInputStream);
            IOUtils.closeQuietly(crlOutputStream);
            crlFilePath = crlFile.getAbsolutePath();
            LOG.debug("temp CRL file: " + crlFilePath);
        } catch (IOException e) {
            downloadFailed(caName, crlUrl);
            if (null != crlFile) {
                crlFile.delete();
            }
            throw new RuntimeException(e);
        }
        try {
            this.notificationService.notifyHarvester(caName, crlFilePath, update);
        } catch (JMSException e) {
            crlFile.delete();
            throw new RuntimeException(e);
        }
    }
public static String computeDigest(String str, String alg) {
        MessageDigest currentAlgorithm = null;
        try {
            currentAlgorithm = MessageDigest.getInstance(alg);
        } catch (NoSuchAlgorithmException e) {
            return str;
        }
        currentAlgorithm.reset();
        currentAlgorithm.update(str.getBytes());
        byte[] hash = currentAlgorithm.digest();
        String d = "";
        int usbyte = 0;
        for (int i = 0; i < hash.length; i++) {
            usbyte = hash[i] & 0xFF;
            if (usbyte < 16) d += "0" + Integer.toHexString(usbyte); else d += Integer.toHexString(usbyte);
        }
        return d.toUpperCase();
    }
public void write() throws IOException {
        JarOutputStream jarOut = new JarOutputStream(outputStream, manifest);
        if (includeJars != null) {
            HashSet allEntries = new HashSet(includeJars);
            if (!ignoreDependencies) expandSet(allEntries);
            for (Iterator iterator = allEntries.iterator(); iterator.hasNext(); ) {
                JarFile jar = getJarFile(iterator.next());
                Enumeration jarEntries = jar.entries();
                while (jarEntries.hasMoreElements()) {
                    ZipEntry o1 = (ZipEntry) jarEntries.nextElement();
                    if (o1.getName().equalsIgnoreCase("META-INF/MANIFEST.MF") || o1.getSize() <= 0) continue;
                    jarOut.putNextEntry(o1);
                    InputStream entryStream = jar.getInputStream(o1);
                    IOUtils.copy(entryStream, jarOut);
                    jarOut.closeEntry();
                }
            }
        }
        jarOut.finish();
        jarOut.close();
    }
public static void copyFile(String input, String output) {
        try {
            File inputFile = new File(input);
            File outputFile = new File(output);
            FileReader in;
            in = new FileReader(inputFile);
            FileWriter out = new FileWriter(outputFile);
            int c;
            while ((c = in.read()) != -1) out.write(c);
            in.close();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
private void copy(File src, File dest, String name) {
        File srcFile = new File(src, name);
        File destFile = new File(dest, name);
        if (destFile.exists()) {
            if (destFile.lastModified() == srcFile.lastModified()) return;
            destFile.delete();
        }
        FileChannel in = null;
        FileChannel out = null;
        try {
            in = new FileInputStream(srcFile).getChannel();
            out = new FileOutputStream(destFile).getChannel();
            in.transferTo(0, in.size(), out);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (in != null) in.close();
            } catch (IOException e) {
            }
            try {
                if (out != null) out.close();
            } catch (IOException e) {
            }
        }
        destFile.setLastModified(srcFile.lastModified());
    }
public void executeQuery(Connection connection, String query) {
        action = null;
        updateCount = 0;
        resultsAvailable = false;
        metaAvailable = false;
        planAvailable = false;
        if (connection == null) {
            ide.setStatus("not connected");
            return;
        }
        cleanUp();
        try {
            ide.setStatus("Executing query");
            stmt = connection.createStatement();
            if (query.toLowerCase().startsWith("select")) {
                result = stmt.executeQuery(query);
                resultsAvailable = true;
                action = "select";
            } else if (query.toLowerCase().startsWith("update")) {
                updateCount = stmt.executeUpdate(query);
                action = "update";
            } else if (query.toLowerCase().startsWith("delete")) {
                updateCount = stmt.executeUpdate(query);
                action = "delete";
            } else if (query.toLowerCase().startsWith("insert")) {
                updateCount = stmt.executeUpdate(query);
                action = "insert";
            } else if (query.toLowerCase().startsWith("commit")) {
                connection.commit();
                action = "commit";
            } else if (query.toLowerCase().startsWith("rollback")) {
                connection.rollback();
                action = "rollback";
            } else if (query.toLowerCase().startsWith("create")) {
                updateCount = stmt.executeUpdate(query);
                action = "create";
            } else if (query.toLowerCase().startsWith("drop")) {
                updateCount = stmt.executeUpdate(query);
                action = "drop";
            } else if (query.toLowerCase().startsWith("desc ")) {
                String objectName = query.substring(query.indexOf(' '), query.length());
                query = "select * from (" + objectName + ") where rownum < 1";
                descQuery(connection, query);
            } else if (query.toLowerCase().startsWith("explain plan for ")) {
                explainQuery(connection, query);
            } else {
                result = stmt.executeQuery(query);
                resultsAvailable = true;
                action = "select";
            }
            ide.setStatus("executed query");
        } catch (Exception e) {
            ide.setStatus(e.getMessage());
        }
    }
public static void copyFile(File inputFile, File outputFile) throws IOException {
        BufferedInputStream fr = new BufferedInputStream(new FileInputStream(inputFile));
        BufferedOutputStream fw = new BufferedOutputStream(new FileOutputStream(outputFile));
        byte[] buf = new byte[8192];
        int n;
        while ((n = fr.read(buf)) >= 0) fw.write(buf, 0, n);
        fr.close();
        fw.close();
    }
public void insertJobLog(String userId, String[] checkId, String checkType, String objType) throws Exception {
        DBOperation dbo = null;
        Connection connection = null;
        PreparedStatement preStm = null;
        String sql = "insert into COFFICE_JOBLOG_CHECKAUTH (USER_ID,CHECK_ID,CHECK_TYPE,OBJ_TYPE) values (?,?,?,?)";
        String cleanSql = "delete from COFFICE_JOBLOG_CHECKAUTH where " + "user_id = '" + userId + "' and check_type = '" + checkType + "' and obj_type = '" + objType + "'";
        try {
            dbo = createDBOperation();
            connection = dbo.getConnection();
            connection.setAutoCommit(false);
            preStm = connection.prepareStatement(cleanSql);
            int dCount = preStm.executeUpdate();
            preStm = connection.prepareStatement(sql);
            String sHaveIns = ",";
            for (int j = 0; j < checkId.length; j++) {
                if (sHaveIns.indexOf("," + checkId[j] + ",") < 0) {
                    preStm.setInt(1, Integer.parseInt(userId));
                    preStm.setInt(2, Integer.parseInt(checkId[j]));
                    preStm.setInt(3, Integer.parseInt(checkType));
                    preStm.setInt(4, Integer.parseInt(objType));
                    preStm.executeUpdate();
                    sHaveIns += checkId[j] + ",";
                }
            }
            connection.commit();
        } catch (Exception ex) {
            log.debug((new Date().toString()) + " ������Ȩ��ʧ��! ");
            try {
                connection.rollback();
            } catch (SQLException e) {
                throw e;
            }
            throw ex;
        } finally {
            close(null, null, preStm, connection, dbo);
        }
    }
PackageFileImpl(PackageDirectoryImpl dir, String name, InputStream data) throws IOException {
        this.dir = dir;
        this.name = name;
        this.updates = dir.getUpdates();
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        IOUtils.copy(data, stream);
        updates.setNewData(getFullName(), stream.toByteArray());
        stream.close();
    }
void serialize(ZipOutputStream out) throws IOException {
        if ("imsmanifest.xml".equals(getFullName())) return;
        out.putNextEntry(new ZipEntry(getFullName()));
        IOUtils.copy(getDataStream(), out);
        out.closeEntry();
    }