semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static LinkedList Import(String url) throws Exception {
        LinkedList data = new LinkedList();
        BufferedReader in = new BufferedReader(new InputStreamReader((new URL(url)).openStream()));
        String csvLine;
        while ((csvLine = in.readLine()) != null) {
            StringTokenizer st = new StringTokenizer(csvLine, ",");
            CSVData cd = new CSVData();
            st.nextToken();
            st.nextToken();
            cd.matrNumber = Integer.parseInt(st.nextToken().trim());
            cd.fName = st.nextToken().trim();
            cd.lName = st.nextToken().trim();
            cd.email = st.nextToken().trim();
            cd.stdyPath = st.nextToken().trim();
            cd.sem = Integer.parseInt(st.nextToken().trim());
            data.add(cd);
        }
        in.close();
        return data;
    }
private String generateUniqueIdMD5(String workgroupIdString, String runIdString) {
            String passwordUnhashed = workgroupIdString + "-" + runIdString;
            MessageDigest m = null;
            try {
                m = MessageDigest.getInstance("MD5");
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
            }
            m.update(passwordUnhashed.getBytes(), 0, passwordUnhashed.length());
            String uniqueIdMD5 = new BigInteger(1, m.digest()).toString(16);
            return uniqueIdMD5;
        }
public static AudioFileFormat getAudioFileFormat(URL url) throws UnsupportedAudioFileException, IOException {
        InputStream inputStream = null;
        if (useragent != null) {
            URLConnection myCon = url.openConnection();
            myCon.setUseCaches(false);
            myCon.setDoInput(true);
            myCon.setDoOutput(true);
            myCon.setAllowUserInteraction(false);
            myCon.setRequestProperty("User-Agent", useragent);
            myCon.setRequestProperty("Accept", "*/*");
            myCon.setRequestProperty("Icy-Metadata", "1");
            myCon.setRequestProperty("Connection", "close");
            inputStream = new BufferedInputStream(myCon.getInputStream());
        } else {
            inputStream = new BufferedInputStream(url.openStream());
        }
        try {
            if (DEBUG == true) {
                System.err.println("Using AppletMpegSPIWorkaround to get codec (AudioFileFormat:url)");
            }
            return getAudioFileFormatForUrl(inputStream);
        } finally {
            inputStream.close();
        }
    }
public void updateFiles(String ourPath) {
        System.out.println("Update");
        DataInputStream dis = null;
        DataOutputStream dos = null;
        for (int i = 0; i < newFiles.size() && i < nameNewFiles.size(); i++) {
            try {
                dis = new DataInputStream(new FileInputStream((String) newFiles.get(i)));
                dos = new DataOutputStream(new FileOutputStream((new StringBuilder(String.valueOf(ourPath))).append("\\").append((String) nameNewFiles.get(i)).toString()));
            } catch (IOException e) {
                System.out.println(e.toString());
                System.exit(0);
            }
            try {
                do dos.writeChar(dis.readChar()); while (true);
            } catch (EOFException e) {
            } catch (IOException e) {
                System.out.println(e.toString());
            }
        }
    }
public PropertiesImpl(URL url) {
        this();
        InputStream in = null;
        lock.lock();
        try {
            in = url.openStream();
            PropertiesLexer lexer = new PropertiesLexer(in);
            lexer.lex();
            List<PropertiesToken> list = lexer.getList();
            new PropertiesParser(list, this).parse();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (in != null) try {
                in.close();
            } catch (IOException e) {
            }
            lock.unlock();
        }
    }
public static byte[] loadURLToBuffer(URL url, int maxLength) throws IOException {
        byte[] buf = new byte[maxLength];
        byte[] data = null;
        int iCount = 0;
        BufferedInputStream in = new BufferedInputStream(url.openStream(), 20480);
        iCount = in.read(buf, 0, buf.length);
        if (iCount != -1) {
            data = new byte[iCount];
            System.arraycopy(buf, 0, data, 0, iCount);
        }
        in.close();
        return data;
    }
public static byte[] loadURLToBuffer(URL url) throws IOException {
        byte[] buf = new byte[4096];
        byte[] data = null;
        byte[] temp = null;
        int iCount = 0;
        int iTotal = 0;
        BufferedInputStream in = new BufferedInputStream(url.openStream(), 20480);
        while ((iCount = in.read(buf, 0, buf.length)) != -1) {
            if (iTotal == 0) {
                data = new byte[iCount];
                System.arraycopy(buf, 0, data, 0, iCount);
                iTotal = iCount;
            } else {
                temp = new byte[iCount + iTotal];
                System.arraycopy(data, 0, temp, 0, iTotal);
                System.arraycopy(buf, 0, temp, iTotal, iCount);
                data = temp;
                iTotal = iTotal + iCount;
            }
        }
        in.close();
        return data;
    }
public static ArrayList<String> loadURLToStrings(URL url, int maxLines, String userAgent, int timeout) throws IOException {
        URLConnection connection = url.openConnection();
        if (userAgent != null && userAgent.trim().length() > 0) {
            connection.setRequestProperty("User-Agent", userAgent);
        } else {
            connection.setRequestProperty("User-Agent", "Mozilla/5.0 (compatible; astrominer/1.0;)");
        }
        if (timeout > 0) {
            connection.setConnectTimeout(timeout);
        }
        connection.connect();
        return loadURLToStrings(connection, maxLines);
    }
public static void main(String[] args) {
        File srcDir = new File(args[0]);
        File dstDir = new File(args[1]);
        File[] srcFiles = srcDir.listFiles();
        for (File f : srcFiles) {
            if (f.isDirectory()) continue;
            try {
                FileChannel srcChannel = new FileInputStream(f).getChannel();
                FileChannel dstChannel = new FileOutputStream(dstDir.getAbsolutePath() + System.getProperty("file.separator") + f.getName()).getChannel();
                ByteBuffer buffer = ByteBuffer.allocate(1024);
                int nr = 0;
                srcChannel.position(nr);
                nr += srcChannel.read(buffer);
                while (nr < f.length()) {
                    buffer.flip();
                    dstChannel.write(buffer);
                    buffer.clear();
                    nr += srcChannel.read(buffer);
                }
                srcChannel.close();
                dstChannel.close();
            } catch (IOException e) {
            }
        }
    }
@Override
    public void loadTest(StoryCardModel story) {
        String strUrl = story.getStoryCard().getAcceptanceTestUrl();
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder loader;
        try {
            URL url = new URL(strUrl);
            loader = factory.newDocumentBuilder();
            Document document;
            document = loader.parse(url.openStream());
            this.numPass = Integer.parseInt(((Element) document.getElementsByTagName("num-pass").item(0)).getFirstChild().getNodeValue());
            this.numFail = Integer.parseInt(((Element) document.getElementsByTagName("num-fail").item(0)).getFirstChild().getNodeValue());
            this.numRuns = Integer.parseInt(((Element) document.getElementsByTagName("num-runs").item(0)).getFirstChild().getNodeValue());
            this.numExceptions = Integer.parseInt(((Element) document.getElementsByTagName("num-exceptions").item(0)).getFirstChild().getNodeValue());
            this.wikiText = ((Element) document.getElementsByTagName("wiki").item(0)).getFirstChild().getNodeValue();
        } catch (Exception e) {
            util.Logger.singleton().error(e);
        }
    }
public void run() {
            if (data.length() > 0) {
                String method = getMethod();
                String action = getAction();
                URL url;
                try {
                    URL actionURL;
                    URL baseURL = hdoc.getBase();
                    if (action == null) {
                        String file = baseURL.getFile();
                        actionURL = new URL(baseURL.getProtocol(), baseURL.getHost(), baseURL.getPort(), file);
                    } else actionURL = new URL(baseURL, action);
                    URLConnection connection;
                    if ("post".equalsIgnoreCase(method)) {
                        url = actionURL;
                        connection = url.openConnection();
                        ((HttpURLConnection) connection).setFollowRedirects(false);
                        XRendererSupport.setCookies(url, connection);
                        connection.setRequestProperty("Accept-Language", "en-us");
                        connection.setRequestProperty("User-Agent", XRendererSupport.getContext().getUserAgent());
                        postData(connection, data);
                        XRendererSupport.getContext().getLogger().message(this, "Posted data: {" + data + "}");
                    } else {
                        url = new URL(actionURL + "?" + data);
                        connection = url.openConnection();
                        XRendererSupport.setCookies(url, connection);
                    }
                    connection.connect();
                    in = connection.getInputStream();
                    URL base = connection.getURL();
                    XRendererSupport.getCookies(base, connection);
                    XRendererSupport.getContext().getLogger().message(this, "Stream got ok.");
                    JEditorPane c = (JEditorPane) getContainer();
                    HTMLEditorKit kit = (HTMLEditorKit) c.getEditorKit();
                    newDoc = (HTMLDocument) kit.createDefaultDocument();
                    newDoc.putProperty(Document.StreamDescriptionProperty, base);
                    SwingUtilities.invokeLater(new Runnable() {

                        public void run() {
                            XRendererSupport.getContext().getLogger().message(this, "loading...");
                            loadDocument();
                            XRendererSupport.getContext().getLogger().message(this, "document loaded...");
                        }
                    });
                } catch (MalformedURLException m) {
                } catch (IOException e) {
                }
            }
        }
public HttpResponse navigateTo(URI url) {
        log.debug("navigateTo: " + url.toString());
        HttpGet get = new HttpGet(url);
        try {
            HttpResponse response = client.execute(get);
            log.debug(response.getStatusLine());
            return response;
        } catch (ClientProtocolException e) {
            e.printStackTrace();
            return null;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
private static void copyFile(File in, File out) throws IOException {
        FileChannel inChannel = new FileInputStream(in).getChannel();
        FileChannel outChannel = new FileOutputStream(out).getChannel();
        try {
            inChannel.transferTo(0, inChannel.size(), outChannel);
        } catch (IOException e) {
            throw e;
        } finally {
            if (inChannel != null) inChannel.close();
            if (outChannel != null) outChannel.close();
        }
    }
@Test
    public void mockingURLWorks() throws Exception {
        URL url = mock(URL.class);
        URLConnection urlConnectionMock = mock(URLConnection.class);
        when(url.openConnection()).thenReturn(urlConnectionMock);
        URLConnection openConnection = url.openConnection();
        assertSame(openConnection, urlConnectionMock);
    }
public String getResource(String resourceName) throws IOException {
        InputStream resourceStream = resourceClass.getResourceAsStream(resourceName);
        ByteArrayOutputStream baos = new ByteArrayOutputStream(2048);
        IOUtils.copyAndClose(resourceStream, baos);
        String expected = new String(baos.toByteArray());
        return expected;
    }
public static void copy(File source, File destination) {
        try {
            FileInputStream fileInputStream = new FileInputStream(source);
            FileOutputStream fileOutputStream = new FileOutputStream(destination);
            FileChannel inputChannel = fileInputStream.getChannel();
            FileChannel outputChannel = fileOutputStream.getChannel();
            transfer(inputChannel, outputChannel, source.length(), 1024 * 1024 * 32, true, true);
            fileInputStream.close();
            fileOutputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
public static BufferedReader getReader(int license) {
        URL url = getResource(license);
        if (url == null) return null;
        InputStream inStream;
        try {
            inStream = url.openStream();
        } catch (IOException e) {
            return null;
        }
        return new BufferedReader(new InputStreamReader(inStream));
    }
public int visitStatement(String statement) throws SQLException {
        mySQLLogger.info(statement);
        if (getConnection() == null) {
            throw new JdbcException("cannot exec: " + statement + ", because 'not connected to database'");
        }
        Statement stmt = getConnection().createStatement();
        try {
            return stmt.executeUpdate(statement);
        } catch (SQLException ex) {
            getConnection().rollback();
            throw ex;
        } finally {
            stmt.close();
        }
    }
public void setTypeRefs(Connection conn) {
        log.traceln("\tProcessing " + table + " references..");
        try {
            String query = " select distinct c.id, c.qualifiedname from " + table + ", CLASSTYPE c " + " where " + table + "." + reffield + " is null and " + table + "." + classnamefield + " = c.qualifiedname";
            PreparedStatement pstmt = conn.prepareStatement(query);
            long start = new Date().getTime();
            ResultSet rset = pstmt.executeQuery();
            long queryTime = new Date().getTime() - start;
            log.debug("query time: " + queryTime + " ms");
            String update = "update " + table + " set " + reffield + "=? where " + classnamefield + "=? and " + reffield + " is null";
            PreparedStatement pstmt2 = conn.prepareStatement(update);
            int n = 0;
            start = new Date().getTime();
            while (rset.next()) {
                n++;
                pstmt2.setInt(1, rset.getInt(1));
                pstmt2.setString(2, rset.getString(2));
                pstmt2.executeUpdate();
            }
            queryTime = new Date().getTime() - start;
            log.debug("total update time: " + queryTime + " ms");
            log.debug("number of times through loop: " + n);
            if (n > 0) log.debug("avg update time: " + (queryTime / n) + " ms");
            pstmt2.close();
            rset.close();
            pstmt.close();
            conn.commit();
            log.verbose("Updated (committed) " + table + " references");
        } catch (SQLException ex) {
            log.error("Internal Reference Update Failed!");
            DBUtils.logSQLException(ex);
            log.error("Rolling back..");
            try {
                conn.rollback();
            } catch (SQLException inner_ex) {
                log.error("rollback failed!");
            }
        }
    }
public InputStream openFileInputStream(String fileName) throws IOException {
        if (fileName.indexOf(':') > 1) {
            URL url = new URL(fileName);
            InputStream in = url.openStream();
            return in;
        }
        fileName = translateFileName(fileName);
        FileInputStream in = new FileInputStream(fileName);
        trace("openFileInputStream", fileName, in);
        return in;
    }
private void initUserExtensions(SeleniumConfiguration seleniumConfiguration) throws IOException {
        StringBuilder contents = new StringBuilder();
        StringOutputStream s = new StringOutputStream();
        IOUtils.copy(SeleniumConfiguration.class.getResourceAsStream("default-user-extensions.js"), s);
        contents.append(s.toString());
        File providedUserExtensions = seleniumConfiguration.getFile(ConfigurationPropertyKeys.SELENIUM_USER_EXTENSIONS, seleniumConfiguration.getDirectoryConfiguration().getInput(), false);
        if (providedUserExtensions != null) {
            contents.append(FileUtils.readFileToString(providedUserExtensions, null));
        }
        seleniumUserExtensions = new File(seleniumConfiguration.getDirectoryConfiguration().getInput(), "user-extensions.js");
        FileUtils.forceMkdir(seleniumUserExtensions.getParentFile());
        FileUtils.writeStringToFile(seleniumUserExtensions, contents.toString(), null);
    }
private void prepareQueryResultData(ZipEntryRef zer, String nodeDir, String reportDir, Set<ZipEntryRef> statusZers) throws Exception {
        String jobDir = nodeDir + File.separator + "job_" + zer.getUri();
        if (!WorkDirectory.isWorkingDirectoryValid(jobDir)) {
            throw new Exception("Cannot acces to " + jobDir);
        }
        File f = new File(jobDir + File.separator + "result.xml");
        if (!f.exists() || !f.isFile() || !f.canRead()) {
            throw new Exception("Cannot acces to result file " + f.getAbsolutePath());
        }
        String fcopyName = reportDir + File.separator + zer.getName() + ".xml";
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(f));
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(fcopyName));
        IOUtils.copy(bis, bos);
        bis.close();
        bos.close();
        zer.setUri(fcopyName);
        f = new File(jobDir + File.separator + "status.xml");
        if (!f.exists() || !f.isFile() || !f.canRead()) {
            throw new Exception("Cannot acces to status file " + f.getAbsolutePath());
        }
        fcopyName = reportDir + File.separator + zer.getName() + "_status.xml";
        bis = new BufferedInputStream(new FileInputStream(f));
        bos = new BufferedOutputStream(new FileOutputStream(fcopyName));
        IOUtils.copy(bis, bos);
        bis.close();
        bos.close();
        statusZers.add(new ZipEntryRef(ZipEntryRef.SINGLE_FILE, zer.getName(), fcopyName, ZipEntryRef.WITH_REL));
    }
public void loadSourceCode() {
        if (getResourceName() != null) {
            String filename = getResourceName() + ".java";
            sourceCode = new String("<html><body bgcolor=\"#ffffff\"><pre>");
            InputStream is;
            InputStreamReader isr;
            CodeViewer cv = new CodeViewer();
            URL url;
            try {
                url = getClass().getResource(filename);
                is = url.openStream();
                isr = new InputStreamReader(is);
                BufferedReader reader = new BufferedReader(isr);
                String line = reader.readLine();
                while (line != null) {
                    sourceCode += cv.syntaxHighlight(line) + " \n ";
                    line = reader.readLine();
                }
                sourceCode += new String("</pre></body></html>");
            } catch (Exception ex) {
                sourceCode = "Could not load file: " + filename;
            }
        }
    }
public static void copyTo(java.io.File source, java.io.File dest) throws Exception {
        java.io.FileInputStream inputStream = null;
        java.nio.channels.FileChannel sourceChannel = null;
        java.io.FileOutputStream outputStream = null;
        java.nio.channels.FileChannel destChannel = null;
        long size = source.length();
        long bufferSize = 1024;
        long count = 0;
        if (size < bufferSize) bufferSize = size;
        Exception exception = null;
        try {
            if (dest.exists() == false) dest.createNewFile();
            inputStream = new java.io.FileInputStream(source);
            sourceChannel = inputStream.getChannel();
            outputStream = new java.io.FileOutputStream(dest);
            destChannel = outputStream.getChannel();
            while (count < size) count += sourceChannel.transferTo(count, bufferSize, destChannel);
        } catch (Exception e) {
            exception = e;
        } finally {
            closeFileChannel(sourceChannel);
            closeFileChannel(destChannel);
        }
        if (exception != null) throw exception;
    }
@Override
    public void Start() {
        try {
            Enumeration<URL> resources = Configurator.class.getClassLoader().getResources(IOCContainer.GetApplicationName() + ".config");
            while (resources.hasMoreElements()) {
                URL url = resources.nextElement();
                if (Logger.logger.isDebugEnabled()) {
                    Logger.logger.debug("Loading '" + url + "'");
                }
                JSONValue configFileContents = JSONValue.Decode(url.openStream(), url.toString());
                if (configFileContents instanceof JSONObjectValue) {
                    for (Configurable configurable : IOCContainer.LookupAll(Configurable.class)) {
                        JSONValue jsonData = ((JSONObjectValue) configFileContents).GetProperty(configurable.GetConfigSectionName());
                        if (jsonData != null) {
                            if (Logger.logger.isDebugEnabled()) {
                                Logger.logger.debug("Configurging " + configurable.getClass() + " with '" + jsonData.Encode());
                            }
                            try {
                                configurable.Configure(jsonData);
                            } catch (Throwable th1) {
                                Logger.logger.error("Caught throwable while configuring " + configurable.getClass() + ":" + th1.getMessage() + ". IGNORED.", th1);
                                Logger.logger.error("[Continued]. Config Data was:" + jsonData.Encode());
                            }
                        }
                    }
                } else {
                    Logger.logger.error("'" + url + "' does not contain a json object. Skipping and looking for other applciation.config files in classpath ...");
                }
            }
        } catch (Throwable th) {
            throw new RuntimeException("Exception while attempting to load application.config:'" + th.getMessage() + "'", th);
        }
    }
private static String completeGet(String encodedURLStr) throws IOException {
        URL url = new URL(encodedURLStr);
        HttpURLConnection connection = initConnection(url);
        String result = getReply(url.openStream());
        connection.disconnect();
        return result;
    }
protected static int[] sort(int[] arr) {
        for (int i = arr.length - 1; i > 0; i--) {
            for (int j = 0; j < i; j++) {
                if (arr[j] > arr[j + 1]) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
        return arr;
    }
private ByteBuffer readProgram(URL url) throws IOException {
        StringBuilder program = new StringBuilder();
        BufferedReader in = null;
        try {
            in = new BufferedReader(new InputStreamReader(url.openStream()));
            String line;
            while ((line = in.readLine()) != null) {
                program.append(line).append("\n");
            }
        } finally {
            if (in != null) in.close();
        }
        ByteBuffer buffer = BufferUtils.createByteBuffer(program.length());
        for (int i = 0; i < program.length(); i++) {
            buffer.put((byte) (program.charAt(i) & 0xFF));
        }
        buffer.flip();
        return buffer;
    }