semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static String translate(String s, String type) {
        try {
            String result = null;
            URL url = new URL("http://www.excite.co.jp/world/english/");
            URLConnection connection = url.openConnection();
            connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
            connection.setDoOutput(true);
            PrintWriter out = new PrintWriter(connection.getOutputStream());
            out.print("before=" + URLEncoder.encode(s, "SJIS") + "&wb_lp=");
            out.print(type);
            out.close();
            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "SJIS"));
            String inputLine;
            while ((inputLine = in.readLine()) != null) {
                int textPos = inputLine.indexOf("name=\"after\"");
                if (textPos >= 0) {
                    int ltrPos = inputLine.indexOf(">", textPos + 11);
                    if (ltrPos >= 0) {
                        int closePos = inputLine.indexOf("<", ltrPos + 1);
                        if (closePos >= 0) {
                            result = inputLine.substring(ltrPos + 1, closePos);
                            break;
                        } else {
                            result = inputLine.substring(ltrPos + 1);
                            break;
                        }
                    }
                }
            }
            in.close();
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
void copyFileOnPeer(String path, RServerInfo peerserver, boolean allowoverwrite) throws IOException {
        RFile file = new RFile(path);
        OutputStream out = null;
        FileInputStream in = null;
        try {
            in = fileManager.openFileRead(path);
            out = localClient.openWrite(file, false, WriteMode.TRANSACTED, 1, peerserver, !allowoverwrite);
            IOUtils.copyLarge(in, out);
            out.close();
            out = null;
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (Throwable t) {
                }
            }
            if (out != null) {
                try {
                    out.close();
                } catch (Throwable t) {
                }
            }
        }
    }
public static void main(String[] args) {
        FTPClient client = new FTPClient();
        String sFTP = "ftp.miservidor.com";
        String sUser = "usuario";
        String sPassword = "password";
        try {
            System.out.println("Conectandose a " + sFTP);
            client.connect(sFTP);
            boolean login = client.login(sUser, sPassword);
            if (login) {
                System.out.println("Login correcto");
                boolean logout = client.logout();
                if (logout) {
                    System.out.println("Logout del servidor FTP");
                }
            } else {
                System.out.println("Error en el login.");
            }
            System.out.println("Desconectando.");
            client.disconnect();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }
public static void copyFile(File sourceFile, File targetFile) throws FileCopyingException {
        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 FileCopyingException(exceptionMessage, ioException);
        }
    }
public CertificateID(String hashAlgorithm, X509Certificate issuerCert, BigInteger number, String provider) throws OCSPException {
        try {
            MessageDigest digest = MessageDigest.getInstance(hashAlgorithm, provider);
            AlgorithmIdentifier hashAlg = new AlgorithmIdentifier(new DERObjectIdentifier(hashAlgorithm), new DERNull());
            X509Principal issuerName = PrincipalUtil.getSubjectX509Principal(issuerCert);
            digest.update(issuerName.getEncoded());
            ASN1OctetString issuerNameHash = new DEROctetString(digest.digest());
            PublicKey issuerKey = issuerCert.getPublicKey();
            ASN1InputStream aIn = new ASN1InputStream(issuerKey.getEncoded());
            SubjectPublicKeyInfo info = SubjectPublicKeyInfo.getInstance(aIn.readObject());
            digest.update(info.getPublicKeyData().getBytes());
            ASN1OctetString issuerKeyHash = new DEROctetString(digest.digest());
            DERInteger serialNumber = new DERInteger(number);
            this.id = new CertID(hashAlg, issuerNameHash, issuerKeyHash, serialNumber);
        } catch (Exception e) {
            throw new OCSPException("problem creating ID: " + e, e);
        }
    }
protected File downloadFile(String href) {
        Map<String, File> currentDownloadDirMap = downloadedFiles.get(downloadDir);
        if (currentDownloadDirMap != null) {
            File downloadedFile = currentDownloadDirMap.get(href);
            if (downloadedFile != null) {
                return downloadedFile;
            }
        } else {
            downloadedFiles.put(downloadDir, new HashMap<String, File>());
            currentDownloadDirMap = downloadedFiles.get(downloadDir);
        }
        URL url;
        File result;
        try {
            FilesystemUtils.forceMkdirIfNotExists(downloadDir);
            url = generateUrl(href);
            result = createUniqueFile(downloadDir, href);
        } catch (IOException e) {
            LOG.warn("Failed to create file for download", e);
            return null;
        }
        currentDownloadDirMap.put(href, result);
        LOG.info("Downloading " + url);
        try {
            IOUtils.copy(url.openStream(), new FileOutputStream(result));
        } catch (IOException e) {
            LOG.warn("Failed to download file " + url);
        }
        return result;
    }
public void execute() throws BuildException {
        Project proj = getProject();
        if (templateFile == null) throw new BuildException("Template file not set");
        if (targetFile == null) throw new BuildException("Target file not set");
        try {
            File template = new File(templateFile);
            File target = new File(targetFile);
            if (!template.exists()) throw new BuildException("Template file does not exist " + template.toString());
            if (!template.canRead()) throw new BuildException("Cannot read template file: " + template.toString());
            if (((!append) && (!overwrite)) && (!target.exists())) throw new BuildException("Target file already exists and append and overwrite are false " + target.toString());
            if (VERBOSE) {
                System.out.println("ProcessTemplate: tmpl in " + template.toString());
                System.out.println("ProcessTemplate: file out " + target.toString());
            }
            BufferedReader reader = new BufferedReader(new FileReader(template));
            BufferedWriter writer = new BufferedWriter(new FileWriter(targetFile, append));
            parse(reader, writer);
            writer.flush();
            writer.close();
        } catch (Exception e) {
            if (VERBOSE) e.printStackTrace();
            throw new BuildException(e);
        }
    }
public static void toValueSAX(Property property, Value value, int valueType, ContentHandler contentHandler, AttributesImpl na, Context context) throws SAXException, RepositoryException {
        na.clear();
        String _value = null;
        switch(valueType) {
            case PropertyType.DATE:
                DateFormat df = new SimpleDateFormat(BackupFormatConstants.DATE_FORMAT_STRING);
                df.setTimeZone(value.getDate().getTimeZone());
                _value = df.format(value.getDate().getTime());
                break;
            case PropertyType.BINARY:
                String outResourceName = property.getParent().getPath() + "/" + property.getName();
                OutputStream os = null;
                InputStream is = null;
                try {
                    os = context.getPersistenceManager().getOutResource(outResourceName, true);
                    is = value.getStream();
                    IOUtils.copy(is, os);
                    os.flush();
                } catch (Exception e) {
                    throw new SAXException("Could not backup binary value of property [" + property.getName() + "]", e);
                } finally {
                    if (null != is) {
                        try {
                            is.close();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                    if (null != os) {
                        try {
                            os.close();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }
                na.addAttribute("", ATTACHMENT, (NAMESPACE.length() > 0 ? NAMESPACE + ":" : "") + ATTACHMENT, "string", outResourceName);
                break;
            case PropertyType.REFERENCE:
                _value = value.getString();
                break;
            default:
                _value = value.getString();
        }
        contentHandler.startElement("", VALUE, (NAMESPACE.length() > 0 ? NAMESPACE + ":" : "") + VALUE, na);
        if (null != _value) contentHandler.characters(_value.toCharArray(), 0, _value.length());
        contentHandler.endElement("", VALUE, (NAMESPACE.length() > 0 ? NAMESPACE + ":" : "") + VALUE);
    }
public InputStream getParameterAsInputStream(String key) throws UndefinedParameterError, IOException {
        String urlString = getParameter(key);
        if (urlString == null) return null;
        try {
            URL url = new URL(urlString);
            InputStream stream = url.openStream();
            return stream;
        } catch (MalformedURLException e) {
            File file = getParameterAsFile(key);
            if (file != null) {
                return new FileInputStream(file);
            } else {
                return null;
            }
        }
    }
public final String hashPassword(final String password) {
            try {
                if (salt == null) {
                    salt = new byte[16];
                    SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
                    sr.setSeed(System.currentTimeMillis());
                    sr.nextBytes(salt);
                }
                MessageDigest md = MessageDigest.getInstance("SHA");
                md.update(salt);
                md.update(password.getBytes("UTF-8"));
                byte[] hash = md.digest();
                for (int i = 0; i < (1999); i++) {
                    md.reset();
                    hash = md.digest(hash);
                }
                return byteToString(hash, 60);
            } catch (Exception exception) {
                log.error(exception);
                return null;
            }
        }
public final String hashPassword(String password) {
            try {
                MessageDigest md = MessageDigest.getInstance("SHA");
                md.update(password.getBytes());
                byte[] hash = md.digest();
                return "{SHA}" + byteToString(hash, 60);
            } catch (NoSuchAlgorithmException nsae) {
                log.error("Error getting password hash - " + nsae.getMessage());
                return null;
            }
        }
public final String hashRealmPassword(String username, String realm, String password) throws GeneralSecurityException {
            MessageDigest md = null;
            md = MessageDigest.getInstance("MD5");
            md.update(username.getBytes());
            md.update(":".getBytes());
            md.update(realm.getBytes());
            md.update(":".getBytes());
            md.update(password.getBytes());
            byte[] hash = md.digest();
            return toHex(hash, hash.length);
        }
public static void saveDigraph(mainFrame parentFrame, DigraphView digraphView, File tobeSaved) {
        DigraphFile digraphFile = new DigraphFile();
        DigraphTextFile digraphTextFile = new DigraphTextFile();
        try {
            if (!DigraphFile.DIGRAPH_FILE_EXTENSION.equals(getExtension(tobeSaved))) {
                tobeSaved = new File(tobeSaved.getPath() + "." + DigraphFile.DIGRAPH_FILE_EXTENSION);
            }
            File dtdFile = new File(tobeSaved.getParent() + "/" + DigraphFile.DTD_FILE);
            if (!dtdFile.exists()) {
                File baseDigraphDtdFile = parentFrame.getDigraphDtdFile();
                if (baseDigraphDtdFile != null && baseDigraphDtdFile.exists()) {
                    try {
                        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(dtdFile));
                        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(baseDigraphDtdFile));
                        while (bis.available() > 1) {
                            bos.write(bis.read());
                        }
                        bis.close();
                        bos.close();
                    } catch (IOException ex) {
                        System.out.println("Unable to Write Digraph DTD File: " + ex.getMessage());
                    }
                } else {
                    System.out.println("Unable to Find Base Digraph DTD File: ");
                }
            }
            Digraph digraph = digraphView.getDigraph();
            digraphFile.saveDigraph(tobeSaved, digraph);
            String fileName = tobeSaved.getName();
            int extensionIndex = fileName.lastIndexOf(".");
            if (extensionIndex > 0) {
                fileName = fileName.substring(0, extensionIndex + 1) + "txt";
            } else {
                fileName = fileName + ".txt";
            }
            File textFile = new File(tobeSaved.getParent() + "/" + fileName);
            digraphTextFile.saveDigraph(textFile, digraph);
            digraphView.setDigraphDirty(false);
            parentFrame.setFilePath(tobeSaved.getPath());
            parentFrame.setSavedOnce(true);
        } catch (DigraphFileException exep) {
            JOptionPane.showMessageDialog(parentFrame, "Error Saving File:\n" + exep.getMessage(), "Save Error", JOptionPane.ERROR_MESSAGE);
        } catch (DigraphException exep) {
            JOptionPane.showMessageDialog(parentFrame, "Error Retrieving Digraph from View:\n" + exep.getMessage(), "Save Error", JOptionPane.ERROR_MESSAGE);
        }
    }
public boolean downloadFile(String sourceFilename, String targetFilename) throws RQLException {
        checkFtpClient();
        InputStream in = null;
        try {
            in = ftpClient.retrieveFileStream(sourceFilename);
            if (in == null) {
                return false;
            }
            FileOutputStream target = new FileOutputStream(targetFilename);
            IOUtils.copy(in, target);
            in.close();
            target.close();
            return ftpClient.completePendingCommand();
        } catch (IOException ex) {
            throw new RQLException("Download of file with name " + sourceFilename + " via FTP from server " + server + " failed.", ex);
        }
    }
public void openFtpConnection(String workingDirectory) throws RQLException {
        try {
            ftpClient = new FTPClient();
            ftpClient.connect(server);
            ftpClient.login(user, password);
            ftpClient.changeWorkingDirectory(workingDirectory);
        } catch (IOException ioex) {
            throw new RQLException("FTP client could not be created. Please check attributes given in constructor.", ioex);
        }
    }
public void uploadFile(String filename) throws RQLException {
        checkFtpClient();
        OutputStream out = null;
        try {
            out = ftpClient.storeFileStream(filename);
            IOUtils.copy(new FileReader(filename), out);
            out.close();
            ftpClient.completePendingCommand();
        } catch (IOException ex) {
            throw new RQLException("Upload of local file with name " + filename + " via FTP to server " + server + " failed.", ex);
        }
    }
public static String getStringFromAFileAtURL(String anURL) {
        String htmlCode = "<html><body></body></html>";
        try {
            URL url = new URL(anURL);
            URLConnection urlConnection = url.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
            String inputLine = "";
            htmlCode = "";
            while ((inputLine = in.readLine()) != null) htmlCode += inputLine + "\n";
            in.close();
        } catch (Exception e) {
            logs.info("URLResolver : lien mort");
            JOptionPane.showMessageDialog(null, "lien mort");
            return "<html><body></body></html>";
        }
        return checkXMLTagsLowerCase(htmlCode);
    }
public void send() {
        final String urlPath = "/rest/nodes/";
        final String preIsy99Cmd = "/cmd/";
        String urlStr = null;
        DefaultHttpClient httpclient = new DefaultHttpClient();
        try {
            httpclient.getCredentialsProvider().setCredentials(new AuthScope(host, 80), new UsernamePasswordCredentials(userName, password));
            StringBuilder urlBuilder = new StringBuilder();
            urlBuilder.append("http://");
            urlBuilder.append(host);
            urlBuilder.append(urlPath);
            urlBuilder.append(address);
            urlBuilder.append(preIsy99Cmd);
            urlBuilder.append(command);
            if (commandParam != null) {
                urlBuilder.append("/");
                urlBuilder.append(commandParam);
                log.warn("commandParam  " + urlBuilder.toString());
            }
            urlStr = urlBuilder.toString();
            log.debug("send(): URL is " + urlStr);
            log.warn("send(): URL is rest call  " + urlStr);
            HttpGet httpget = new HttpGet(urlStr);
            log.debug("executing request" + httpget.getRequestLine());
            HttpResponse response = httpclient.execute(httpget);
            int responseStatusCode = response.getStatusLine().getStatusCode();
            if (responseStatusCode != 200) {
                log.error("send(): response status code was " + responseStatusCode);
            }
        } catch (IOException e) {
            log.error("send(): IOException: address: " + address + "command: " + command, e);
        } finally {
        }
    }
private static FTPClient getFtpClient(String ftpHost, String ftpUsername, String ftpPassword) throws SocketException, IOException {
        FTPClient ftp = new FTPClient();
        ftp.connect(ftpHost);
        int reply = ftp.getReplyCode();
        if (!FTPReply.isPositiveCompletion(reply)) {
            ftp.disconnect();
            return null;
        }
        if (!ftp.login(ftpUsername, ftpPassword)) {
            return null;
        }
        ftp.setFileType(FTP.BINARY_FILE_TYPE);
        ftp.enterLocalPassiveMode();
        return ftp;
    }
public final InputSource getInputSource() {
        if (url == null) throw new RuntimeException("Cannot find table defs");
        try {
            InputStream stream = url.openStream();
            InputStreamReader reader = new InputStreamReader(stream);
            return new InputSource(reader);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
protected void createGraphicalViewer(Composite parent) {
        final RulerComposite rc = new RulerComposite(parent, SWT.NONE);
        viewer = new ScrollingGraphicalViewer();
        viewer.createControl(rc);
        editDomain.addViewer(viewer);
        rc.setGraphicalViewer(viewer);
        viewer.getControl().setBackground(ColorConstants.white);
        viewer.setEditPartFactory(new EditPartFactory() {

            public EditPart createEditPart(EditPart context, Object model) {
                return new RecorderEditPart(TopLevelModel.getRecorderModel());
            }
        });
        viewer.setContents(TopLevelModel.getRecorderModel());
        Control control = viewer.getControl();
        System.out.println("widget: " + control);
        DropTarget dt = new DropTarget(control, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_DEFAULT);
        dt.setTransfer(new Transfer[] { TextTransfer.getInstance() });
        dt.addDropListener(new SensorTransferDropTargetListener(viewer));
    }
public boolean copier(String source, String nomFichierSource, java.io.File destination) {
        boolean resultat = false;
        OutputStream tmpOut;
        try {
            tmpOut = new BufferedOutputStream(new FileOutputStream(nomFichierSource + "001.tmp"));
            InputStream is = getClass().getResourceAsStream(source + nomFichierSource);
            int i;
            while ((i = is.read()) != -1) tmpOut.write(i);
            tmpOut.close();
            is.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        FileChannel in = null;
        FileChannel out = null;
        try {
            in = new FileInputStream(new File(nomFichierSource + "001.tmp")).getChannel();
            out = new FileOutputStream(destination).getChannel();
            in.transferTo(0, in.size(), out);
            resultat = true;
        } catch (java.io.FileNotFoundException f) {
        } catch (java.io.IOException e) {
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                }
            }
            if (out != null) {
                try {
                    out.close();
                } catch (IOException e) {
                }
            }
        }
        new File(nomFichierSource + "001.tmp").delete();
        return (resultat);
    }
private void compress(String outputFile, ArrayList<String> inputFiles, PrintWriter log, boolean compress) throws Exception {
        String absPath = getAppConfig().getPathConfig().getAbsoluteServerPath();
        log.println("Concat files into: " + outputFile);
        OutputStream out = new FileOutputStream(absPath + outputFile);
        byte[] buffer = new byte[4096];
        int readBytes;
        for (String file : inputFiles) {
            log.println(" Read: " + file);
            InputStream in = new FileInputStream(absPath + file);
            while ((readBytes = in.read(buffer)) != -1) {
                out.write(buffer, 0, readBytes);
            }
            in.close();
        }
        out.close();
        if (compress) {
            long normalSize = new File(absPath + outputFile).length();
            ProcessBuilder builder = new ProcessBuilder("java", "-jar", "WEB-INF/yuicompressor.jar", outputFile, "-o", outputFile, "--line-break", "4000");
            builder.directory(new File(absPath));
            Process process = builder.start();
            process.waitFor();
            long minSize = new File(absPath + outputFile).length();
            long diff = normalSize - minSize;
            double percentage = Math.floor((double) diff / normalSize * 1000.0) / 10.0;
            double diffSize = (Math.floor(diff / 1024.0 * 10.0) / 10.0);
            log.println("Result: " + percentage + " % (" + diffSize + " KB)");
        }
    }