semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = null;
        try {
            serverSocket = new ServerSocket(4444);
        } catch (IOException e) {
            System.err.println("Could not listen on port: 4444.");
            System.exit(1);
        }
        Socket clientSocket = null;
        try {
            clientSocket = serverSocket.accept();
        } catch (IOException e) {
            System.err.println("Accept failed.");
            System.exit(1);
        }
        DataOutputStream out = new DataOutputStream(clientSocket.getOutputStream());
        BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
        String inputLine, outputLine;
        inputLine = in.readLine();
        String dist_metric = in.readLine();
        File outFile = new File("data.txt");
        FileWriter outw = new FileWriter(outFile);
        outw.write(inputLine);
        outw.close();
        File sample_coords = new File("sample_coords.txt");
        sample_coords.delete();
        File sp_coords = new File("sp_coords.txt");
        sp_coords.delete();
        try {
            System.out.println("Running python script...");
            System.out.println("Command: " + "python l19test.py " + "\"" + dist_metric + "\"");
            Process pr = Runtime.getRuntime().exec("python l19test.py " + dist_metric);
            BufferedReader br = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
            String line;
            while ((line = br.readLine()) != null) {
                System.out.println(line);
            }
            int exitVal = pr.waitFor();
            System.out.println("Process Exit Value: " + exitVal);
            System.out.println("done.");
        } catch (Exception e) {
            System.out.println("Unable to run python script for PCoA analysis");
        }
        File myFile = new File("sp_coords.txt");
        byte[] mybytearray = new byte[(new Long(myFile.length())).intValue()];
        FileInputStream fis = new FileInputStream(myFile);
        System.out.println(".");
        System.out.println(myFile.length());
        out.writeInt((int) myFile.length());
        for (int i = 0; i < myFile.length(); i++) {
            out.writeByte(fis.read());
        }
        myFile = new File("sample_coords.txt");
        mybytearray = new byte[(int) myFile.length()];
        fis = new FileInputStream(myFile);
        fis.read(mybytearray);
        System.out.println(".");
        System.out.println(myFile.length());
        out.writeInt((int) myFile.length());
        out.write(mybytearray);
        myFile = new File("evals.txt");
        mybytearray = new byte[(new Long(myFile.length())).intValue()];
        fis = new FileInputStream(myFile);
        fis.read(mybytearray);
        System.out.println(".");
        System.out.println(myFile.length());
        out.writeInt((int) myFile.length());
        out.write(mybytearray);
        out.flush();
        out.close();
        in.close();
        clientSocket.close();
        serverSocket.close();
    }
public byte[] pipeBytes() {
        byte ba[] = null;
        try {
            URL url = new URL(server);
            conn = (HttpURLConnection) url.openConnection();
            InputStream is = conn.getInputStream();
            ByteArrayOutputStream tout = new ByteArrayOutputStream();
            int nmax = 10000;
            byte b[] = new byte[nmax + 1];
            int nread = 0;
            while ((nread = is.read(b, 0, nmax)) >= 0) tout.write(b, 0, nread);
            ba = tout.toByteArray();
        } catch (Exception ex) {
            System.err.println(ex);
        }
        return ba;
    }
public static String encrypt(String password, Long digestSeed) {
        try {
            MessageDigest algorithm = MessageDigest.getInstance("MD5");
            algorithm.reset();
            algorithm.update(password.getBytes("UTF-8"));
            algorithm.update(digestSeed.toString().getBytes("UTF-8"));
            byte[] messageDigest = algorithm.digest();
            StringBuffer hexString = new StringBuffer();
            for (int i = 0; i < messageDigest.length; i++) {
                hexString.append(Integer.toHexString(0xff & messageDigest[i]));
            }
            return hexString.toString();
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
    }
public static String getMD5(String... list) {
        if (list.length == 0) return null;
        MessageDigest md;
        try {
            md = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
        md.reset();
        for (String in : list) md.update(in.getBytes());
        byte[] digest = md.digest();
        StringBuilder hexString = new StringBuilder();
        for (int i = 0; i < digest.length; ++i) {
            String hex = Integer.toHexString(0xFF & digest[i]);
            if (hex.length() == 1) hexString.append('0');
            hexString.append(hex);
        }
        return hexString.toString();
    }
@Test
    public void testSecondary() throws Exception {
        ConnectionFactoryIF cf = new DefaultConnectionFactory(PropertyUtils.loadProperties(StreamUtils.getInputStream(propfile)), false);
        Connection conn = cf.requestConnection();
        try {
            Statement stm = conn.createStatement();
            stm.executeUpdate("drop table if exists first");
            stm.executeUpdate("drop table if exists first_changes");
            stm.executeUpdate("drop table if exists second");
            stm.executeUpdate("drop table if exists second_changes");
            stm.executeUpdate("create table first (a integer, b varchar, c integer, d date)");
            stm.executeUpdate("create table first_changes (a integer, b varchar, c integer, d date, ct varchar, cd integer)");
            stm.executeUpdate("create table second (a integer, b varchar, c integer, d date)");
            stm.executeUpdate("create table second_changes (a integer, b varchar, c integer, d date, ct varchar, cd integer)");
            stm.executeUpdate("insert into first (a,b,c,d) values (1,'a',10, date '2007-01-01')");
            stm.executeUpdate("insert into first (a,b,c,d) values (2,'b',20, date '2007-01-02')");
            stm.executeUpdate("insert into first (a,b,c,d) values (3,'c',30, date '2007-01-03')");
            stm.executeUpdate("insert into first (a,b,c,d) values (4,'d',40, date '2007-01-04')");
            stm.executeUpdate("insert into second (a,b,c,d) values (1,'e',50, date '2007-02-01')");
            stm.executeUpdate("insert into second (a,b,c,d) values (2,'f',60, date '2007-02-02')");
            stm.executeUpdate("insert into second (a,b,c,d) values (3,'g',70, date '2007-02-03')");
            stm.executeUpdate("insert into second (a,b,c,d) values (4,'h',80, date '2007-02-04')");
            conn.commit();
            RelationMapping mapping = RelationMapping.readFromClasspath("net/ontopia/topicmaps/db2tm/JDBCDataSourceTest-secondary.xml");
            TopicMapStoreIF store = new InMemoryTopicMapStore();
            LocatorIF baseloc = URIUtils.getURILocator("base:foo");
            store.setBaseAddress(baseloc);
            TopicMapIF topicmap = store.getTopicMap();
            Processor.addRelations(mapping, null, topicmap, baseloc);
            exportTopicMap(topicmap, "after-first-sync");
            stm.executeUpdate("insert into second_changes (a,b,c,d,ct,cd) values (2,'f',60,date '2007-02-02', 'r', 2)");
            stm.executeUpdate("delete from second where a = 2");
            conn.commit();
            Processor.synchronizeRelations(mapping, null, topicmap, baseloc);
            exportTopicMap(topicmap, "after-second-sync");
            mapping.close();
            stm.executeUpdate("drop table first");
            stm.executeUpdate("drop table first_changes");
            stm.executeUpdate("drop table second");
            stm.executeUpdate("drop table second_changes");
            stm.close();
            store.close();
            conn.commit();
        } catch (Exception e) {
            conn.rollback();
            throw e;
        } finally {
            conn.close();
        }
    }
public static void copyFile(File src, File dest, int bufSize, boolean force) throws IOException {
        if (dest.exists()) {
            if (force) {
                dest.delete();
            } else {
                throw new IOException(className + "Cannot overwrite existing file: " + dest.getAbsolutePath());
            }
        }
        byte[] buffer = new byte[bufSize];
        int read = 0;
        InputStream in = null;
        OutputStream out = null;
        try {
            in = new FileInputStream(src);
            out = new FileOutputStream(dest);
            while (true) {
                read = in.read(buffer);
                if (read == -1) {
                    break;
                }
                out.write(buffer, 0, read);
            }
        } finally {
            if (in != null) {
                try {
                    in.close();
                } finally {
                    if (out != null) {
                        out.close();
                    }
                }
            }
        }
    }
private void sort() {
        boolean unsortiert = true;
        Datei tmp = null;
        while (unsortiert) {
            unsortiert = false;
            for (int i = 0; i < this.size - 1; i++) {
                if (dateien[i] != null && dateien[i + 1] != null) {
                    if (dateien[i].compareTo(dateien[i + 1]) < 0) {
                        tmp = dateien[i];
                        dateien[i] = dateien[i + 1];
                        dateien[i + 1] = tmp;
                        unsortiert = true;
                    }
                }
            }
        }
    }
public osid.shared.Id ingest(String fileName, String templateFileName, String fileType, File file, Properties properties) throws osid.repository.RepositoryException, java.net.SocketException, java.io.IOException, osid.shared.SharedException, javax.xml.rpc.ServiceException {
        long sTime = System.currentTimeMillis();
        if (DEBUG) System.out.println("INGESTING FILE TO FEDORA:fileName =" + fileName + "fileType =" + fileType + "t = 0");
        String host = FedoraUtils.getFedoraProperty(this, "admin.ftp.address");
        String url = FedoraUtils.getFedoraProperty(this, "admin.ftp.url");
        int port = Integer.parseInt(FedoraUtils.getFedoraProperty(this, "admin.ftp.port"));
        String userName = FedoraUtils.getFedoraProperty(this, "admin.ftp.username");
        String password = FedoraUtils.getFedoraProperty(this, "admin.ftp.password");
        String directory = FedoraUtils.getFedoraProperty(this, "admin.ftp.directory");
        FTPClient client = new FTPClient();
        client.connect(host, port);
        client.login(userName, password);
        client.changeWorkingDirectory(directory);
        client.setFileType(FTP.BINARY_FILE_TYPE);
        client.storeFile(fileName, new FileInputStream(file));
        client.logout();
        client.disconnect();
        if (DEBUG) System.out.println("INGESTING FILE TO FEDORA: Writting to FTP Server:" + (System.currentTimeMillis() - sTime));
        fileName = url + fileName;
        int BUFFER_SIZE = 10240;
        StringBuffer sb = new StringBuffer();
        String s = new String();
        BufferedInputStream fis = new BufferedInputStream(new FileInputStream(new File(getResource(templateFileName).getFile().replaceAll("%20", " "))));
        byte[] buf = new byte[BUFFER_SIZE];
        int ch;
        int len;
        while ((len = fis.read(buf)) > 0) {
            s = s + new String(buf);
        }
        fis.close();
        if (DEBUG) System.out.println("INGESTING FILE TO FEDORA: Read Mets File:" + (System.currentTimeMillis() - sTime));
        String r = updateMetadata(s, fileName, file.getName(), fileType, properties);
        if (DEBUG) System.out.println("INGESTING FILE TO FEDORA: Resplaced Metadata:" + (System.currentTimeMillis() - sTime));
        File METSfile = File.createTempFile("vueMETSMap", ".xml");
        FileOutputStream fos = new FileOutputStream(METSfile);
        fos.write(r.getBytes());
        fos.close();
        AutoIngestor a = new AutoIngestor(address.getHost(), address.getPort(), FedoraUtils.getFedoraProperty(this, "admin.fedora.username"), FedoraUtils.getFedoraProperty(this, "admin.fedora.username"));
        String pid = a.ingestAndCommit(new FileInputStream(METSfile), "Test Ingest");
        if (DEBUG) System.out.println("INGESTING FILE TO FEDORA: Ingest complete:" + (System.currentTimeMillis() - sTime));
        System.out.println(" METSfile= " + METSfile.getPath() + " PID = " + pid);
        return new PID(pid);
    }
public static PipeID getPipeIDForService(ServiceDescriptor descriptor) {
        PipeID id = null;
        URI uri = descriptor.getUri();
        if (uri != null) {
            try {
                id = (PipeID) IDFactory.fromURI(uri);
            } catch (URISyntaxException e) {
                throw new RuntimeException("Error creating id for pipe " + uri, e);
            }
        }
        if (id == null) {
            MessageDigest md = null;
            try {
                md = MessageDigest.getInstance("MD5");
            } catch (NoSuchAlgorithmException e) {
            }
            String idToHash = descriptor.getName();
            if (descriptor.getHost() != null) {
                idToHash += descriptor.getHost();
            }
            md.update(idToHash.getBytes());
            id = IDFactory.newPipeID(InfrastructurePeerGroupID, md.digest());
        }
        return id;
    }
public LocalizationSolver(String name, String serverIP, int portNum, String workDir) {
        this.info = new HashMap<String, Object>();
        this.workDir = workDir;
        try {
            Socket solverSocket = new Socket(serverIP, portNum);
            this.fromServer = new Scanner(solverSocket.getInputStream());
            this.toServer = new PrintWriter(solverSocket.getOutputStream(), true);
            this.toServer.println("login client abc");
            this.toServer.println("solver " + name);
            System.out.println(this.fromServer.nextLine());
        } catch (IOException e) {
            System.err.println(e);
            e.printStackTrace();
            System.exit(1);
        }
        System.out.println("Localization Solver started with name: " + name);
    }
public static String replace(URL url, Replacer replacer) throws Exception {
        URLConnection con = url.openConnection();
        InputStreamReader reader = new InputStreamReader(con.getInputStream());
        StringWriter wr = new StringWriter();
        int c;
        StringBuffer token = null;
        while ((c = reader.read()) != -1) {
            if (c == '@') {
                if (token == null) {
                    token = new StringBuffer();
                } else {
                    String val = replacer.replace(token.toString());
                    if (val != null) {
                        wr.write(val);
                        token = null;
                    } else {
                        wr.write('@');
                        wr.write(token.toString());
                        token.delete(0, token.length());
                    }
                }
            } else {
                if (token == null) {
                    wr.write((char) c);
                } else {
                    token.append((char) c);
                }
            }
        }
        if (token != null) {
            wr.write('@');
            wr.write(token.toString());
        }
        return wr.toString();
    }
public void readContents() throws IOException {
        fireProgressEvent(new ProgressEvent(this, ProgressEvent.PROGRESS_START, 0.0f, "loading file"));
        URLConnection conn = url.openConnection();
        conn.connect();
        filesize = conn.getContentLength();
        logger.finest("filesize: " + filesize);
        InputStreamReader in = new InputStreamReader(conn.getInputStream());
        readFirstLine(in);
        readHeaderLines(in);
        readData(in);
        fireProgressEvent(new ProgressEvent(this, ProgressEvent.PROGRESS_FINISH, 1.0f, "loading file"));
    }
private String listaArquivo() {
        String arquivo = "";
        String linha = "";
        try {
            URL url = new URL(this.getCodeBase(), "./listador?dir=" + "cenarios" + "/" + user);
            URLConnection con = url.openConnection();
            con.setUseCaches(false);
            InputStream in = con.getInputStream();
            DataInputStream result = new DataInputStream(new BufferedInputStream(in));
            while ((linha = result.readLine()) != null) {
                arquivo += linha + "\n";
            }
            return arquivo;
        } catch (Exception e) {
            return null;
        }
    }
public void manageRequest(Transformer transformer) throws ServletException {
        try {
            this.parser.reset();
            String encodedQuery = URLEncoder.encode(this.query, "ISO-8859-1");
            URL url = new URL(EXIST_SERVER + "?_query=" + encodedQuery);
            InputStream in = url.openStream();
            Document doc = this.parser.parse(in);
            Source source = new DOMSource(doc);
            transformer.transform(source, new StreamResult(this.getOut()));
        } catch (TransformerException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (SAXException e) {
            e.printStackTrace();
        }
    }
public void SetRoles(Connection conn, User user, String[] roles) throws NpsException {
        if (!IsSysAdmin() && !IsLocalAdmin()) throw new NpsException(ErrorHelper.ACCESS_NOPRIVILEGE);
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        try {
            String sql = "delete from userrole where userid=?";
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1, user.id);
            pstmt.executeUpdate();
            if (roles != null && roles.length > 0) {
                try {
                    pstmt.close();
                } catch (Exception e1) {
                }
                sql = "insert into userrole(userid,roleid) values(?,?)";
                pstmt = conn.prepareStatement(sql);
                for (int i = 0; i < roles.length; i++) {
                    if (roles[i] != null && roles[i].length() > 0) {
                        pstmt.setString(1, user.GetId());
                        pstmt.setString(2, roles[i]);
                        pstmt.executeUpdate();
                    }
                }
            }
            try {
                pstmt.close();
            } catch (Exception e1) {
            }
            if (user.roles_by_name != null) user.roles_by_name.clear();
            if (user.roles_by_id != null) user.roles_by_id.clear();
            if (roles != null && roles.length > 0) {
                sql = "select b.* from UserRole a,Role b where a.roleid = b.id and a.userid=?";
                pstmt = conn.prepareStatement(sql);
                pstmt.setString(1, user.id);
                rs = pstmt.executeQuery();
                while (rs.next()) {
                    if (user.roles_by_name == null) user.roles_by_name = new Hashtable();
                    if (user.roles_by_id == null) user.roles_by_id = new Hashtable();
                    user.roles_by_name.put(rs.getString("name"), rs.getString("id"));
                    user.roles_by_id.put(rs.getString("id"), rs.getString("name"));
                }
            }
        } catch (Exception e) {
            try {
                conn.rollback();
            } catch (Exception e1) {
            }
            com.microfly.util.DefaultLog.error(e);
        } finally {
            if (rs != null) try {
                rs.close();
            } catch (Exception e) {
            }
            if (pstmt != null) try {
                pstmt.close();
            } catch (Exception e1) {
            }
        }
    }
public void writeToFtp(String login, String password, String address, String directory, String filename) {
        String newline = System.getProperty("line.separator");
        try {
            URL url = new URL("ftp://" + login + ":" + password + "@ftp." + address + directory + filename + ".html" + ";type=i");
            URLConnection urlConn = url.openConnection();
            urlConn.setDoOutput(true);
            OutputStreamWriter stream = new OutputStreamWriter(urlConn.getOutputStream());
            stream.write("<html><title>" + title + "</title>" + newline);
            stream.write("<h1><b>" + title + "</b></h1>" + newline);
            stream.write("<h2>Table Of Contents:</h2><ul>" + newline);
            for (int k = 0; k < rings.size(); k++) {
                stream.write("<li><i><a href=\"#");
                stream.write(readNoteTitle(k));
                stream.write("\">");
                stream.write(readNoteTitle(k));
                stream.write("</a></i></li>" + newline);
            }
            stream.write("</ul><hr>" + newline + newline);
            for (int k = 0; k < rings.size(); k++) {
                stream.write("<h3><b>");
                stream.write("<a name=\"");
                stream.write(readNoteTitle(k));
                stream.write("\">");
                stream.write(readNoteTitle(k) + "</a>");
                stream.write("</b></h3>" + newline);
                stream.write(readNoteBody(k) + newline);
            }
            stream.write(newline + "<br><hr><a>This was created using Scribe, a free crutch editor.</a></html>");
            stream.close();
        } catch (IOException error) {
            System.out.println("There was an error: " + error);
        }
    }
private void copyFile(File src_file, File dest_file) {
        InputStream src_stream = null;
        OutputStream dest_stream = null;
        try {
            int b;
            src_stream = new BufferedInputStream(new FileInputStream(src_file));
            dest_stream = new BufferedOutputStream(new FileOutputStream(dest_file));
            while ((b = src_stream.read()) != -1) dest_stream.write(b);
        } catch (Exception e) {
            XRepository.getLogger().warning(this, "Error on copying the plugin file!");
            XRepository.getLogger().warning(this, e);
        } finally {
            try {
                src_stream.close();
                dest_stream.close();
            } catch (Exception ex2) {
            }
        }
    }