semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void configureKerberos(boolean overwriteExistingSetup) throws Exception {
        OutputStream keyTabOut = null;
        InputStream keyTabIn = null;
        OutputStream krb5ConfOut = null;
        try {
            keyTabIn = loadKeyTabResource(keyTabResource);
            File file = new File(keyTabRepository + keyTabResource);
            if (!file.exists() || overwriteExistingSetup) {
                keyTabOut = new FileOutputStream(file, false);
                if (logger.isDebugEnabled()) logger.debug("Installing keytab file to : " + file.getAbsolutePath());
                IOUtils.copy(keyTabIn, keyTabOut);
            }
            File krb5ConfFile = new File(System.getProperty("java.security.krb5.conf", defaultKrb5Config));
            if (logger.isDebugEnabled()) logger.debug("Using Kerberos config file : " + krb5ConfFile.getAbsolutePath());
            if (!krb5ConfFile.exists()) throw new Exception("Kerberos config file not found : " + krb5ConfFile.getAbsolutePath());
            FileInputStream fis = new FileInputStream(krb5ConfFile);
            Wini krb5Conf = new Wini(KerberosConfigUtil.toIni(fis));
            Ini.Section krb5Realms = krb5Conf.get("realms");
            String windowsDomainSetup = krb5Realms.get(kerberosRealm);
            if (kerberosRealm == null || overwriteExistingSetup) {
                windowsDomainSetup = "{  kdc = " + keyDistributionCenter + ":88 admin_server = " + keyDistributionCenter + ":749  default_domain = " + kerberosRealm.toLowerCase() + "  }";
                krb5Realms.put(kerberosRealm, windowsDomainSetup);
            }
            Ini.Section krb5DomainRealms = krb5Conf.get("domain_realm");
            String domainRealmSetup = krb5DomainRealms.get(kerberosRealm.toLowerCase());
            if (domainRealmSetup == null || overwriteExistingSetup) {
                krb5DomainRealms.put(kerberosRealm.toLowerCase(), kerberosRealm);
                krb5DomainRealms.put("." + kerberosRealm.toLowerCase(), kerberosRealm);
            }
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            krb5Conf.store(baos);
            InputStream bios = new ByteArrayInputStream(baos.toByteArray());
            bios = KerberosConfigUtil.toKrb5(bios);
            krb5ConfOut = new FileOutputStream(krb5ConfFile, false);
            IOUtils.copy(bios, krb5ConfOut);
        } catch (Exception e) {
            logger.error("Error while configuring Kerberos :" + e.getMessage(), e);
            throw e;
        } finally {
            IOUtils.closeQuietly(keyTabOut);
            IOUtils.closeQuietly(keyTabIn);
            IOUtils.closeQuietly(krb5ConfOut);
        }
    }
public static void main(String[] args) {
        if (args.length != 3) {
            System.out.println("Usage: HexStrToBin enc/dec <infileName> <outfilename>");
            System.exit(1);
        }
        try {
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            InputStream in = new FileInputStream(args[1]);
            int len = 0;
            byte buf[] = new byte[1024];
            while ((len = in.read(buf)) > 0) os.write(buf, 0, len);
            in.close();
            os.close();
            byte[] data = null;
            if (args[0].equals("dec")) data = decode(os.toString()); else {
                String strData = encode(os.toByteArray());
                data = strData.getBytes();
            }
            FileOutputStream fos = new FileOutputStream(args[2]);
            fos.write(data);
            fos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
public static String encrypt(String plaintext) {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("SHA-1");
        } catch (NoSuchAlgorithmException e) {
            logger.error("NoSuchAlgorithmException:" + e);
        }
        try {
            md.update(plaintext.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            logger.error("UnsupportedEncodingException:" + e);
        }
        byte raw[] = md.digest();
        String hash = (new BASE64Encoder()).encode(raw);
        return hash;
    }
public String getXML(String servletURL, String request) {
        StringBuffer stringBuffer = new StringBuffer();
        try {
            String encodedRequest = URLEncoder.encode(request, "UTF-8");
            URL url = new URL(servletURL + request);
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String inputLine;
            while ((inputLine = in.readLine()) != null) {
                stringBuffer.append(inputLine);
            }
            in.close();
        } catch (MalformedURLException ex) {
            return null;
        } catch (UnsupportedEncodingException ex) {
            return null;
        } catch (IOException ex) {
            return null;
        }
        return stringBuffer.toString();
    }
public synchronized String encrypt(String plaintext) {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        try {
            md.update(plaintext.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        byte raw[] = md.digest();
        String hash = (new BASE64Encoder()).encode(raw);
        return hash;
    }
public static void DecodeMapFile(String mapFile, String outputFile) throws Exception {
        byte magicKey = 0;
        byte[] buffer = new byte[2048];
        int nread;
        InputStream map;
        OutputStream output;
        try {
            map = new FileInputStream(mapFile);
        } catch (Exception e) {
            throw new Exception("Map file error", e);
        }
        try {
            output = new FileOutputStream(outputFile);
        } catch (Exception e) {
            throw new Exception("Map file error", e);
        }
        while ((nread = map.read(buffer, 0, 2048)) != 0) {
            for (int i = 0; i < nread; ++i) {
                buffer[i] ^= magicKey;
                magicKey += 43;
            }
            output.write(buffer, 0, nread);
        }
        map.close();
        output.close();
    }
@Test
    public void testCopy() throws IOException {
        final byte[] input = { 0x00, 0x01, 0x7F, 0x03, 0x40 };
        final byte[] verification = input.clone();
        Assert.assertNotSame("Expecting verification to be a new array.", input, verification);
        final ByteArrayInputStream in = new ByteArrayInputStream(input);
        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        IOUtils.copy(in, out);
        final byte[] output = out.toByteArray();
        Assert.assertTrue("Expecting input to be unchanged.", Arrays.equals(verification, input));
        Assert.assertTrue("Expecting output to be like input.", Arrays.equals(verification, output));
        Assert.assertNotSame("Expecting output to be a new array.", input, output);
        Assert.assertNotSame("Expecting output to be a new array.", verification, output);
    }
public static String getMD5Hash(String data) {
        MessageDigest digest;
        try {
            digest = java.security.MessageDigest.getInstance("MD5");
            digest.update(data.getBytes());
            byte[] hash = digest.digest();
            StringBuffer hexString = new StringBuffer();
            String hexChar = "";
            for (int i = 0; i < hash.length; i++) {
                hexChar = Integer.toHexString(0xFF & hash[i]);
                if (hexChar.length() < 2) {
                    hexChar = "0" + hexChar;
                }
                hexString.append(hexChar);
            }
            return hexString.toString();
        } catch (NoSuchAlgorithmException ex) {
            return null;
        }
    }
public static final String computeHash(String stringToCompile) {
        String retVal = null;
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.reset();
            md5.update(stringToCompile.getBytes());
            byte[] result = md5.digest();
            StringBuffer hexString = new StringBuffer();
            for (int i = 0; i < result.length; i++) {
                hexString.append(Integer.toHexString(0xFF & result[i]));
            }
            retVal = hexString.toString();
            if (log.isDebugEnabled()) log.debug("MD5 hash for \"" + stringToCompile + "\" is: " + retVal);
        } catch (Exception exe) {
            log.error(exe.getMessage(), exe);
        }
        return retVal;
    }
public File createReadmeFile(File dir, MavenProject mavenProject) throws IOException {
        InputStream is = getClass().getResourceAsStream("README.template");
        StringWriter sw = new StringWriter();
        IOUtils.copy(is, sw);
        String content = sw.getBuffer().toString();
        content = StringUtils.replace(content, "{project_name}", mavenProject.getArtifactId());
        File readme = new File(dir, "README.TXT");
        FileUtils.writeStringToFile(readme, content);
        return readme;
    }
public static String MD5(String s) {
        try {
            MessageDigest m = MessageDigest.getInstance("MD5");
            m.update(s.getBytes(), 0, s.length());
            return new BigInteger(1, m.digest()).toString(16);
        } catch (NoSuchAlgorithmException ex) {
            return "";
        }
    }
public static void download(URL url, File file, String userAgent) throws IOException {
        URLConnection conn = url.openConnection();
        if (userAgent != null) {
            conn.setRequestProperty("User-Agent", userAgent);
        }
        InputStream in = conn.getInputStream();
        FileOutputStream out = new FileOutputStream(file);
        StreamUtil.copyThenClose(in, out);
    }
public static void downloadXrefTask(String url, String file) {
        int n, progressi, progressn;
        if (debug) System.err.println("Downloading " + url + " into " + file);
        Progress progress = Progress.crNew(null, "Downloading xref task");
        FileOutputStream oo = null;
        InputStream ii = null;
        try {
            URLConnection con = new URL(url).openConnection();
            ii = con.getInputStream();
            File of = new File(file);
            if (!of.getParentFile().exists()) {
                of.getParentFile().mkdir();
            }
            oo = new FileOutputStream(of);
            byte buffer[] = new byte[XREF_DOWNLOAD_BUFFER_SIZE];
            progressi = 0;
            progressn = con.getContentLength();
            n = 1;
            while (n >= 0) {
                n = ii.read(buffer, 0, XREF_DOWNLOAD_BUFFER_SIZE);
                if (n > 0) {
                    oo.write(buffer, 0, n);
                    progressi += n;
                }
                if (!progress.setProgress(progressi * 100 / progressn)) {
                    n = -2;
                }
            }
            ii.close();
            oo.close();
            fileSetExecPermission(file);
            if (n == -2) {
                of.delete();
            }
        } catch (Exception e) {
            try {
                if (oo != null) {
                    oo.close();
                    new File(file).delete();
                }
                if (ii != null) ii.close();
            } catch (Exception ee) {
            }
            progress.setVisible(false);
            JOptionPane.showMessageDialog(null, e.toString() + "\nWhile downloading " + url + ".\nMaybe wrong proxy configuration?", "Xrefactory Error", JOptionPane.ERROR_MESSAGE);
        }
        progress.setVisible(false);
    }
public MultiValueMap<String> queryResource(String resourceName) {
        if (resourceName.startsWith("http://dbpedia.org/resource/")) {
            resourceName = resourceName.substring(28);
        }
        try {
            resourceName = resourceName.replace(' ', '_');
            resourceName = URLEncoder.encode(resourceName, "UTF-8");
        } catch (UnsupportedEncodingException exc) {
        }
        String select = prefix + " SELECT ?property ?hasValue WHERE { { " + "<http://dbpedia.org/resource/" + resourceName + "> ?property ?hasValue  } FILTER (lang(?hasValue) = \"" + lang + "\" || !isLiteral(?hasValue))}";
        System.out.println(select);
        MultiValueMap<String> resourceMap = new MultiValueMap<String>();
        try {
            URL url = new URL(queryBase + URLEncoder.encode(select, "UTF-8"));
            InputStream inStream = url.openStream();
            Document doc = docBuild.parse(inStream);
            Element table = doc.getDocumentElement();
            NodeList rows = table.getElementsByTagName("tr");
            for (int i = 0; i < rows.getLength(); i++) {
                Element row = (Element) rows.item(i);
                NodeList cols = row.getElementsByTagName("td");
                if (cols.getLength() > 1) {
                    Element propElem = (Element) cols.item(0);
                    Element valElem = (Element) cols.item(1);
                    String property = ((Text) propElem.getFirstChild()).getData();
                    if (property.startsWith("http://dbpedia.org/property/")) {
                        property = property.substring(28);
                    } else {
                        int inx = property.indexOf('#');
                        if (inx == -1) {
                            inx = property.lastIndexOf('/');
                        }
                        property = property.substring(inx + 1);
                    }
                    String value = ((Text) valElem.getFirstChild()).getData();
                    if (value.startsWith("http://dbpedia.org/resource/")) {
                        value = value.substring(28).replaceAll("_", " ");
                    }
                    resourceMap.addFieldValue(property, value);
                }
            }
        } catch (UnsupportedEncodingException exc) {
            exc.printStackTrace();
        } catch (IOException exc) {
            System.err.println("Cannot retrieve record for " + resourceName);
        } catch (SAXException exc) {
            System.err.println("Cannot parse record for " + resourceName);
        }
        return resourceMap;
    }
public HashSet<String> queryResource(String resourceName, String propertyName) {
        if (resourceName.startsWith("http://dbpedia.org/resource/")) {
            resourceName = resourceName.substring(28);
        }
        try {
            resourceName = resourceName.trim().replace(' ', '_');
            resourceName = URLEncoder.encode(resourceName, "UTF-8");
        } catch (UnsupportedEncodingException exc) {
        }
        String select = prefix + " SELECT ?hasValue WHERE { { " + "<http://dbpedia.org/resource/" + resourceName + "> " + propertyName + " ?hasValue  } FILTER (lang(?hasValue) = \"" + lang + "\" || !isLiteral(?hasValue))}";
        System.out.println(select);
        HashSet<String> values = new HashSet<String>();
        try {
            URL url = new URL(queryBase + URLEncoder.encode(select, "UTF-8"));
            InputStream inStream = url.openStream();
            Document doc = docBuild.parse(inStream);
            Element table = doc.getDocumentElement();
            NodeList rows = table.getElementsByTagName("tr");
            for (int i = 0; i < rows.getLength(); i++) {
                Element row = (Element) rows.item(i);
                NodeList cols = row.getElementsByTagName("td");
                if (cols.getLength() > 0) {
                    Element valElem = (Element) cols.item(0);
                    String value = ((Text) valElem.getFirstChild()).getData();
                    if (value.startsWith("http://dbpedia.org/resource/")) {
                        value = value.substring(28).replaceAll("_", " ");
                    } else if (value.startsWith("http://dbpedia.org/ontology/")) {
                        value = value.substring(28).replaceAll("_", " ");
                    } else if (value.startsWith("http://dbpedia.org/class/yago/")) {
                        value = value.substring(30);
                        value = value.split("[\\d]+")[0];
                    }
                    values.add(value);
                }
            }
        } catch (UnsupportedEncodingException exc) {
            exc.printStackTrace();
        } catch (IOException exc) {
            System.err.println("Cannot retrieve record for " + resourceName);
        } catch (SAXException exc) {
            System.err.println("Cannot parse record for " + resourceName);
        }
        return values;
    }
@Override
    protected Set<DataRecord> retrieveRecords(DataTemplate template) {
        String query = template.getQuery();
        if (query == null) {
            query = topic;
        }
        String select = prefix + " SELECT ?resource WHERE { { ?resource rdf:type " + "<http://dbpedia.org/class/yago/" + StringUtils.toCamelCase(query) + "> } UNION { ?resource skos:subject <http://dbpedia.org/resource/Category:" + query.replaceAll(" ", "_") + "> } }";
        Document doc = null;
        HashSet<DataRecord> recs = new HashSet<DataRecord>();
        try {
            URL url = new URL(queryBase + URLEncoder.encode(select, "UTF-8"));
            InputStream inStream = url.openStream();
            doc = docBuild.parse(inStream);
            HashSet<String> resourceNames = new HashSet<String>();
            Element table = doc.getDocumentElement();
            NodeList rows = table.getElementsByTagName("tr");
            for (int i = 0; i < rows.getLength(); i++) {
                Element row = (Element) rows.item(i);
                NodeList cols = row.getElementsByTagName("td");
                if (cols.getLength() > 0) {
                    Element elem = (Element) cols.item(0);
                    String resource = ((Text) elem.getFirstChild()).getData();
                    resourceNames.add(resource);
                }
            }
            inStream.close();
            for (String resource : resourceNames) {
                MultiValueMap<String> resRecord = queryResource(resource);
                if (resource != null) {
                    DataRecord rec = parseResource(resRecord, template);
                    if (rec != null) {
                        recs.add(rec);
                    }
                }
            }
        } catch (IOException exc) {
            exc.printStackTrace();
        } catch (SAXException exc) {
            exc.printStackTrace();
        }
        return recs;
    }
private List<Feature> getFeatures(String source, EntryPoint e) throws MalformedURLException, SAXException, IOException, ParserConfigurationException, URISyntaxException {
        SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
        FeatureParser featp = new FeatureParser();
        parser.parse(URIFactory.url(serverPrefix + "/das/" + source + "/features?segment=" + e.id + ":" + e.start + "," + e.stop).openStream(), featp);
        return featp.list;
    }
public static synchronized String getURLContent(URL url) {
        Log log = LogUtil.getLog(FileManager.class, "getURLContent");
        if (url == null) {
            throw new IllegalArgumentException("url shouldn't be null!");
        }
        String content = (String) urlCache.get(url);
        if (content != null) {
            return content;
        }
        try {
            InputStream is = null;
            if ("file".equals(url.getProtocol())) {
                is = new java.io.FileInputStream(url.getFile());
            } else {
                is = url.openStream();
            }
            ByteArrayOutputStream baos = new ByteArrayOutputStream(is.available());
            pump(is, baos);
            content = new String(baos.toByteArray());
            urlCache.put(url, content);
            return content;
        } catch (FileNotFoundException e) {
            return null;
        } catch (Exception e) {
            e.printStackTrace();
            log.error(Translator.getString(XDocletMessages.class, XDocletUtilMessages.EXCEPTION_READING_MERGE_FILE, new String[] { e.toString() }));
            return null;
        }
    }
@Override
    public void sendContent(OutputStream out, Range range, Map<String, String> params, String contentType) throws IOException, NotAuthorizedException, BadRequestException {
        try {
            if (vtf == null) {
                LOG.debug("Serializing from database");
                existDocument.stream(out);
            } else {
                LOG.debug("Serializing from buffer");
                InputStream is = vtf.getByteStream();
                IOUtils.copy(is, out);
                out.flush();
                IOUtils.closeQuietly(is);
                vtf.delete();
                vtf = null;
            }
        } catch (PermissionDeniedException e) {
            LOG.debug(e.getMessage());
            throw new NotAuthorizedException(this);
        } finally {
            IOUtils.closeQuietly(out);
        }
    }
public String SHA1(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest md;
        md = MessageDigest.getInstance("SHA-1");
        byte[] sha1hash = new byte[40];
        md.update(text.getBytes("iso-8859-1"), 0, text.length());
        sha1hash = md.digest();
        return convertToHex(sha1hash);
    }
@Override
    public void close() throws IOException {
        super.close();
        byte[] signatureData = toByteArray();
        ZipOutputStream zipOutputStream = new ZipOutputStream(this.targetOutputStream);
        ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(this.originalZipFile));
        ZipEntry zipEntry;
        while (null != (zipEntry = zipInputStream.getNextEntry())) {
            if (!zipEntry.getName().equals(ODFUtil.SIGNATURE_FILE)) {
                ZipEntry newZipEntry = new ZipEntry(zipEntry.getName());
                zipOutputStream.putNextEntry(newZipEntry);
                LOG.debug("copying " + zipEntry.getName());
                IOUtils.copy(zipInputStream, zipOutputStream);
            }
        }
        zipInputStream.close();
        zipEntry = new ZipEntry(ODFUtil.SIGNATURE_FILE);
        LOG.debug("writing " + zipEntry.getName());
        zipOutputStream.putNextEntry(zipEntry);
        IOUtils.write(signatureData, zipOutputStream);
        zipOutputStream.close();
    }
public void updatePortletName(PortletName portletNameBean) {
        DatabaseAdapter dbDyn = null;
        PreparedStatement ps = null;
        try {
            dbDyn = DatabaseAdapter.getInstance();
            String sql = "update WM_PORTAL_PORTLET_NAME " + "set    TYPE=? " + "where  ID_SITE_CTX_TYPE=?";
            ps = dbDyn.prepareStatement(sql);
            ps.setString(1, portletNameBean.getPortletName());
            RsetTools.setLong(ps, 2, portletNameBean.getPortletId());
            int i1 = ps.executeUpdate();
            if (log.isDebugEnabled()) log.debug("Count of updated record - " + i1);
            dbDyn.commit();
        } catch (Exception e) {
            try {
                if (dbDyn != null) dbDyn.rollback();
            } catch (Exception e001) {
            }
            String es = "Error save portlet name";
            log.error(es, e);
            throw new IllegalStateException(es, e);
        } finally {
            DatabaseManager.close(dbDyn, ps);
            dbDyn = null;
            ps = null;
        }
    }