semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void initForEncryption() throws CryptographyException, IOException {
        String ownerPassword = pdDocument.getOwnerPasswordForEncryption();
        String userPassword = pdDocument.getUserPasswordForEncryption();
        if (ownerPassword == null) {
            ownerPassword = "";
        }
        if (userPassword == null) {
            userPassword = "";
        }
        PDStandardEncryption encParameters = (PDStandardEncryption) pdDocument.getEncryptionDictionary();
        int permissionInt = encParameters.getPermissions();
        int revision = encParameters.getRevision();
        int length = encParameters.getLength() / 8;
        COSArray idArray = document.getDocumentID();
        if (idArray == null || idArray.size() < 2) {
            idArray = new COSArray();
            try {
                MessageDigest md = MessageDigest.getInstance("MD5");
                BigInteger time = BigInteger.valueOf(System.currentTimeMillis());
                md.update(time.toByteArray());
                md.update(ownerPassword.getBytes());
                md.update(userPassword.getBytes());
                md.update(document.toString().getBytes());
                byte[] id = md.digest(this.toString().getBytes());
                COSString idString = new COSString();
                idString.append(id);
                idArray.add(idString);
                idArray.add(idString);
                document.setDocumentID(idArray);
            } catch (NoSuchAlgorithmException e) {
                throw new CryptographyException(e);
            }
        }
        COSString id = (COSString) idArray.getObject(0);
        encryption = new PDFEncryption();
        byte[] o = encryption.computeOwnerPassword(ownerPassword.getBytes("ISO-8859-1"), userPassword.getBytes("ISO-8859-1"), revision, length);
        byte[] u = encryption.computeUserPassword(userPassword.getBytes("ISO-8859-1"), o, permissionInt, id.getBytes(), revision, length);
        encryptionKey = encryption.computeEncryptedKey(userPassword.getBytes("ISO-8859-1"), o, permissionInt, id.getBytes(), revision, length);
        encParameters.setOwnerKey(o);
        encParameters.setUserKey(u);
        document.setEncryptionDictionary(encParameters.getCOSDictionary());
    }
public void myClickHandler(View view) {
        switch(view.getId()) {
            case R.id.ReadWebPage:
                try {
                    textView.setText("");
                    URL url = new URL(urlText.getText().toString());
                    BufferedReader rd = new BufferedReader(new InputStreamReader(url.openStream()));
                    String line = "";
                    while ((line = rd.readLine()) != null) {
                        textView.append(line);
                    }
                } catch (Exception e) {
                    System.out.println("Nay, did not work");
                    textView.setText(e.getMessage());
                }
                break;
        }
    }
public HttpResponse execute(HttpHost host, HttpRequest req, HttpContext ctx) throws IOException, ClientProtocolException {
        HttpResponse resp = backend.execute(host, req, ctx);
        if (assessor.isFailure(resp)) {
            throw new UnsuccessfulResponseException(resp);
        }
        return resp;
    }
public Attributes getAttributes() throws SchemaViolationException, NoSuchAlgorithmException, UnsupportedEncodingException {
        BasicAttributes outAttrs = new BasicAttributes(true);
        BasicAttribute oc = new BasicAttribute("objectclass", "inetOrgPerson");
        oc.add("organizationalPerson");
        oc.add("person");
        outAttrs.put(oc);
        if (lastName != null && firstName != null) {
            outAttrs.put("sn", lastName);
            outAttrs.put("givenName", firstName);
            outAttrs.put("cn", firstName + " " + lastName);
        } else {
            throw new SchemaViolationException("user must have surname");
        }
        if (password != null) {
            MessageDigest sha = MessageDigest.getInstance("md5");
            sha.reset();
            sha.update(password.getBytes("utf-8"));
            byte[] digest = sha.digest();
            String hash = Base64.encodeBase64String(digest);
            outAttrs.put("userPassword", "{MD5}" + hash);
        }
        if (email != null) {
            outAttrs.put("mail", email);
        }
        return (Attributes) outAttrs;
    }
private String GetResponse(URL url) {
        String content = null;
        try {
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setDoOutput(false);
            conn.setRequestMethod("GET");
            if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
                BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                String line;
                while ((line = br.readLine()) != null) content += line;
            } else {
            }
        } catch (MalformedURLException e) {
            e.getStackTrace();
        } catch (IOException e) {
            e.getStackTrace();
        }
        return content;
    }
public static void readTestData(String getDkpUrl) throws Exception {
        final URL url = new URL(getDkpUrl);
        final InputStream is = url.openStream();
        try {
            final LineNumberReader rd = new LineNumberReader(new BufferedReader(new InputStreamReader(is)));
            String line = rd.readLine();
            while (line != null) {
                System.out.println(line);
                line = rd.readLine();
            }
        } finally {
            is.close();
        }
    }
private Attachment setupSimpleAttachment(Context context, long messageId, boolean withBody) throws IOException {
        Attachment attachment = new Attachment();
        attachment.mFileName = "the file.jpg";
        attachment.mMimeType = "image/jpg";
        attachment.mSize = 0;
        attachment.mContentId = null;
        attachment.mContentUri = "content://com.android.email/1/1";
        attachment.mMessageKey = messageId;
        attachment.mLocation = null;
        attachment.mEncoding = null;
        if (withBody) {
            InputStream inStream = new ByteArrayInputStream(TEST_STRING.getBytes());
            File cacheDir = context.getCacheDir();
            File tmpFile = File.createTempFile("setupSimpleAttachment", "tmp", cacheDir);
            OutputStream outStream = new FileOutputStream(tmpFile);
            IOUtils.copy(inStream, outStream);
            attachment.mContentUri = "file://" + tmpFile.getAbsolutePath();
        }
        return attachment;
    }
public static String getMD5(String s) {
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(s.toLowerCase().getBytes());
            return HexString.bufferToHex(md5.digest());
        } catch (NoSuchAlgorithmException e) {
            System.err.println("Error grave al inicializar MD5");
            e.printStackTrace();
            return "!!";
        }
    }
public static String getSHA1(String s) {
        try {
            MessageDigest sha1 = MessageDigest.getInstance("SHA1");
            sha1.update(s.toLowerCase().getBytes());
            return HexString.bufferToHex(sha1.digest());
        } catch (NoSuchAlgorithmException e) {
            System.err.println("Error grave al inicializar SHA1");
            e.printStackTrace();
            return "!!";
        }
    }
public static boolean init(String language) {
        URL url = S.class.getResource("strings_" + language + ".txt");
        strings = new Properties();
        try {
            strings.load(url.openStream());
        } catch (Exception e) {
            String def = "en";
            if (language.equals(def)) return false;
            return init(def);
        }
        ;
        return true;
    }
private String readWebpage() {
        BufferedReader in = null;
        StringBuffer sb = new StringBuffer();
        try {
            URI uri = new URI("file:///www.vogella.de");
            IProxyService proxyService = getProxyService();
            IProxyData[] proxyDataForHost = proxyService.select(uri);
            for (IProxyData data : proxyDataForHost) {
                if (data.getHost() != null) {
                    System.setProperty("http.proxySet", "true");
                    System.setProperty("http.proxyHost", data.getHost());
                }
                if (data.getHost() != null) {
                    System.setProperty("http.proxyPort", String.valueOf(data.getPort()));
                }
            }
            proxyService = null;
            URL url;
            url = uri.toURL();
            in = new BufferedReader(new InputStreamReader(url.openStream()));
            String inputLine;
            while ((inputLine = in.readLine()) != null) {
                sb.append(inputLine + "\n");
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (URISyntaxException e) {
            e.printStackTrace();
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return sb.toString();
    }
private static boolean isXmlApplicationFile(URL url) throws java.io.IOException {
        if (DEBUG) {
            System.out.println("Checking whether file is xml");
        }
        String firstLine;
        BufferedReader fileReader = null;
        try {
            fileReader = new BomStrippingInputStreamReader(url.openStream());
            firstLine = fileReader.readLine();
        } finally {
            if (fileReader != null) fileReader.close();
        }
        if (firstLine == null) {
            return false;
        }
        for (String startOfXml : STARTOFXMLAPPLICATIONFILES) {
            if (firstLine.length() >= startOfXml.length() && firstLine.substring(0, startOfXml.length()).equals(startOfXml)) {
                if (DEBUG) {
                    System.out.println("isXMLApplicationFile = true");
                }
                return true;
            }
        }
        if (DEBUG) {
            System.out.println("isXMLApplicationFile = false");
        }
        return false;
    }
public void copy(String original, String copy) throws SQLException {
        try {
            OutputStream out = openFileOutputStream(copy, false);
            InputStream in = openFileInputStream(original);
            IOUtils.copyAndClose(in, out);
        } catch (IOException e) {
            throw Message.convertIOException(e, "Can not copy " + original + " to " + copy);
        }
    }
public static void copyFile(String source, String destination) throws IOException {
        File srcDir = new File(source);
        File[] files = srcDir.listFiles();
        FileChannel in = null;
        FileChannel out = null;
        for (File file : files) {
            try {
                in = new FileInputStream(file).getChannel();
                File outFile = new File(destination, file.getName());
                out = new FileOutputStream(outFile).getChannel();
                in.transferTo(0, in.size(), out);
            } finally {
                if (in != null) in.close();
                if (out != null) out.close();
            }
        }
    }
public static boolean URLExists(URL url) {
        int responseCode = -1;
        boolean exists = true;
        try {
            if (useHttpURLConnection && url.getProtocol().equals("http")) {
                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                conn.setRequestMethod("HEAD");
                responseCode = conn.getResponseCode();
                if (!(responseCode >= 200 && responseCode < 400)) exists = false;
                conn.disconnect();
            } else {
                InputStream testStream = url.openStream();
            }
        } catch (IOException ioe) {
            exists = false;
        }
        return exists;
    }
public String copyImages(Document doc, String sXML, String newPath, String tagName, String itemName) {
        NodeList nl = null;
        Node n = null;
        NamedNodeMap nnp = null;
        Node nsrc = null;
        URL url = null;
        String sFilename = "";
        String sNewPath = "";
        int index;
        String sOldPath = "";
        try {
            nl = doc.getElementsByTagName(tagName);
            for (int i = 0; i < nl.getLength(); i++) {
                n = nl.item(i);
                nnp = n.getAttributes();
                nsrc = nnp.getNamedItem(itemName);
                String sTemp = nsrc.getTextContent();
                url = new URL("file", "localhost", sTemp);
                sOldPath = url.getPath();
                sOldPath = sOldPath.replace('/', File.separatorChar);
                int indexFirstSlash = sOldPath.indexOf(File.separatorChar);
                String sSourcePath;
                if (itemName.equals("data")) sSourcePath = sOldPath; else sSourcePath = sOldPath.substring(indexFirstSlash + 1);
                index = sOldPath.lastIndexOf(File.separatorChar);
                sFilename = sOldPath.substring(index + 1);
                sNewPath = newPath + sFilename;
                FileChannel in = null;
                FileChannel out = null;
                try {
                    in = new FileInputStream(sSourcePath).getChannel();
                    out = new FileOutputStream(sNewPath).getChannel();
                    long size = in.size();
                    MappedByteBuffer buf = in.map(FileChannel.MapMode.READ_ONLY, 0, size);
                    out.write(buf);
                } finally {
                    if (in != null) in.close();
                    if (out != null) out.close();
                }
                sXML = sXML.replace(nsrc.getTextContent(), sFilename);
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return sXML;
    }
public static void copyFile(File source, File dest) throws IOException {
        if (source.equals(dest)) throw new IOException("Source and destination cannot be the same file path");
        FileChannel srcChannel = new FileInputStream(source).getChannel();
        if (!dest.exists()) dest.createNewFile();
        FileChannel dstChannel = new FileOutputStream(dest).getChannel();
        dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
        srcChannel.close();
        dstChannel.close();
    }
public static void copyDirs(File sourceDir, File destDir) throws IOException {
        if (!destDir.exists()) destDir.mkdirs();
        for (File file : sourceDir.listFiles()) {
            if (file.isDirectory()) {
                copyDirs(file, new File(destDir, file.getName()));
            } else {
                FileChannel srcChannel = new FileInputStream(file).getChannel();
                File out = new File(destDir, file.getName());
                out.createNewFile();
                FileChannel dstChannel = new FileOutputStream(out).getChannel();
                dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
                srcChannel.close();
                dstChannel.close();
            }
        }
    }
private void loadDDL() throws IOException {
        try {
            conn.createStatement().executeQuery("SELECT * FROM overrides").close();
        } catch (SQLException e) {
            Statement stmt = null;
            if (!e.getMessage().startsWith(ERR_MISSING_TABLE)) {
                LOG.fatal(SQL_ERROR, e);
                throw new IOException("Error on initial data store read", e);
            }
            String[] qry = { "CREATE TABLE monitor (id INTEGER PRIMARY KEY NOT NULL, status VARCHAR(32) NOT NULL, next_update TIMESTAMP NOT NULL)", "CREATE TABLE overrides (id INT NOT NULL, title VARCHAR(255) NOT NULL, subtitle VARCHAR(255) NOT NULL, enable BOOLEAN NOT NULL DEFAULT TRUE, PRIMARY KEY(id))", "CREATE TABLE settings (var VARCHAR(32) NOT NULL, val VARCHAR(255) NOT NULL, PRIMARY KEY(var))", "INSERT INTO settings (var, val) VALUES ('schema', '1')" };
            try {
                conn.setAutoCommit(false);
                stmt = conn.createStatement();
                for (String q : qry) stmt.executeUpdate(q);
                conn.commit();
            } catch (SQLException e2) {
                try {
                    conn.rollback();
                } catch (SQLException e3) {
                    LOG.fatal(SQL_ERROR, e3);
                }
                LOG.fatal(SQL_ERROR, e2);
                throw new IOException("Error initializing data store", e2);
            } finally {
                if (stmt != null) {
                    try {
                        stmt.close();
                    } catch (SQLException e4) {
                        LOG.fatal(SQL_ERROR, e4);
                        throw new IOException("Unable to cleanup data store resources", e4);
                    }
                }
                try {
                    conn.setAutoCommit(true);
                } catch (SQLException e3) {
                    LOG.fatal(SQL_ERROR, e3);
                    throw new IOException("Unable to reset data store auto commit", e3);
                }
            }
        }
        return;
    }
private void upgradeSchema() throws IOException {
        Statement stmt = null;
        try {
            int i = getSchema();
            LOG.info("DB is currently at schema " + i);
            if (i < SCHEMA_VERSION) {
                LOG.info("Upgrading from schema " + i + " to schema " + SCHEMA_VERSION);
                conn.setAutoCommit(false);
                stmt = conn.createStatement();
                while (i < SCHEMA_VERSION) {
                    String qry;
                    switch(i) {
                        case 1:
                            qry = "UPDATE settings SET val = '2' WHERE var = 'schema'";
                            stmt.executeUpdate(qry);
                            break;
                    }
                    i++;
                }
                conn.commit();
            }
        } catch (SQLException e) {
            try {
                conn.rollback();
            } catch (SQLException e2) {
                LOG.error(SQL_ERROR, e2);
            }
            LOG.fatal(SQL_ERROR, e);
            throw new IOException("Error upgrading data store", e);
        } finally {
            try {
                if (stmt != null) stmt.close();
                conn.setAutoCommit(true);
            } catch (SQLException e) {
                LOG.error(SQL_ERROR, e);
                throw new IOException("Unable to cleanup SQL resources", e);
            }
        }
    }
@Override
    public void execute() throws BuildException {
        final String GC_USERNAME = "google-code-username";
        final String GC_PASSWORD = "google-code-password";
        if (StringUtils.isBlank(this.projectName)) throw new BuildException("undefined project");
        if (this.file == null) throw new BuildException("undefined file");
        if (!this.file.exists()) throw new BuildException("file not found :" + file);
        if (!this.file.isFile()) throw new BuildException("not a file :" + file);
        if (this.config == null) throw new BuildException("undefined config");
        if (!this.config.exists()) throw new BuildException("file not found :" + config);
        if (!this.config.isFile()) throw new BuildException("not a file :" + config);
        PostMethod post = null;
        try {
            Properties cfg = new Properties();
            FileInputStream fin = new FileInputStream(this.config);
            cfg.loadFromXML(fin);
            fin.close();
            if (!cfg.containsKey(GC_USERNAME)) throw new BuildException("undefined " + GC_USERNAME + " in " + this.config);
            if (!cfg.containsKey(GC_PASSWORD)) throw new BuildException("undefined " + GC_PASSWORD + " in " + this.config);
            HttpClient client = new HttpClient();
            post = new PostMethod("https://" + projectName + ".googlecode.com/files");
            post.addRequestHeader("User-Agent", getClass().getName());
            post.addRequestHeader("Authorization", "Basic " + Base64.encode(cfg.getProperty(GC_USERNAME) + ":" + cfg.getProperty(GC_PASSWORD)));
            List<Part> parts = new ArrayList<Part>();
            String s = this.summary;
            if (StringUtils.isBlank(s)) {
                s = this.file.getName() + " (" + TimeUtils.toYYYYMMDD() + ")";
            }
            parts.add(new StringPart("summary", s));
            for (String lbl : this.labels.split("[, \t\n]+")) {
                if (StringUtils.isBlank(lbl)) continue;
                parts.add(new StringPart("label", lbl.trim()));
            }
            parts.add(new FilePart("filename", this.file));
            MultipartRequestEntity requestEntity = new MultipartRequestEntity(parts.toArray(new Part[parts.size()]), post.getParams());
            post.setRequestEntity(requestEntity);
            int status = client.executeMethod(post);
            if (status != 201) {
                throw new BuildException("http status !=201 : " + post.getResponseBodyAsString());
            } else {
                IOUtils.copyTo(post.getResponseBodyAsStream(), new NullOutputStream());
            }
        } catch (BuildException e) {
            throw e;
        } catch (Exception e) {
            throw new BuildException(e);
        } finally {
            if (post != null) post.releaseConnection();
        }
    }