semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
protected String readContent(URL url, int width) {
        StringBuffer content = new StringBuffer("");
        String line = "";
        try {
            BufferedReader f = new BufferedReader(new InputStreamReader(url.openStream()));
            while ((line = f.readLine()) != null) content.append(line + "\n");
            f.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (width >= 0) {
            String width_old = "width=\"xxx\"";
            String width_new = "width=\"" + width + "\"";
            int v0 = content.indexOf(width_old);
            int v1 = v0 + width_old.length();
            content.replace(v0, v1, width_new);
        }
        return content.toString();
    }
public void readHTMLFromURL(URL url) throws IOException {
        InputStream in = url.openStream();
        try {
            readHTMLFromStream(new InputStreamReader(in));
        } finally {
            try {
                in.close();
            } catch (IOException ex) {
                Logger.getLogger(HTMLTextAreaModel.class.getName()).log(Level.SEVERE, "Exception while closing InputStream", ex);
            }
        }
    }
public void load() throws ResourceInstantiationException, InvalidFormatException {
        if (null == url) {
            throw new ResourceInstantiationException("URL not set (null).");
        }
        try {
            BufferedReader mapReader = new BomStrippingInputStreamReader((url).openStream(), ENCODING);
            String line;
            MappingNode node;
            while (null != (line = mapReader.readLine())) {
                if (0 != line.trim().length()) {
                    node = new MappingNode(line);
                    this.add(node);
                }
            }
            mapReader.close();
        } catch (InvalidFormatException ife) {
            throw new InvalidFormatException(url, "on load");
        } catch (IOException ioe) {
            throw new ResourceInstantiationException(ioe);
        }
    }
private static void copyFile(File sourceFile, File targetFile) throws FileSaveException {
        try {
            FileInputStream inputStream = new FileInputStream(sourceFile);
            FileOutputStream outputStream = new FileOutputStream(targetFile);
            FileChannel readableChannel = inputStream.getChannel();
            FileChannel writableChannel = outputStream.getChannel();
            writableChannel.truncate(0);
            writableChannel.transferFrom(readableChannel, 0, readableChannel.size());
            inputStream.close();
            outputStream.close();
        } catch (IOException ioException) {
            String exceptionMessage = "An error occurred when copying from the file \"" + sourceFile.getAbsolutePath() + "\" to the file \"" + targetFile.getAbsolutePath() + "\".";
            throw new FileSaveException(exceptionMessage, ioException);
        }
    }
private boolean createPKCReqest(String keystoreLocation, String pw) {
        boolean created = false;
        Security.addProvider(new BouncyCastleProvider());
        KeyStore ks = null;
        try {
            ks = KeyStore.getInstance(KeyStore.getDefaultType());
            ks.load(new BufferedInputStream(new FileInputStream(keystoreLocation)), pw.toCharArray());
        } catch (Exception e) {
            if (this.debugLevel >= SAWSConstant.ErrorInfo) {
                this.sawsDebugLog.write("Error reading keystore file when creating PKC request: " + e.getMessage());
            }
            return false;
        }
        Certificate cert = null;
        try {
            cert = ks.getCertificate("saws");
        } catch (KeyStoreException e) {
            if (this.debugLevel >= SAWSConstant.ErrorInfo) {
                this.sawsDebugLog.write("Error reading certificate from keystore file when creating PKC request: " + e.getMessage());
            }
            return false;
        }
        PKCS10CertificationRequest request = null;
        PublicKey pk = cert.getPublicKey();
        try {
            request = new PKCS10CertificationRequest("SHA1with" + pk.getAlgorithm(), new X500Principal(((X509Certificate) cert).getSubjectDN().toString()), pk, new DERSet(), (PrivateKey) ks.getKey("saws", pw.toCharArray()));
            PEMWriter pemWrt = new PEMWriter(new OutputStreamWriter(new FileOutputStream("sawsRequest.csr")));
            pemWrt.writeObject(request);
            pemWrt.close();
            created = true;
        } catch (Exception e) {
            if (this.debugLevel >= SAWSConstant.ErrorInfo) {
                this.sawsDebugLog.write("Error creating PKC request file: " + e.getMessage());
            }
            return false;
        }
        return created;
    }
private boolean exportPKC(String keystoreLocation, String pw) {
        boolean created = false;
        KeyStore ks = null;
        try {
            ks = KeyStore.getInstance(KeyStore.getDefaultType());
            ks.load(new BufferedInputStream(new FileInputStream(keystoreLocation)), pw.toCharArray());
        } catch (Exception e) {
            if (this.debugLevel >= SAWSConstant.ErrorInfo) {
                this.sawsDebugLog.write("Error reading keystore file when exporting PKC: " + e.getMessage());
            }
            return false;
        }
        Certificate cert = null;
        try {
            cert = ks.getCertificate("saws");
        } catch (KeyStoreException e) {
            if (this.debugLevel >= SAWSConstant.ErrorInfo) {
                this.sawsDebugLog.write("Error reading certificate from keystore file when exporting PKC: " + e.getMessage());
            }
            return false;
        }
        try {
            StringBuffer sb = new StringBuffer("-----BEGIN CERTIFICATE-----\n");
            sb.append(new String(Base64.encode(cert.getEncoded())));
            sb.append("\n-----END CERTIFICATE-----\n");
            OutputStreamWriter wr = new OutputStreamWriter(new FileOutputStream("sawsSigningPKC.crt"));
            wr.write(new String(sb));
            wr.flush();
            wr.close();
            created = true;
        } catch (Exception e) {
            if (this.debugLevel >= SAWSConstant.ErrorInfo) {
                this.sawsDebugLog.write("Error exporting PKC file: " + e.getMessage());
            }
            return false;
        }
        return created;
    }
private boolean importPKC(String keystoreLocation, String pw, String pkcFile, String alias) {
        boolean imported = false;
        KeyStore ks = null;
        try {
            ks = KeyStore.getInstance(KeyStore.getDefaultType());
            ks.load(new BufferedInputStream(new FileInputStream(keystoreLocation)), pw.toCharArray());
        } catch (Exception e) {
            if (this.debugLevel >= SAWSConstant.ErrorInfo) {
                this.sawsDebugLog.write("Error reading keystore file when exporting PKC: " + e.getMessage());
            }
            return false;
        }
        Certificate cert = null;
        try {
            BufferedInputStream bis = new BufferedInputStream(new FileInputStream(pkcFile));
            CertificateFactory cf = CertificateFactory.getInstance("X.509");
            while (bis.available() > 0) {
                cert = cf.generateCertificate(bis);
            }
        } catch (Exception e) {
            if (this.debugLevel >= SAWSConstant.ErrorInfo) {
                this.sawsDebugLog.write("Error reading certificate from file when importing PKC: " + e.getMessage());
            }
            return false;
        }
        BufferedOutputStream bos = null;
        try {
            bos = new BufferedOutputStream(new FileOutputStream(new File(keystoreLocation)));
        } catch (FileNotFoundException e) {
            if (this.debugLevel >= SAWSConstant.ErrorInfo) {
                this.sawsDebugLog.write("Error accessing key store file when importing certificate: " + e.getMessage());
            }
            return false;
        }
        try {
            if (alias.equals("rootca")) {
                ks.setCertificateEntry(alias, cert);
            } else {
                KeyStore.PrivateKeyEntry pkEntry = (KeyStore.PrivateKeyEntry) ks.getEntry(alias, new KeyStore.PasswordProtection(pw.toCharArray()));
                ks.setKeyEntry(alias, pkEntry.getPrivateKey(), pw.toCharArray(), new Certificate[] { cert });
            }
            ks.store(bos, pw.toCharArray());
            imported = true;
        } catch (Exception e) {
            e.printStackTrace();
            if (this.debugLevel >= SAWSConstant.ErrorInfo) {
                this.sawsDebugLog.write("Error writing keystore to file when importing key store: " + e.getMessage());
            }
            return false;
        }
        return imported;
    }
public static final boolean copyFileNio(File src, File dst) throws IOException {
        FileChannel srcChannel = null, dstChannel = null;
        try {
            srcChannel = new FileInputStream(src).getChannel();
            dstChannel = new FileOutputStream(dst).getChannel();
            {
                int safe_max = (64 * 1024 * 1024) / 4;
                long size = srcChannel.size();
                long position = 0;
                while (position < size) {
                    position += srcChannel.transferTo(position, safe_max, dstChannel);
                }
            }
            srcChannel.close();
            srcChannel = null;
            dstChannel.close();
            dstChannel = null;
            return true;
        } finally {
            try {
                if (srcChannel != null) srcChannel.close();
            } catch (IOException e) {
                Debug.debug(e);
            }
            try {
                if (dstChannel != null) dstChannel.close();
            } catch (IOException e) {
                Debug.debug(e);
            }
        }
    }
public static String readFromURL(String sURL) {
        logger.info("com.rooster.utils.URLReader.readFromURL - Entry");
        String sWebPage = "";
        try {
            URL url = new URL(sURL);
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String inputLine = "";
            while ((inputLine = in.readLine()) != null) {
                sWebPage += inputLine;
            }
            in.close();
        } catch (Exception e) {
            logger.debug("com.rooster.utils.URLReader.readFromURL - Error" + e);
        }
        logger.info("com.rooster.utils.URLReader.readFromURL - Exit");
        return sWebPage;
    }
private String crypt(String s) throws BaseException, NoSuchAlgorithmException {
        if (s != null && s.length() > 0) {
            MessageDigest algorithm = MessageDigest.getInstance("MD5");
            algorithm.reset();
            algorithm.update(s.getBytes());
            byte messageDigest[] = algorithm.digest();
            StringBuffer hexString = new StringBuffer();
            for (int i = 0; i < messageDigest.length; i++) {
                hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
            }
            return hexString.toString();
        } else {
            throw new BaseException(ErrorCodes.CODE_2100);
        }
    }
public static void copyFile(String oldPath, String newPath) throws IOException {
        int bytesum = 0;
        int byteread = 0;
        File oldfile = new File(oldPath);
        if (oldfile.exists()) {
            InputStream inStream = new FileInputStream(oldPath);
            FileOutputStream fs = new FileOutputStream(newPath);
            byte[] buffer = new byte[1444];
            while ((byteread = inStream.read(buffer)) != -1) {
                bytesum += byteread;
                fs.write(buffer, 0, byteread);
            }
            inStream.close();
        }
    }
public List<SysSequences> getSeqs() throws Exception {
        List<SysSequences> list = new ArrayList<SysSequences>();
        Connection conn = null;
        try {
            conn = ConnectUtil.getConnect();
            conn.setAutoCommit(false);
            PreparedStatement ps = conn.prepareStatement("update ss_sys_sequences set next_value=next_value+step_value");
            ps.executeUpdate();
            ps.close();
            ps = conn.prepareStatement("select * from ss_sys_sequences");
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                SysSequences seq = new SysSequences();
                seq.setTableName(rs.getString(1));
                long nextValue = rs.getLong(2);
                long stepValue = rs.getLong(3);
                seq.setNextValue(nextValue - stepValue);
                seq.setStepValue(stepValue);
                list.add(seq);
            }
            rs.close();
            ps.close();
            conn.commit();
        } catch (Exception e) {
            conn.rollback();
            e.printStackTrace();
        } finally {
            try {
                conn.setAutoCommit(true);
            } catch (Exception e) {
            }
            ConnectUtil.closeConn(conn);
        }
        return list;
    }
public SysSequences getSeqs(String tableName) throws SQLException {
        SysSequences seq = new SysSequences();
        if (tableName == null || tableName.trim().equals("")) return null;
        Connection conn = null;
        try {
            conn = ConnectUtil.getConnect();
            conn.setAutoCommit(false);
            PreparedStatement ps = conn.prepareStatement("update ss_sys_sequences set next_value=next_value+step_value where table_name='" + tableName + "'");
            ps.executeUpdate();
            ps.close();
            ps = conn.prepareStatement("select * from ss_sys_sequences where table_name='" + tableName + "'");
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                long nextValue = rs.getLong(2);
                long stepValue = rs.getLong(3);
                seq.setTableName(tableName);
                seq.setNextValue(nextValue - stepValue + 1);
                seq.setStepValue(stepValue);
            }
            rs.close();
            ps.close();
            if (seq.getTableName() == null) {
                ps = conn.prepareStatement("insert into ss_sys_sequences values('" + tableName + "'," + (Constants.DEFAULT_CURR_VALUE + Constants.DEFAULT_STEP_VALUE) + "," + Constants.DEFAULT_STEP_VALUE + ")");
                ps.executeUpdate();
                ps.close();
                seq.setTableName(tableName);
                seq.setNextValue(Constants.DEFAULT_CURR_VALUE + 1);
                seq.setStepValue(Constants.DEFAULT_STEP_VALUE);
            }
            conn.commit();
        } catch (Exception e) {
            conn.rollback();
            e.printStackTrace();
        } finally {
            try {
                conn.setAutoCommit(true);
            } catch (Exception e) {
            }
            ConnectUtil.closeConn(conn);
        }
        return seq;
    }
public String getInternetData() throws Exception {
        BufferedReader in = null;
        String data = null;
        try {
            HttpClient client = new DefaultHttpClient();
            URI website = new URI("http://code.google.com/p/gadi-works");
            HttpGet request = new HttpGet();
            request.setURI(website);
            HttpResponse response = client.execute(request);
            in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
            StringBuffer sb = new StringBuffer("");
            String l = "";
            String nl = System.getProperty("line.separator");
            while ((l = in.readLine()) != null) {
                sb.append(l + nl);
            }
            in.close();
            data = sb.toString();
            return data;
        } finally {
            if (in != null) {
                try {
                    in.close();
                    return data;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
public ZipViewdataReader(ZipInputStream stream) throws IOException {
        ZipEntry ze;
        while ((ze = stream.getNextEntry()) != null) {
            File temp = File.createTempFile("spool.", ".synu");
            temp.deleteOnExit();
            FileOutputStream fos = new FileOutputStream(temp);
            byte[] buffer = new byte[1024 * 1024];
            int length;
            while ((length = stream.read(buffer)) != -1) fos.write(buffer, 0, length);
            fos.close();
            String name = ze.getName();
            String[] parts = name.split("[\\\\/]");
            this._file_hash.put(parts[parts.length - 1], temp);
        }
        stream.close();
        for (String key : this._file_hash.keySet()) if (key.endsWith("Viewdata")) {
            File f = this._file_hash.get(key);
            FileReader fr = new FileReader(f);
            this._viewdata = new BufferedReader(fr);
            break;
        }
        if (this._viewdata == null) throw new FileNotFoundException("No Viewdata found in ZIP file.");
    }
protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
        if (name.startsWith("java.")) {
            return super.loadClass(name, resolve);
        }
        Class<?> c = super.findLoadedClass(name);
        if (c != null) {
            return c;
        }
        String resource = name.replace('.', '/') + ".class";
        try {
            URL url = super.getResource(resource);
            if (url == null) {
                throw new ClassNotFoundException(name);
            }
            File f = new File("build/bin/" + resource);
            System.out.println("FileLen:" + f.length() + "  " + f.getName());
            InputStream is = url.openStream();
            try {
                ByteArrayOutputStream os = new ByteArrayOutputStream();
                byte[] b = new byte[2048];
                int count;
                while ((count = is.read(b, 0, 2048)) != -1) {
                    os.write(b, 0, count);
                }
                byte[] bytes = os.toByteArray();
                System.err.println("bytes: " + bytes.length + " " + resource);
                return defineClass(name, bytes, 0, bytes.length);
            } finally {
                if (is != null) {
                    is.close();
                }
            }
        } catch (SecurityException e) {
            return super.loadClass(name, resolve);
        } catch (IOException e) {
            throw new ClassNotFoundException(name, e);
        }
    }
public static void main(String args[]) throws IOException {
        BufferedReader in = new BufferedReader(new FileReader(args[0]));
        Writer out = new FileWriter(args[1]);
        out = new WrapFilter(new BufferedWriter(out), 40);
        out = new TitleCaseFilter(out);
        String line;
        while ((line = in.readLine()) != null) out.write(line + "\n");
        out.close();
        in.close();
    }
private String doGet(String identifier) throws IOException, MalformedURLException {
        URL url = new URL(baseurl.toString() + "/" + identifier);
        logger.debug("get " + url.toString());
        HttpURLConnection huc = (HttpURLConnection) (url.openConnection());
        BufferedReader reader = new BufferedReader(new InputStreamReader(huc.getInputStream()));
        StringWriter writer = new StringWriter();
        char[] buffer = new char[BUFFER_SIZE];
        int count = 0;
        while ((count = reader.read(buffer)) != -1) {
            writer.write(buffer, 0, count);
        }
        writer.close();
        reader.close();
        int code = huc.getResponseCode();
        logger.debug(" get result" + code);
        if (code == 200) {
            return writer.toString();
        } else throw new IOException("cannot get " + url.toString());
    }
private boolean doPost(String content) throws IOException {
        logger.debug("Service Registry PutRecordHandler: " + baseurl.toString());
        logger.debug("**** Service Registry PutRecord Request ****\n " + content);
        HttpURLConnection huc = (HttpURLConnection) (baseurl.openConnection());
        huc.setRequestMethod("POST");
        huc.setDoOutput(true);
        ByteArrayInputStream in = new ByteArrayInputStream(content.getBytes());
        OutputStream out = huc.getOutputStream();
        byte[] buffer = new byte[BUFFER_SIZE];
        BufferedInputStream bis = new BufferedInputStream(in);
        int count = 0;
        while ((count = bis.read(buffer)) != -1) {
            out.write(buffer, 0, count);
        }
        out.close();
        int code = huc.getResponseCode();
        logger.debug("Service Registry Response Code: " + code);
        if (code == 200) {
            return true;
        } else return false;
    }
private boolean doDelete(String identifier) throws IOException, MalformedURLException {
        URL url = new URL(baseurl.toString() + "/" + identifier);
        HttpURLConnection huc = (HttpURLConnection) (url.openConnection());
        huc.setRequestMethod("DELETE");
        huc.connect();
        if (huc.getResponseCode() == 200) {
            return true;
        } else return false;
    }
public static final String encryptSHA(String decrypted) {
        try {
            MessageDigest sha = MessageDigest.getInstance("SHA-1");
            sha.reset();
            sha.update(decrypted.getBytes());
            byte hash[] = sha.digest();
            sha.reset();
            return hashToHex(hash);
        } catch (NoSuchAlgorithmException _ex) {
            return null;
        }
    }
public static void copyFile(File sourceFile, File destFile) throws IOException {
        FileChannel inputFileChannel = new FileInputStream(sourceFile).getChannel();
        FileChannel outputFileChannel = new FileOutputStream(destFile).getChannel();
        long offset = 0L;
        long length = inputFileChannel.size();
        final long MAXTRANSFERBUFFERLENGTH = 1024 * 1024;
        try {
            for (; offset < length; ) {
                offset += inputFileChannel.transferTo(offset, MAXTRANSFERBUFFERLENGTH, outputFileChannel);
                inputFileChannel.position(offset);
            }
        } finally {
            try {
                outputFileChannel.close();
            } catch (Exception ignore) {
            }
            try {
                inputFileChannel.close();
            } catch (IOException ignore) {
            }
        }
    }
public static void concatFiles(List<File> sourceFiles, File destFile) throws IOException {
        FileOutputStream outFile = new FileOutputStream(destFile);
        FileChannel outChannel = outFile.getChannel();
        for (File f : sourceFiles) {
            FileInputStream fis = new FileInputStream(f);
            FileChannel channel = fis.getChannel();
            channel.transferTo(0, channel.size(), outChannel);
            channel.close();
            fis.close();
        }
        outChannel.close();
    }