semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
private String findTitle(URL url) {
            HTMLEditorKit.ParserCallback callback;
            try {
                URLConnection conn = url.openConnection();
                Reader rd = new InputStreamReader(conn.getInputStream());
                ParserDelegator parser = new ParserDelegator();
                callback = new Callback();
                parser.parse(rd, callback, true);
            } catch (Exception exp) {
                System.err.println(exp);
            }
            return title;
        }
public MobileAgentProperties(Class declaringClass, String propertyFile) throws IOException {
            this.defaults = (MobileAgent) AnnotationElement.getAnyAnnotation(declaringClass, MobileAgent.class);
            URL url = getClass().getClassLoader().getResource(propertyFile);
            if (url != null) {
                props.load(url.openStream());
                log.info("MobileAgent parameters loaded from file " + url);
            }
        }
private static boolean initLOG4JProperties(String homeDir) {
        String Log4jURL = homeDir + LOG4J_URL;
        try {
            URL log4jurl = getURL(Log4jURL);
            InputStream inStreamLog4j = log4jurl.openStream();
            Properties propertiesLog4j = new Properties();
            try {
                propertiesLog4j.load(inStreamLog4j);
                PropertyConfigurator.configure(propertiesLog4j);
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (Exception e) {
            logger.info("Failed to initialize LOG4J with properties file.");
            return false;
        }
        return true;
    }
public static String getURLContent(String href) throws BuildException {
        URL url = null;
        String content;
        try {
            URL context = new URL("file:" + System.getProperty("user.dir") + "/");
            url = new URL(context, href);
            InputStream is = url.openStream();
            InputStreamReader isr = new InputStreamReader(is);
            StringBuffer stringBuffer = new StringBuffer();
            char[] buffer = new char[1024];
            int len;
            while ((len = isr.read(buffer, 0, 1024)) > 0) stringBuffer.append(buffer, 0, len);
            content = stringBuffer.toString();
            isr.close();
        } catch (Exception ex) {
            throw new BuildException("Cannot get content of URL " + href + ": " + ex);
        }
        return content;
    }
private void sendFile(File file, HttpServletResponse response) throws IOException {
        response.setContentLength((int) file.length());
        InputStream inputStream = null;
        try {
            inputStream = new FileInputStream(file);
            IOUtils.copy(inputStream, response.getOutputStream());
        } finally {
            IOUtils.closeQuietly(inputStream);
        }
    }
@Override
    protected Integer doInBackground() throws Exception {
        int numOfRows = 0;
        combinationMap = new HashMap<AnsweredQuestion, Integer>();
        combinationMapReverse = new HashMap<Integer, AnsweredQuestion>();
        LinkedHashSet<AnsweredQuestion> answeredQuestionSet = new LinkedHashSet<AnsweredQuestion>();
        LinkedHashSet<Integer> studentSet = new LinkedHashSet<Integer>();
        final String delimiter = ";";
        final String typeToProcess = "F";
        String line;
        String[] chunks = new String[9];
        try {
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream(), "ISO-8859-2"));
            in.readLine();
            while ((line = in.readLine()) != null) {
                chunks = line.split(delimiter);
                numOfRows++;
                if (chunks[2].equals(typeToProcess)) {
                    answeredQuestionSet.add(new AnsweredQuestion(chunks[4], chunks[5]));
                    studentSet.add(new Integer(chunks[0]));
                }
            }
            in.close();
            int i = 0;
            Integer I;
            for (AnsweredQuestion pair : answeredQuestionSet) {
                I = new Integer(i++);
                combinationMap.put(pair, I);
                combinationMapReverse.put(I, pair);
            }
            matrix = new SparseObjectMatrix2D(answeredQuestionSet.size(), studentSet.size());
            int lastStudentNumber = -1;
            AnsweredQuestion pair;
            in = new BufferedReader(new InputStreamReader(url.openStream(), "ISO-8859-2"));
            in.readLine();
            while ((line = in.readLine()) != null) {
                chunks = line.split(delimiter);
                pair = null;
                if (chunks[2].equals(typeToProcess)) {
                    if (Integer.parseInt(chunks[0]) != lastStudentNumber) {
                        lastStudentNumber++;
                    }
                    pair = new AnsweredQuestion(chunks[4], chunks[5]);
                    if (combinationMap.containsKey(pair)) {
                        matrix.setQuick(combinationMap.get(pair), lastStudentNumber, Boolean.TRUE);
                    }
                }
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        supportVector = new int[combinationMap.size()];
        ObjectMatrix1D row = null;
        for (int i = 0; i < combinationMap.size(); i++) {
            row = matrix.viewRow(i);
            int sum = 0;
            for (int k = 0; k < row.size(); k++) {
                if (row.getQuick(k) != null && row.getQuick(k).equals(Boolean.TRUE)) {
                    sum++;
                }
            }
            supportVector[i] = sum;
        }
        applet.combinationMap = this.combinationMap;
        applet.combinationMapReverse = this.combinationMapReverse;
        applet.matrix = this.matrix;
        applet.supportVector = supportVector;
        System.out.println("data loaded.");
        return null;
    }
private static String md5(String input) {
        String res = "";
        try {
            MessageDigest cript = MessageDigest.getInstance("MD5");
            cript.reset();
            cript.update(input.getBytes());
            byte[] md5 = cript.digest();
            String tmp = "";
            for (int i = 0; i < md5.length; i++) {
                tmp = (Integer.toHexString(0xFF & md5[i]));
                if (tmp.length() == 1) {
                    res += "0" + tmp;
                } else {
                    res += tmp;
                }
            }
        } catch (NoSuchAlgorithmException ex) {
            Log4k.error(pdfPrinter.class.getName(), ex.getMessage());
        }
        return res;
    }
@Test
    public void test_validate_tag_getTopAlbums() {
        try {
            SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
            File schemaLocation = new File("tes.xsd");
            Schema schema = factory.newSchema(schemaLocation);
            Validator validator = schema.newValidator();
            URL url = new URL("http://ws.audioscrobbler.com/2.0/?method=tag.gettopalbums&tag=disco&api_key=b25b959554ed76058ac220b7b2e0a026");
            InputStream inputStream = url.openStream();
            Source source = new StreamSource(inputStream);
            validator.validate(source);
        } catch (IOException ex) {
            Logger.getLogger(GetTopAlbums_Test.class.getName()).log(Level.SEVERE, null, ex);
            assertFalse("File not found", true);
        } catch (SAXException ex) {
            Logger.getLogger(GetTopAlbums_Test.class.getName()).log(Level.SEVERE, null, ex);
            assertFalse("Schema did not validate", true);
        }
        assertTrue(true);
    }
public String getMD5(String data) {
        try {
            MessageDigest md5Algorithm = MessageDigest.getInstance("MD5");
            md5Algorithm.update(data.getBytes(), 0, data.length());
            byte[] digest = md5Algorithm.digest();
            StringBuffer hexString = new StringBuffer();
            String hexDigit = null;
            for (int i = 0; i < digest.length; i++) {
                hexDigit = Integer.toHexString(0xFF & digest[i]);
                if (hexDigit.length() < 2) {
                    hexDigit = "0" + hexDigit;
                }
                hexString.append(hexDigit);
            }
            return hexString.toString();
        } catch (NoSuchAlgorithmException ne) {
            return data;
        }
    }
protected String getGraphPath(String name) throws ServletException {
        String hash;
        try {
            MessageDigest md = MessageDigest.getInstance(m_messagedigest_algorithm);
            md.update(name.getBytes());
            hash = bytesToHex(md.digest());
        } catch (NoSuchAlgorithmException e) {
            throw new ServletException("NoSuchAlgorithmException while " + "attempting to hash file name: " + e);
        }
        File tempDir = (File) getServletContext().getAttribute("javax.servlet.context.tempdir");
        return tempDir.getAbsolutePath() + File.separatorChar + hash;
    }
protected String insertCommand(String command) throws ServletException {
        String digest;
        try {
            MessageDigest md = MessageDigest.getInstance(m_messagedigest_algorithm);
            md.update(command.getBytes());
            byte bytes[] = new byte[20];
            m_random.nextBytes(bytes);
            md.update(bytes);
            digest = bytesToHex(md.digest());
        } catch (NoSuchAlgorithmException e) {
            throw new ServletException("NoSuchAlgorithmException while " + "attempting to generate graph ID: " + e);
        }
        String id = System.currentTimeMillis() + "-" + digest;
        m_map.put(id, command);
        return id;
    }
ServerInfo getServerInfo(String key, String protocol) throws InvalidKeyException, NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, IOException, ClassNotFoundException, IllegalBlockSizeException, BadPaddingException {
        DESedeKeySpec ks = new DESedeKeySpec(Base64.decode(key));
        SecretKeyFactory skf = SecretKeyFactory.getInstance("DESede");
        SecretKey sk = skf.generateSecret(ks);
        Cipher cipher = Cipher.getInstance("DESede");
        cipher.init(Cipher.DECRYPT_MODE, sk);
        ClassLoader cl = this.getClass().getClassLoader();
        URL url = cl.getResource(protocol + ".sobj");
        JarURLConnection jc = (JarURLConnection) url.openConnection();
        ObjectInputStream os = new ObjectInputStream(jc.getInputStream());
        SealedObject so = (SealedObject) os.readObject();
        return (ServerInfo) so.getObject(cipher);
    }
public PhoneSetImpl(URL url) throws IOException {
        BufferedReader reader;
        String line;
        phonesetMap = new HashMap();
        reader = new BufferedReader(new InputStreamReader(url.openStream()));
        line = reader.readLine();
        lineCount++;
        while (line != null) {
            if (!line.startsWith("***")) {
                parseAndAdd(line);
            }
            line = reader.readLine();
        }
        reader.close();
    }
private void createWikiPages(WikiContext context) throws PluginException {
        OntologyWikiPageName owpn = new OntologyWikiPageName(omemo.getFormDataAlias().toUpperCase(), omemo.getFormDataVersionDate());
        String wikiPageFullFileName = WikiPageName2FullFileName(context, owpn.toString());
        String rdfFileNameWithPath = getWorkDir(context) + File.separator + owpn.toFileName();
        FileOutputStream fos = null;
        FileInputStream fis = null;
        try {
            fos = new FileOutputStream(wikiPageFullFileName);
            fis = new FileInputStream(rdfFileNameWithPath);
            InfoExtractor infoe = new InfoExtractor(fis, omemo.getFormDataNS(), omemo.getFormDataOntLang());
            infoe.writePage(getWorkDir(context), owpn, Omemo.checksWikiPageName);
            fis.close();
            fos.close();
        } catch (Exception e) {
            log.error("Can not read local rdf file or can not write wiki page");
            throw new PluginException("Error creating wiki pages. See logs");
        }
    }
public static String getSignature(String s) {
        try {
            final AsciiEncoder coder = new AsciiEncoder();
            final MessageDigest msgDigest = MessageDigest.getInstance("MD5");
            msgDigest.update(s.getBytes("UTF-8"));
            final byte[] digest = msgDigest.digest();
            return coder.encode(digest);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            throw new IllegalStateException();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            throw new IllegalStateException();
        }
    }
public static byte[] request(String remoteUrl, boolean keepalive) throws Exception {
        Log.d(TAG, String.format("started request(remote=%s)", remoteUrl));
        Process.setThreadPriority(Process.THREAD_PRIORITY_LOWEST);
        byte[] buffer = new byte[1024];
        URL url = new URL(remoteUrl);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setAllowUserInteraction(false);
        connection.setRequestProperty("Viewer-Only-Client", "1");
        connection.setRequestProperty("Client-Daap-Version", "3.10");
        connection.setRequestProperty("Accept-Encoding", "gzip, deflate");
        if (!keepalive) {
            connection.setConnectTimeout(1200000);
            connection.setReadTimeout(1200000);
        } else {
            connection.setReadTimeout(0);
        }
        connection.connect();
        if (connection.getResponseCode() >= HttpURLConnection.HTTP_UNAUTHORIZED) throw new RequestException("HTTP Error Response Code: " + connection.getResponseCode(), connection.getResponseCode());
        String encoding = connection.getContentEncoding();
        InputStream inputStream = null;
        if (encoding != null && encoding.equalsIgnoreCase("gzip")) {
            inputStream = new GZIPInputStream(connection.getInputStream());
        } else if (encoding != null && encoding.equalsIgnoreCase("deflate")) {
            inputStream = new InflaterInputStream(connection.getInputStream(), new Inflater(true));
        } else {
            inputStream = connection.getInputStream();
        }
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        try {
            int bytesRead;
            while ((bytesRead = inputStream.read(buffer)) != -1) {
                os.write(buffer, 0, bytesRead);
            }
        } finally {
            if (os != null) {
                os.flush();
                os.close();
            }
            if (inputStream != null) {
                inputStream.close();
            }
        }
        return os.toByteArray();
    }
@Override
    public void doHandler(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        String directURL = request.getRequestURL().toString();
        response.setCharacterEncoding("gbk");
        PrintWriter out = response.getWriter();
        try {
            directURL = urlTools.urlFilter(directURL, true);
            URL url = new URL(directURL);
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream(), "gbk"));
            String line;
            while ((line = in.readLine()) != null) {
                out.println(line);
            }
            in.close();
        } catch (Exception e) {
            out.println("file not find");
        }
        out.flush();
    }
public static void copyFile(File sourceFile, File destFile) throws IOException {
        if (!sourceFile.exists()) {
            return;
        }
        if (!destFile.exists()) {
            destFile.createNewFile();
        }
        FileChannel source = null;
        FileChannel destination = null;
        source = new FileInputStream(sourceFile).getChannel();
        destination = new FileOutputStream(destFile).getChannel();
        if (destination != null && source != null) {
            destination.transferFrom(source, 0, source.size());
        }
        if (source != null) {
            source.close();
        }
        if (destination != null) {
            destination.close();
        }
    }
public static int sendButton(String url, String id, String command) throws ClientProtocolException, IOException {
        String connectString = url + "/rest/button/" + id + "/" + command;
        HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost(connectString);
        HttpResponse response = client.execute(post);
        int code = response.getStatusLine().getStatusCode();
        return code;
    }
private void readFromStorableInput(String filename) {
        try {
            URL url = new URL(getCodeBase(), filename);
            InputStream stream = url.openStream();
            StorableInput input = new StorableInput(stream);
            fDrawing.release();
            fDrawing = (Drawing) input.readStorable();
            view().setDrawing(fDrawing);
        } catch (IOException e) {
            initDrawing();
            showStatus("Error:" + e);
        }
    }
private void readFromObjectInput(String filename) {
        try {
            URL url = new URL(getCodeBase(), filename);
            InputStream stream = url.openStream();
            ObjectInput input = new ObjectInputStream(stream);
            fDrawing.release();
            fDrawing = (Drawing) input.readObject();
            view().setDrawing(fDrawing);
        } catch (IOException e) {
            initDrawing();
            showStatus("Error: " + e);
        } catch (ClassNotFoundException e) {
            initDrawing();
            showStatus("Class not found: " + e);
        }
    }
private synchronized void persist() {
        Connection conn = null;
        try {
            PoolManager pm = PoolManager.getInstance();
            conn = pm.getConnection(JukeXTrackStore.DB_NAME);
            conn.setAutoCommit(false);
            Statement state = conn.createStatement();
            state.executeUpdate("DELETE FROM PlaylistEntry WHERE playlistid=" + this.id);
            if (this.size() > 0) {
                StringBuffer sql = new StringBuffer();
                sql.append("INSERT INTO PlaylistEntry ( playlistid , trackid , position ) VALUES ");
                int location = 0;
                Iterator i = ll.iterator();
                while (i.hasNext()) {
                    long currTrackID = ((DatabaseObject) i.next()).getId();
                    sql.append('(').append(this.id).append(',').append(currTrackID).append(',').append(location++).append(')');
                    if (i.hasNext()) sql.append(',');
                }
                state.executeUpdate(sql.toString());
            }
            conn.commit();
            conn.setAutoCommit(true);
            state.close();
        } catch (SQLException se) {
            try {
                conn.rollback();
            } catch (SQLException ignore) {
            }
            log.error("Encountered an error persisting a playlist", se);
        } finally {
            try {
                conn.close();
            } catch (SQLException ignore) {
            }
        }
    }
public void render(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception {
        response.setContentType(s_contentType);
        response.setHeader("Cache-control", "no-cache");
        InputStream graphStream = getGraphStream(request);
        OutputStream out = getOutputStream(response);
        IOUtils.copy(graphStream, out);
        out.flush();
    }
public Configuration(URL url) {
        InputStream in = null;
        try {
            load(in = url.openStream());
        } catch (Exception e) {
            throw new RuntimeException("Could not load configuration from " + url, e);
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException ignore) {
                }
            }
        }
    }
@Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String fullUrl = req.getRequestURL().toString();
        if (fullUrl.indexOf(ip) != -1) {
            fullUrl = fullUrl.replaceAll(ip, "a.tbcdn.cn");
        }
        URL url = new URL(fullUrl);
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        PrintWriter out = resp.getWriter();
        String line;
        while ((line = in.readLine()) != null) {
            out.println(line);
        }
        in.close();
        out.flush();
    }
private void downloadImage(final String sImgName) {
        if (sImgName != null && sImgName.length() > 0) {
            File f = new File(m_sTargetDir);
            if (f.canWrite()) {
                f = new File(f, sImgName);
                if (!f.exists()) {
                    try {
                        URL url = new URL(m_sCodeBase + '/' + sImgName);
                        BufferedInputStream is = new BufferedInputStream(url.openStream());
                        BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(f));
                        int c;
                        while ((c = is.read()) != -1) {
                            os.write(c);
                        }
                        is.close();
                        os.close();
                    } catch (Exception exc) {
                        System.out.println("TestImagesHelper::downloadImage(): " + exc);
                    }
                }
            }
        }
    }
private String readDataFromUrl(URL url) throws IOException {
        InputStream inputStream = null;
        InputStreamReader streamReader = null;
        BufferedReader in = null;
        StringBuffer data = new StringBuffer();
        try {
            inputStream = url.openStream();
            streamReader = new InputStreamReader(inputStream);
            in = new BufferedReader(streamReader);
            String inputLine;
            while ((inputLine = in.readLine()) != null) data.append(inputLine);
        } finally {
            if (in != null) {
                in.close();
            }
            if (streamReader != null) {
                streamReader.close();
            }
            if (inputStream != null) {
                inputStream.close();
            }
        }
        return data.toString();
    }