semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void testOptionalSections() throws Exception {
        final File implementationDirectory = this.getTestSourcesDirectory();
        final File specificationDirectory = this.getTestSourcesDirectory();
        IOUtils.copy(this.getClass().getResourceAsStream("ImplementationWithoutConstructorsSection.java.txt"), new FileOutputStream(new File(implementationDirectory, "Implementation.java")));
        this.getTestTool().manageSources(this.getTestTool().getModules().getImplementation("Implementation"), implementationDirectory);
        IOUtils.copy(this.getClass().getResourceAsStream("ImplementationWithoutDefaultConstructorSection.java.txt"), new FileOutputStream(new File(implementationDirectory, "Implementation.java")));
        this.getTestTool().manageSources(this.getTestTool().getModules().getImplementation("Implementation"), implementationDirectory);
        IOUtils.copy(this.getClass().getResourceAsStream("ImplementationWithoutDocumentationSection.java.txt"), new FileOutputStream(new File(implementationDirectory, "Implementation.java")));
        this.getTestTool().manageSources(this.getTestTool().getModules().getImplementation("Implementation"), implementationDirectory);
        IOUtils.copy(this.getClass().getResourceAsStream("ImplementationWithoutLicenseSection.java.txt"), new FileOutputStream(new File(implementationDirectory, "Implementation.java")));
        this.getTestTool().manageSources(this.getTestTool().getModules().getImplementation("Implementation"), implementationDirectory);
        IOUtils.copy(this.getClass().getResourceAsStream("SpecificationWithoutDocumentationSection.java.txt"), new FileOutputStream(new File(specificationDirectory, "Specification.java")));
        this.getTestTool().manageSources(this.getTestTool().getModules().getSpecification("Specification"), specificationDirectory);
        IOUtils.copy(this.getClass().getResourceAsStream("SpecificationWithoutLicenseSection.java.txt"), new FileOutputStream(new File(specificationDirectory, "Specification.java")));
        this.getTestTool().manageSources(this.getTestTool().getModules().getSpecification("Specification"), specificationDirectory);
    }
private void Download(String uri) throws MalformedURLException {
        URL url = new URL(uri);
        try {
            bm = BitmapFactory.decodeStream(url.openConnection().getInputStream());
        } catch (IOException ex) {
            bm = getError();
        }
    }
public static void writeFileType(String uriFile, String outputfile, int num) {
        BufferedWriter writer = null;
        String uri = null;
        try {
            int counter = 1;
            writer = new BufferedWriter(new FileWriter(outputfile));
            BufferedReader reader = new BufferedReader(new FileReader(uriFile));
            uri = null;
            while (counter < num) {
                uri = reader.readLine();
                counter++;
            }
            while ((uri = reader.readLine()) != null) {
                try {
                    System.err.println("working on the [" + counter + "]th document.");
                    counter++;
                    URL url = new URL(uri);
                    URLConnection myConnection = url.openConnection();
                    BufferedReader myReader = new BufferedReader(new InputStreamReader(myConnection.getInputStream()));
                    String line = null;
                    boolean hasOWL = false;
                    boolean hasRDFS = false;
                    boolean hasRDF = false;
                    int linecount = 0;
                    while ((line = myReader.readLine()) != null) {
                        if (line.indexOf("http://www.w3.org/2002/07/owl") != -1) hasOWL = true; else if (line.indexOf("http://www.w3.org/2000/01/rdf-schema") != -1) hasRDFS = true; else if (line.indexOf("http://www.w3.org/1999/02/22-rdf-syntax-ns") != -1) hasRDF = true;
                        linecount++;
                        if (linecount > 100) break;
                    }
                    if (hasOWL) writer.write(uri + "\t" + OWL); else if (hasRDFS) writer.write(uri + "\t" + RDFS); else if (hasRDF) writer.write(uri + "\t" + RDF); else writer.write(uri + "\t" + UNKNOWN);
                    writer.newLine();
                    writer.flush();
                } catch (Exception e) {
                    e.printStackTrace();
                    try {
                        writer.write(uri + "\t" + BROKEN);
                        writer.newLine();
                        writer.flush();
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
public void copyFile(File source, File destination) {
        try {
            FileInputStream sourceStream = new FileInputStream(source);
            try {
                FileOutputStream destinationStream = new FileOutputStream(destination);
                try {
                    FileChannel sourceChannel = sourceStream.getChannel();
                    sourceChannel.transferTo(0, sourceChannel.size(), destinationStream.getChannel());
                } finally {
                    try {
                        destinationStream.close();
                    } catch (Exception e) {
                        throw new RuntimeIoException(e, IoMode.CLOSE);
                    }
                }
            } finally {
                try {
                    sourceStream.close();
                } catch (Exception e) {
                    throw new RuntimeIoException(e, IoMode.CLOSE);
                }
            }
        } catch (IOException e) {
            throw new RuntimeIoException(e, IoMode.COPY);
        }
    }
public static void copyFile(File source, File dest) throws IOException {
        FileChannel in = null, out = null;
        try {
            in = new FileInputStream(source).getChannel();
            out = new FileOutputStream(dest).getChannel();
            in.transferTo(0, in.size(), out);
        } catch (Exception e) {
            log.error(e, e);
        } finally {
            if (in != null) in.close();
            if (out != null) out.close();
        }
    }
@Test
    public void testWrite() {
        System.out.println("write");
        final File[] files = { new File(sharePath) };
        System.out.println("Creating hash...");
        String initHash = MD5File.MD5Directory(files[0]);
        System.out.println("Hash: " + initHash);
        Share readShare = ShareUtility.createShare(files, "TestShare");
        System.out.println("Creating shares...");
        final ShareFolder[] readers = ShareUtility.cropShareToParts(readShare, PARTS);
        System.out.println("Reading and writing shares...");
        done = 0;
        for (int i = 0; i < PARTS; i++) {
            final int j = i;
            new Thread() {

                public void run() {
                    ShareFolder part = (ShareFolder) ObjectClone.clone(readers[j]);
                    ShareFileReader reader = new ShareFileReader(readers[j], files[0]);
                    ShareFileWriter writer = new ShareFileWriter(part, new File("Downloads/" + readers[j].getName()));
                    long tot = 0;
                    byte[] b = new byte[(int) (Math.random() * 10000)];
                    while (tot < readers[j].getSize()) {
                        reader.read(b);
                        byte[] bwrite = new byte[(int) (Math.random() * 10000) + b.length];
                        System.arraycopy(b, 0, bwrite, 0, b.length);
                        writer.write(bwrite, b.length);
                        tot += b.length;
                    }
                    done++;
                    System.out.println((int) (done * 100.0 / PARTS) + "% Complete");
                }
            }.start();
        }
        while (done < PARTS) {
            Thread.yield();
        }
        File resultFile = new File("Downloads/" + readShare.getName());
        System.out.println("Creating hash of written share...");
        String resultHash = MD5File.MD5Directory(resultFile);
        System.out.println("Init hash:   " + initHash);
        System.out.println("Result hash: " + resultHash);
        assertEquals(initHash, resultHash);
    }
public void run() {
                    ShareFolder part = (ShareFolder) ObjectClone.clone(readers[j]);
                    ShareFileReader reader = new ShareFileReader(readers[j], files[0]);
                    ShareFileWriter writer = new ShareFileWriter(part, new File("Downloads/" + readers[j].getName()));
                    long tot = 0;
                    byte[] b = new byte[(int) (Math.random() * 10000)];
                    while (tot < readers[j].getSize()) {
                        reader.read(b);
                        byte[] bwrite = new byte[(int) (Math.random() * 10000) + b.length];
                        System.arraycopy(b, 0, bwrite, 0, b.length);
                        writer.write(bwrite, b.length);
                        tot += b.length;
                    }
                    done++;
                    System.out.println((int) (done * 100.0 / PARTS) + "% Complete");
                }
public User getUser(String userlogin) {
        UserDAO userDAO = new UserDAO();
        User user = null;
        try {
            user = userDAO.load(userlogin);
            if (user == null) {
                URL url = Thread.currentThread().getContextClassLoader().getResource("users.cfg");
                BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
                String linea = br.readLine();
                while (linea != null) {
                    StringTokenizer st = new StringTokenizer(linea, ":");
                    if (st.countTokens() == 3) {
                        String login = st.nextToken();
                        String password = st.nextToken();
                        String profile = st.nextToken();
                        if (login.equals(userlogin)) {
                            user = new User(login, password, profile);
                            userDAO.save(user);
                        }
                    } else {
                    }
                    linea = br.readLine();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return user;
    }
@Override
    public void onLoadingEnded() {
        if (m_frame != null) {
            try {
                String urltext = getDocument().getDocumentURI();
                URL url = new URL(urltext);
                InputStreamReader isr = new InputStreamReader(url.openStream());
                BufferedReader in = new BufferedReader(isr);
                String inputLine;
                urltext = null;
                url = null;
                m_content.clear();
                while ((inputLine = in.readLine()) != null) {
                    m_content.add(inputLine);
                }
                in.close();
                isr = null;
                in = null;
                inputLine = null;
                Action action = parseHtml();
                if (action.value() == Action.ACTION_BROWSER_LOADING_DONE && action.toString().equals(Action.COMMAND_CARD_PREVIEW)) {
                    FileUtils.copyURLToFile(new URL(getCardImageURL(m_card.MID)), new File(m_card.getImagePath()));
                    fireActionEvent(MainWindow.class, action.value(), action.toString());
                }
                action = null;
            } catch (Exception ex) {
                Dialog.ErrorBox(m_frame, ex.getStackTrace());
            }
        }
        m_loading = false;
    }
private static void extractSOUNDFILES() throws Exception {
        ArrayList<File> soundFiles = new ArrayList<File>();
        File soundsFolder = new File("/var/lib/asterisk/sounds/");
        if (soundsFolder.exists()) {
            File soundFiles1[] = soundsFolder.listFiles(new FilenameFilter() {

                @Override
                public boolean accept(File dir, String name) {
                    if (NullStatus.isNull(name)) {
                        return false;
                    }
                    if (name.endsWith("-sounds.jar")) {
                        return true;
                    }
                    return false;
                }
            });
            for (int i = 0; i < soundFiles1.length; i++) {
                soundFiles.add(soundFiles1[i]);
            }
        }
        soundsFolder = new File("/opt/jboss/server/default/deploy/Tobe.war/WEB-INF/lib/");
        if (soundsFolder.exists()) {
            File soundFiles1[] = soundsFolder.listFiles(new FilenameFilter() {

                @Override
                public boolean accept(File dir, String name) {
                    if (NullStatus.isNull(name)) {
                        return false;
                    }
                    if (name.endsWith("-sounds.jar")) {
                        return true;
                    }
                    return false;
                }
            });
            for (int i = 0; i < soundFiles1.length; i++) {
                soundFiles.add(soundFiles1[i]);
            }
        }
        for (int i = 0; i < soundFiles.size(); i++) {
            ZipFile zipFile = new ZipFile(soundFiles.get(i));
            InputStream inputStream = null;
            Enumeration<? extends ZipEntry> oEnum = zipFile.entries();
            while (oEnum.hasMoreElements()) {
                ZipEntry zipEntry = oEnum.nextElement();
                File file = new File("/var/lib/asterisk/sounds/", zipEntry.getName());
                if (zipEntry.isDirectory()) {
                    file.mkdirs();
                } else {
                    inputStream = zipFile.getInputStream(zipEntry);
                    FileOutputStream fos = new FileOutputStream(file);
                    IOUtils.copy(inputStream, fos);
                    fos.close();
                }
            }
        }
    }
private static void exportConfigResource(ClassLoader classLoader, String resourceName, String targetFileName) throws Exception {
        InputStream is = classLoader.getResourceAsStream(resourceName);
        FileOutputStream fos = new FileOutputStream(targetFileName, false);
        IOUtils.copy(is, fos);
        fos.close();
        is.close();
    }
private boolean getCached(Get g) throws IOException {
        boolean ret = false;
        File f = getCachedFile(g);
        if (f.exists()) {
            InputStream is = null;
            OutputStream os = null;
            try {
                is = new FileInputStream(f);
                os = new FileOutputStream(getDestFile(g));
                int read;
                byte[] buffer = new byte[4096];
                while ((read = is.read(buffer)) > 0) {
                    os.write(buffer, 0, read);
                }
                ret = true;
            } finally {
                if (is != null) is.close();
                if (os != null) os.close();
                is = null;
                os = null;
            }
        }
        return ret;
    }
private boolean get(String surl, File dst, Get get) throws IOException {
        boolean ret = false;
        InputStream is = null;
        OutputStream os = null;
        try {
            try {
                if (surl.startsWith("file://")) {
                    is = new FileInputStream(surl.substring(7));
                } else {
                    URL url = new URL(surl);
                    is = url.openStream();
                }
                if (is != null) {
                    os = new FileOutputStream(dst);
                    int read;
                    byte[] buffer = new byte[4096];
                    while ((read = is.read(buffer)) > 0) {
                        os.write(buffer, 0, read);
                    }
                    ret = true;
                }
            } catch (ConnectException ex) {
                log("Connect exception " + ex.getMessage(), ex, 3);
                if (dst.exists()) dst.delete();
            } catch (UnknownHostException ex) {
                log("Unknown host " + ex.getMessage(), ex, 3);
            } catch (FileNotFoundException ex) {
                log("File not found: " + ex.getMessage(), 3);
            }
        } finally {
            if (is != null) is.close();
            if (os != null) os.close();
            is = null;
            os = null;
        }
        if (ret) {
            try {
                is = new FileInputStream(dst);
                os = new FileOutputStream(getCachedFile(get));
                int read;
                byte[] buffer = new byte[4096];
                while ((read = is.read(buffer)) > 0) {
                    os.write(buffer, 0, read);
                }
            } finally {
                if (is != null) is.close();
                if (os != null) os.close();
                is = null;
                os = null;
            }
        }
        return ret;
    }
public void setInternalReferences() {
        for (int i = 0; i < REFSPECS.length; i++) {
            REFSPECS[i].setTypeRefs(conn);
        }
        String sql, sql2;
        try {
            String[][] params2 = { { "PACKAGE", "name" }, { "CLASSTYPE", "qualifiedname" }, { "MEMBER", "qualifiedname" }, { "EXECMEMBER", "fullyqualifiedname" } };
            for (int i = 0; i < params2.length; i++) {
                log.traceln("\tProcessing seetag " + params2[i][0] + " references..");
                sql = "select r.sourcedoc_id, " + params2[i][0] + ".id, " + params2[i][0] + "." + params2[i][1] + " from REFERENCE r, " + params2[i][0] + " where r.refdoc_name = " + params2[i][0] + "." + params2[i][1] + " and r.refdoc_id is null";
                Statement stmt = conn.createStatement();
                ResultSet rset = stmt.executeQuery(sql);
                sql2 = "update REFERENCE set refdoc_id=? where sourcedoc_id=? and refdoc_name=?";
                PreparedStatement pstmt = conn.prepareStatement(sql2);
                while (rset.next()) {
                    pstmt.clearParameters();
                    pstmt.setInt(1, rset.getInt(2));
                    pstmt.setInt(2, rset.getInt(1));
                    pstmt.setString(3, rset.getString(3));
                    pstmt.executeUpdate();
                }
                pstmt.close();
                rset.close();
                stmt.close();
                conn.commit();
            }
        } 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 synchronized String encrypt(String plaintext) throws SystemUnavailableException {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("SHA");
        } catch (NoSuchAlgorithmException e) {
            throw new SystemUnavailableException(e.getMessage());
        }
        try {
            md.update(plaintext.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            throw new SystemUnavailableException(e.getMessage());
        }
        byte raw[] = md.digest();
        String hash = new Base64().encodeAsString(raw);
        return hash;
    }
public static final String enCode(String algorithm, String string) {
        MessageDigest md;
        String result = "";
        try {
            md = MessageDigest.getInstance(algorithm);
            md.update(string.getBytes());
            result = binaryToString(md.digest());
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return result;
    }
private HttpURLConnection sendData(URL url, String user, String password) throws IOException, IllegalArgumentException {
        String tmpAuthUserName = "";
        if (user != null) {
            tmpAuthUserName = user;
        }
        final String anAuthUserName = tmpAuthUserName;
        String tmpAuthPasswd = "";
        if (password != null) {
            tmpAuthPasswd = password;
        }
        final String anAuthPasswd = tmpAuthPasswd;
        Authenticator.setDefault(new Authenticator() {

            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(anAuthUserName, anAuthPasswd.toCharArray());
            }
        });
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");
        conn.setReadTimeout(1000);
        conn.connect();
        return conn;
    }
public static byte[] readFromURI(URI uri) throws IOException {
        if (uri.toString().contains("http:")) {
            URL url = uri.toURL();
            URLConnection urlConnection = url.openConnection();
            int length = urlConnection.getContentLength();
            System.out.println("length of content in URL = " + length);
            if (length > -1) {
                byte[] pureContent = new byte[length];
                DataInputStream dis = new DataInputStream(urlConnection.getInputStream());
                dis.readFully(pureContent, 0, length);
                dis.close();
                return pureContent;
            } else {
                throw new IOException("Unable to determine the content-length of the document pointed at " + url.toString());
            }
        } else {
            return readWholeFile(uri).getBytes("UTF-8");
        }
    }
public void testHttpsConnection() throws Throwable {
        setUpStoreProperties();
        try {
            SSLContext ctx = getContext();
            ServerSocket ss = ctx.getServerSocketFactory().createServerSocket(0);
            TestHostnameVerifier hnv = new TestHostnameVerifier();
            HttpsURLConnection.setDefaultHostnameVerifier(hnv);
            URL url = new URL("https://localhost:" + ss.getLocalPort());
            HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
            SSLSocket peerSocket = (SSLSocket) doInteraction(connection, ss);
            checkConnectionStateParameters(connection, peerSocket);
            connection.connect();
        } finally {
            tearDownStoreProperties();
        }
    }
public void testHttpsPersistentConnection() throws Throwable {
        setUpStoreProperties();
        try {
            SSLContext ctx = getContext();
            ServerSocket ss = ctx.getServerSocketFactory().createServerSocket(0);
            TestHostnameVerifier hnv = new TestHostnameVerifier();
            HttpsURLConnection.setDefaultHostnameVerifier(hnv);
            URL url = new URL("https://localhost:" + ss.getLocalPort());
            HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
            SSLSocket peerSocket = (SSLSocket) doPersistentInteraction(connection, ss);
            checkConnectionStateParameters(connection, peerSocket);
            connection.connect();
        } finally {
            tearDownStoreProperties();
        }
    }
public void testHttpsConnection_Not_Found_Response() throws Throwable {
        setUpStoreProperties();
        try {
            SSLContext ctx = getContext();
            ServerSocket ss = ctx.getServerSocketFactory().createServerSocket(0);
            TestHostnameVerifier hnv = new TestHostnameVerifier();
            HttpsURLConnection.setDefaultHostnameVerifier(hnv);
            URL url = new URL("https://localhost:" + ss.getLocalPort());
            HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
            try {
                doInteraction(connection, ss, NOT_FOUND_CODE);
                fail("Expected exception was not thrown.");
            } catch (FileNotFoundException e) {
                if (DO_LOG) {
                    System.out.println("Expected exception was thrown: " + e.getMessage());
                }
            }
            connection.connect();
        } finally {
            tearDownStoreProperties();
        }
    }