semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static NSData sendSynchronousRequest(NSMutableURLRequest req, NSHTTPURLResponseHolder resp, NSErrorHolder error) {
        NSData data = null;
        URL url = req.URL().xmlvmGetURL();
        URLConnection conn;
        try {
            conn = url.openConnection();
            data = new NSData(conn.getInputStream());
        } catch (IOException e) {
        }
        return data;
    }
protected void registerClasses() throws PrintException {
        if (!init) {
            try {
                Enumeration<URL> somethingToRegister = this.getClass().getClassLoader().getResources("META-INF/" + getClass().getSimpleName() + ".properties");
                while (somethingToRegister.hasMoreElements()) {
                    URL url = (URL) somethingToRegister.nextElement();
                    InputStream in = url.openStream();
                    BufferedReader buff = new BufferedReader(new InputStreamReader(in));
                    String line = buff.readLine();
                    while (line != null) {
                        log.debug(line);
                        try {
                            Class cls = Class.forName(line);
                            cls.newInstance();
                            log.debug("class " + line + " registered " + url);
                        } catch (ClassNotFoundException e) {
                            log.error("class " + line + " not found " + url, e);
                        } catch (InstantiationException e) {
                            log.error("class " + line + " not found " + url, e);
                        } catch (IllegalAccessException e) {
                            log.error("class " + line + " not found " + url, e);
                        }
                        line = buff.readLine();
                    }
                    buff.close();
                    in.close();
                }
            } catch (IOException e) {
                throw new PrintException(e.getMessage(), e);
            }
            init = true;
        }
    }
public void show(HttpServletRequest request, HttpServletResponse response, String pantalla, Atributos modelos) {
        URL url = getRecurso(pantalla);
        try {
            IOUtils.copy(url.openStream(), response.getOutputStream());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
public static void copyFile(File source, File dest) throws Exception {
        FileChannel in = null;
        FileChannel out = null;
        try {
            in = new FileInputStream(source).getChannel();
            out = new FileOutputStream(dest).getChannel();
            in.transferTo(0, in.size(), out);
        } catch (Exception e) {
            throw new Exception("Cannot copy file " + source.getAbsolutePath() + " to " + dest.getAbsolutePath(), e);
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
                if (out != null) {
                    out.close();
                }
            } catch (Exception e) {
                throw new Exception("Cannot close streams.", e);
            }
        }
    }
public static synchronized String encrypt(String text) {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("MD5");
            md.update(text.getBytes("UTF-8"));
            byte raw[] = md.digest();
            return new BASE64Encoder().encode(raw);
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalStateException(e.getMessage());
        } catch (UnsupportedEncodingException e) {
            throw new IllegalStateException(e.getMessage());
        }
    }
public void load() throws ResourceInstantiationException {
        if (null == url) {
            throw new ResourceInstantiationException("URL not set (null).");
        }
        try {
            BufferedReader defReader = new BomStrippingInputStreamReader((url).openStream(), ENCODING);
            String line;
            LinearNode node;
            while (null != (line = defReader.readLine())) {
                node = new LinearNode(line);
                try {
                    this.add(node);
                } catch (GateRuntimeException ex) {
                    throw new ResourceInstantiationException(ex);
                }
            }
            defReader.close();
            isModified = false;
        } catch (Exception x) {
            throw new ResourceInstantiationException(x);
        }
    }
private Metadata readMetadataIndexFileFromNetwork(String mediaMetadataURI) throws IOException {
        Metadata tempMetadata = new Metadata();
        URL url = new URL(mediaMetadataURI);
        BufferedReader input = new BufferedReader(new InputStreamReader(url.openStream()));
        String tempLine = null;
        while ((tempLine = input.readLine()) != null) {
            Property tempProperty = PropertyList.splitStringIntoKeyAndValue(tempLine);
            if (tempProperty != null) {
                tempMetadata.addIfNotNull(tempProperty.getKey(), tempProperty.getValue());
            }
        }
        input.close();
        return tempMetadata;
    }
public Map readMap(String filename) throws Exception {
        xmlPath = filename.substring(0, filename.lastIndexOf(File.separatorChar) + 1);
        String xmlFile = makeUrl(filename);
        URL url = new URL(xmlFile);
        InputStream is = url.openStream();
        if (filename.endsWith(".gz")) {
            is = new GZIPInputStream(is);
        }
        Map unmarshalledMap = unmarshal(is);
        unmarshalledMap.setFilename(filename);
        map = null;
        return unmarshalledMap;
    }
public Object apply(Context context, Object arg) {
        Object result = null;
        if (arg == null) {
            throw new NullArgument("Null argument to read().");
        }
        if (arg instanceof String) {
            String filename = (String) arg;
            File file = new File(filename);
            if (!file.exists()) {
                throw new FileNotFound("File not found: " + filename);
            }
            if (!file.isFile()) {
                throw new BadArgument("Argument to read() is not a file: " + filename);
            }
            if (!file.canRead()) {
                throw new BadArgument("File cannot be read: " + filename);
            }
            try {
                StringBuffer buffer = new StringBuffer();
                BufferedReader input = new BufferedReader(new FileReader(file));
                String sep = System.getProperty("line.separator");
                String line = null;
                for (; ; ) {
                    line = input.readLine();
                    if (line == null) {
                        break;
                    }
                    buffer.append(line);
                    buffer.append(sep);
                }
                result = buffer.toString();
                input.close();
            } catch (Exception e) {
                throw new IOError("Error reading " + filename);
            }
        } else if (arg instanceof URL) {
            URL url = (URL) arg;
            try {
                StringBuffer buffer = new StringBuffer();
                InputStreamReader isr = new InputStreamReader(url.openStream());
                BufferedReader input = new BufferedReader(isr);
                String sep = System.getProperty("line.separator");
                String line = null;
                for (; ; ) {
                    line = input.readLine();
                    if (line == null) {
                        break;
                    }
                    buffer.append(line);
                    buffer.append(sep);
                }
                result = buffer.toString();
                input.close();
            } catch (Exception e) {
                throw new IOError("Error reading " + url);
            }
        } else {
            throw new BadArgument("Bad argument to read()");
        }
        return result;
    }
public static List<PropertiesHolder> convertToPropertiesHolders(Collection<String> locations) {
        List<PropertiesHolder> propertiesHolders = new ArrayList<PropertiesHolder>();
        for (String path : locations) {
            Locale locale = null;
            int startIndex = path.lastIndexOf('/');
            if (startIndex < 0) {
                startIndex = 0;
            }
            int localeIndex = path.indexOf('_', startIndex);
            String localeString = null;
            if (localeIndex > 0) {
                localeString = path.substring(localeIndex + 1, path.lastIndexOf('.'));
            }
            if (org.apache.commons.lang.StringUtils.isBlank(localeString)) {
                locale = MessageProvider.DEFAULT_LOCALE;
                log.info("no locale could be guessed for properties: " + path);
            } else {
                locale = StringUtils.parseLocaleString(localeString);
                if (locale == null) {
                    locale = Locale.getDefault();
                    log.info("no locale could be guessed for properties: " + path);
                }
            }
            try {
                Properties props = new Properties();
                URL url = new URL(path);
                if (path.endsWith(".properties")) {
                    props.load(url.openStream());
                } else if (path.endsWith(".xml")) {
                    props.loadFromXML(url.openStream());
                } else if (path.endsWith(".xls")) {
                } else {
                    log.warn("unknown filetype for properties: " + path);
                }
                String bundleName = props.getProperty("webwarp-modules-bundle-id");
                if (org.apache.commons.lang.StringUtils.isEmpty(bundleName)) {
                    log.warn("bundle name is empty for path: " + path + ". Provide a bundle entry 'webwarp-modules-bundle-id' to set one.");
                    bundleName = MessageProvider.DEFAULT_BUNDLE_NAME;
                }
                propertiesHolders.add(new PropertiesHolder(props, bundleName, locale));
            } catch (Exception e) {
                log.error("Error reading properties from : " + path, e);
            }
        }
        return propertiesHolders;
    }
public static boolean isSameHttpContent(final String url, final File localFile, UsernamePasswordCredentials creds) throws IOException {
        if (localFile.isFile()) {
            long localContentLength = localFile.length();
            long localLastModified = localFile.lastModified() / 1000;
            long contentLength = -1;
            long lastModified = -1;
            HttpClient httpclient = createHttpClient(creds);
            try {
                HttpHead httphead = new HttpHead(url);
                HttpResponse response = httpclient.execute(httphead);
                if (response != null) {
                    StatusLine statusLine = response.getStatusLine();
                    int status = statusLine.getStatusCode() / 100;
                    if (status == 2) {
                        Header lastModifiedHeader = response.getFirstHeader("Last-Modified");
                        Header contentLengthHeader = response.getFirstHeader("Content-Length");
                        if (contentLengthHeader != null) {
                            contentLength = Integer.parseInt(contentLengthHeader.getValue());
                        }
                        if (lastModifiedHeader != null) {
                            SimpleDateFormat formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");
                            formatter.setDateFormatSymbols(new DateFormatSymbols(Locale.US));
                            try {
                                lastModified = formatter.parse(lastModifiedHeader.getValue()).getTime() / 1000;
                            } catch (ParseException e) {
                                logger.error(e);
                            }
                        }
                    } else {
                        return true;
                    }
                }
            } finally {
                httpclient.getConnectionManager().shutdown();
            }
            if (logger.isDebugEnabled()) {
                logger.debug("local:" + localContentLength + " " + localLastModified);
                logger.debug("remote:" + contentLength + " " + lastModified);
            }
            if (contentLength != -1 && localContentLength != contentLength) return false;
            if (lastModified != -1 && lastModified != localLastModified) return false;
            if (contentLength == -1 && lastModified == -1) return false;
            return true;
        }
        return false;
    }
public File addFile(File file, String suffix) throws IOException {
        if (file.exists() && file.isFile()) {
            File nf = File.createTempFile(prefix, "." + suffix, workdir);
            nf.delete();
            if (!file.renameTo(nf)) {
                IOUtils.copy(file, nf);
            }
            synchronized (fileList) {
                fileList.add(nf);
            }
            if (log.isDebugEnabled()) {
                log.debug("Add file [" + file.getPath() + "] -> [" + nf.getPath() + "]");
            }
            return nf;
        }
        return file;
    }
private String mkSid() {
        String temp = toString();
        MessageDigest messagedigest = null;
        try {
            messagedigest = MessageDigest.getInstance("SHA");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return null;
        }
        messagedigest.update(temp.getBytes());
        byte digest[] = messagedigest.digest();
        String chk = "";
        for (int i = 0; i < digest.length; i++) {
            String s = Integer.toHexString(digest[i] & 0xFF);
            chk += ((s.length() == 1) ? "0" + s : s);
        }
        return chk.toString();
    }
private void createSoundbank(String testSoundbankFileName) throws Exception {
        System.out.println("Create soundbank");
        File packageDir = new File("testsoundbank");
        if (packageDir.exists()) {
            for (File file : packageDir.listFiles()) assertTrue(file.delete());
            assertTrue(packageDir.delete());
        }
        packageDir.mkdir();
        String sourceFileName = "testsoundbank/TestSoundBank.java";
        File sourceFile = new File(sourceFileName);
        FileWriter writer = new FileWriter(sourceFile);
        writer.write("package testsoundbank;\n" + "public class TestSoundBank extends com.sun.media.sound.ModelAbstractOscillator { \n" + "    @Override public int read(float[][] buffers, int offset, int len) throws java.io.IOException { \n" + "   return 0;\n" + " }\n" + "    @Override public String getVersion() {\n" + "   return \"" + (soundbankRevision++) + "\";\n" + "    }\n" + "}\n");
        writer.close();
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
        fileManager.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File(".")));
        compiler.getTask(null, fileManager, null, null, null, fileManager.getJavaFileObjectsFromFiles(Arrays.asList(sourceFile))).call();
        ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(testSoundbankFileName));
        ZipEntry ze = new ZipEntry("META-INF/services/javax.sound.midi.Soundbank");
        zos.putNextEntry(ze);
        zos.write("testsoundbank.TestSoundBank".getBytes());
        ze = new ZipEntry("testsoundbank/TestSoundBank.class");
        zos.putNextEntry(ze);
        FileInputStream fis = new FileInputStream("testsoundbank/TestSoundBank.class");
        int b = fis.read();
        while (b != -1) {
            zos.write(b);
            b = fis.read();
        }
        zos.close();
    }
protected static void clearTables() throws SQLException {
        Connection conn = null;
        Statement stmt = null;
        try {
            conn = FidoDataSource.getConnection();
            conn.setAutoCommit(false);
            stmt = conn.createStatement();
            ClearData.clearTables(stmt);
            stmt.executeUpdate("insert into Objects (ObjectId, Description) values (2, '')");
            stmt.executeUpdate("insert into Objects (ObjectId, Description) values (3, '')");
            stmt.executeUpdate("insert into Objects (ObjectId, Description) values (4, '')");
            stmt.executeUpdate("insert into Objects (ObjectId, Description) values (5, '')");
            stmt.executeUpdate("insert into Objects (ObjectId, Description) values (6, '')");
            stmt.executeUpdate("insert into Objects (ObjectId, Description) values (7, '')");
            stmt.executeUpdate("insert into Objects (ObjectId, Description) values (8, '')");
            conn.commit();
        } catch (SQLException e) {
            if (conn != null) conn.rollback();
            throw e;
        } finally {
            if (stmt != null) stmt.close();
            if (conn != null) conn.close();
        }
    }
@TestProperties(name = "Simple test for adding different image files to report as link")
    public void testAddLinkToImage() throws Exception {
        InputStream in = this.getClass().getClassLoader().getResourceAsStream("regression/generic/images/splash.jpg");
        report.report(report.getCurrentTestFolder() + System.getProperty("file.separator") + "splash.jpg");
        IOUtils.copy(in, new FileOutputStream(new File(report.getCurrentTestFolder() + System.getProperty("file.separator") + "splash.jpg")));
        in = this.getClass().getClassLoader().getResourceAsStream("regression/generic/images/blue.png");
        IOUtils.copy(in, new FileOutputStream(new File(report.getCurrentTestFolder() + System.getProperty("file.separator") + "blue.png")));
        in = this.getClass().getClassLoader().getResourceAsStream("regression/generic/images/classDir.gif");
        IOUtils.copy(in, new FileOutputStream(new File(report.getCurrentTestFolder() + System.getProperty("file.separator") + "classDir.gif")));
        report.addLink("Link to JPG", "splash.jpg");
        report.addLink("Link to PNG", "blue.png");
        report.addLink("Link to GIF", "classDir.gif");
    }
public static void copy(String inputFile, String outputFile) throws Exception {
        try {
            FileReader in = new FileReader(inputFile);
            FileWriter out = new FileWriter(outputFile);
            int c;
            while ((c = in.read()) != -1) out.write(c);
            in.close();
            out.close();
        } catch (Exception e) {
            throw new Exception("Could not copy " + inputFile + " into " + outputFile + " because:\n" + e.getMessage());
        }
    }
public static void createModelZip(String filename, String tempdir, boolean overwrite) throws Exception {
        FileTools.checkOutput(filename, overwrite);
        BufferedInputStream origin = null;
        FileOutputStream dest = new FileOutputStream(filename);
        ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(dest));
        int BUFFER = 2048;
        byte data[] = new byte[BUFFER];
        File f = new File(tempdir);
        for (File fs : f.listFiles()) {
            FileInputStream fi = new FileInputStream(fs.getAbsolutePath());
            origin = new BufferedInputStream(fi, BUFFER);
            ZipEntry entry = new ZipEntry(fs.getName());
            out.putNextEntry(entry);
            int count;
            while ((count = origin.read(data, 0, BUFFER)) != -1) out.write(data, 0, count);
            out.closeEntry();
            origin.close();
        }
        out.close();
    }
public static void unzipModel(String filename, String tempdir) throws Exception {
        try {
            BufferedOutputStream dest = null;
            FileInputStream fis = new FileInputStream(filename);
            int BUFFER = 2048;
            ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
            ZipEntry entry;
            while ((entry = zis.getNextEntry()) != null) {
                int count;
                byte data[] = new byte[BUFFER];
                FileOutputStream fos = new FileOutputStream(tempdir + entry.getName());
                dest = new BufferedOutputStream(fos, BUFFER);
                while ((count = zis.read(data, 0, BUFFER)) != -1) dest.write(data, 0, count);
                dest.flush();
                dest.close();
            }
            zis.close();
        } catch (Exception e) {
            e.printStackTrace();
            throw new Exception("Can not expand model in \"" + tempdir + "\" because:\n" + e.getMessage());
        }
    }
public static String getUserToken(String userName) {
        if (userName != null && userName.trim().length() > 0) try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update((userName + seed).getBytes("ISO-8859-1"));
            return BaseController.bytesToHex(md.digest());
        } catch (NullPointerException npe) {
        } catch (NoSuchAlgorithmException e) {
        } catch (UnsupportedEncodingException e) {
        }
        return null;
    }
String connect() throws IOException {
        String reply = null;
        if (ftp == null) {
            FTPClient ftp = new FTPClient();
            ftp.connect(remote);
            if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
                throw new IOException("Connection failed: " + remote);
            }
            reply = ftp.getReplyString();
            if (!ftp.login("anonymous", "")) {
                throw new IOException("Login failed: " + remote);
            }
            if (!ftp.setFileType(FTP.BINARY_FILE_TYPE)) {
                throw new IOException("Setting binary file type failed: " + remote);
            }
            this.ftp = ftp;
        }
        return reply;
    }
@Test
    public void testProxySsl() throws Throwable {
        URL url = new URL("https://login.yahoo.co.jp/config/login");
        HttpsURLConnection httpsconnection = (HttpsURLConnection) url.openConnection();
        KeyManager[] km = null;
        TrustManager[] tm = { new X509TrustManager() {

            public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
            }

            public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
            }

            public X509Certificate[] getAcceptedIssuers() {
                return null;
            }
        } };
        SSLContext sslcontext = SSLContext.getInstance("SSL");
        sslcontext.init(km, tm, new SecureRandom());
        httpsconnection.setSSLSocketFactory(sslcontext.getSocketFactory());
        InputStream is = httpsconnection.getInputStream();
        readInputStream(is);
        is.close();
    }
public Document transform(URL url) throws IOException {
        Document doc = null;
        try {
            InputStream in = url.openStream();
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            Tidy tidy = new Tidy();
            tidy.setShowWarnings(false);
            tidy.setXmlOut(true);
            tidy.setXmlPi(false);
            tidy.setDocType("auto");
            tidy.setXHTML(false);
            tidy.setRawOut(true);
            tidy.setNumEntities(true);
            tidy.setQuiet(true);
            tidy.setFixComments(true);
            tidy.setIndentContent(true);
            tidy.setCharEncoding(org.w3c.tidy.Configuration.ASCII);
            DOMBuilder docBuilder = new DOMBuilder();
            doc = docBuilder.build(tidy.parseDOM(in, baos));
            String result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + baos.toString();
            in.close();
            baos.close();
            doc = XMLHelper.parseXMLFromString(result);
        } catch (IOException ioEx) {
            throw ioEx;
        } catch (XMLHelperException xmlEx) {
            xmlEx.printStackTrace();
        }
        return doc;
    }