semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public String getTextData() {
        if (tempFileWriter != null) {
            try {
                tempFileWriter.flush();
                tempFileWriter.close();
                FileReader in = new FileReader(tempFile);
                StringWriter out = new StringWriter();
                int len;
                char[] buf = new char[BUFSIZ];
                while ((len = in.read(buf)) > 0) out.write(buf, 0, len);
                out.close();
                in.close();
                return out.toString();
            } catch (IOException ioe) {
                Logger.instance().log(Logger.ERROR, LOGGER_PREFIX, "XMLTextData.getTextData", ioe);
                return "";
            }
        } else if (textBuffer != null) return textBuffer.toString(); else return null;
    }
private void unzipResource(final String resourceName, final File targetDirectory) throws IOException {
        final URL resource = this.getClass().getResource(resourceName);
        assertNotNull("Expected '" + resourceName + "' not found.", resource);
        assertTrue(targetDirectory.isAbsolute());
        FileUtils.deleteDirectory(targetDirectory);
        assertTrue(targetDirectory.mkdirs());
        ZipInputStream in = null;
        boolean suppressExceptionOnClose = true;
        try {
            in = new ZipInputStream(resource.openStream());
            ZipEntry e;
            while ((e = in.getNextEntry()) != null) {
                if (e.isDirectory()) {
                    continue;
                }
                final File dest = new File(targetDirectory, e.getName());
                assertTrue(dest.isAbsolute());
                OutputStream out = null;
                try {
                    out = FileUtils.openOutputStream(dest);
                    IOUtils.copy(in, out);
                    suppressExceptionOnClose = false;
                } finally {
                    try {
                        if (out != null) {
                            out.close();
                        }
                        suppressExceptionOnClose = true;
                    } catch (final IOException ex) {
                        if (!suppressExceptionOnClose) {
                            throw ex;
                        }
                    }
                }
                in.closeEntry();
            }
            suppressExceptionOnClose = false;
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
            } catch (final IOException e) {
                if (!suppressExceptionOnClose) {
                    throw e;
                }
            }
        }
    }
public static void copyFile(File file, String destDir) throws IOException {
        if (!isCanReadFile(file)) throw new RuntimeException("The File can't read:" + file.getPath());
        if (!isCanWriteDirectory(destDir)) throw new RuntimeException("The Directory can't write:" + destDir);
        FileChannel srcChannel = null;
        FileChannel dstChannel = null;
        try {
            srcChannel = new FileInputStream(file).getChannel();
            dstChannel = new FileOutputStream(destDir + "/" + file.getName()).getChannel();
            dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
        } catch (IOException e) {
            throw e;
        } finally {
            if (srcChannel != null) try {
                srcChannel.close();
            } catch (IOException e) {
            }
            if (dstChannel != null) try {
                dstChannel.close();
            } catch (IOException e) {
            }
        }
    }
private void sendFile(File file, HttpExchange response) throws IOException {
        response.getResponseHeaders().add(FileUploadBase.CONTENT_LENGTH, Long.toString(file.length()));
        InputStream inputStream = null;
        try {
            inputStream = new FileInputStream(file);
            IOUtils.copy(inputStream, response.getResponseBody());
        } catch (Exception exception) {
            throw new IOException("error sending file", exception);
        } finally {
            IOUtils.closeQuietly(inputStream);
        }
    }
public void savaUserPerm(String userid, Collection user_perm_collect) throws DAOException, SQLException {
        ConnectionProvider cp = null;
        Connection conn = null;
        ResultSet rs = null;
        PreparedStatement pstmt = null;
        PrivilegeFactory factory = PrivilegeFactory.getInstance();
        Operation op = factory.createOperation();
        try {
            cp = ConnectionProviderFactory.getConnectionProvider(Constants.DATA_SOURCE);
            conn = cp.getConnection();
            pstmt = conn.prepareStatement(DEL_USER_PERM);
            pstmt.setString(1, userid);
            pstmt.executeUpdate();
            if ((user_perm_collect == null) || (user_perm_collect.size() <= 0)) {
                return;
            } else {
                conn.setAutoCommit(false);
                pstmt = conn.prepareStatement(ADD_USER_PERM);
                Iterator user_perm_ir = user_perm_collect.iterator();
                while (user_perm_ir.hasNext()) {
                    UserPermission userPerm = (UserPermission) user_perm_ir.next();
                    pstmt.setString(1, String.valueOf(userPerm.getUser_id()));
                    pstmt.setString(2, String.valueOf(userPerm.getResource_id()));
                    pstmt.setString(3, String.valueOf(userPerm.getResop_id()));
                    pstmt.executeUpdate();
                }
                conn.commit();
                conn.setAutoCommit(true);
            }
        } catch (Exception e) {
            e.printStackTrace();
            conn.rollback();
            throw new DAOException();
        } finally {
            try {
                if (conn != null) {
                    conn.close();
                }
                if (pstmt != null) {
                    pstmt.close();
                }
            } catch (Exception e) {
            }
        }
    }
public void savaRolePerm(String roleid, Collection role_perm_collect) throws DAOException, SQLException {
        ConnectionProvider cp = null;
        Connection conn = null;
        ResultSet rs = null;
        PreparedStatement pstmt = null;
        PrivilegeFactory factory = PrivilegeFactory.getInstance();
        Operation op = factory.createOperation();
        try {
            cp = ConnectionProviderFactory.getConnectionProvider(Constants.DATA_SOURCE);
            conn = cp.getConnection();
            try {
                pstmt = conn.prepareStatement(DEL_ROLE_PERM);
                pstmt.setString(1, roleid);
                pstmt.executeUpdate();
            } catch (Exception e) {
            }
            if ((role_perm_collect == null) || (role_perm_collect.size() == 0)) {
                return;
            } else {
                conn.setAutoCommit(false);
                pstmt = conn.prepareStatement(ADD_ROLE_PERM);
                Iterator role_perm_ir = role_perm_collect.iterator();
                while (role_perm_ir.hasNext()) {
                    RolePermission rolePerm = (RolePermission) role_perm_ir.next();
                    pstmt.setString(1, String.valueOf(rolePerm.getRoleid()));
                    pstmt.setString(2, String.valueOf(rolePerm.getResourceid()));
                    pstmt.setString(3, String.valueOf(rolePerm.getResopid()));
                    pstmt.executeUpdate();
                }
                conn.commit();
                conn.setAutoCommit(true);
            }
        } catch (Exception e) {
            conn.rollback();
            throw new DAOException();
        } finally {
            try {
                if (conn != null) {
                    conn.close();
                }
                if (pstmt != null) {
                    pstmt.close();
                }
            } catch (Exception e) {
            }
        }
    }
public Map<? extends ClassLoader, Set<String>> getClassNamesByClassLoader() throws IOException {
        final Map<? extends ClassLoader, Set<URL>> urlsByClassLoader = getClassNameListURLsByClassLoader();
        final LinkedHashMap<ClassLoader, Set<String>> map = new LinkedHashMap<ClassLoader, Set<String>>(urlsByClassLoader.size());
        final HashSet<String> allNames = new HashSet<String>(map.size());
        for (final Map.Entry<? extends ClassLoader, Set<URL>> e : urlsByClassLoader.entrySet()) {
            LinkedHashSet<String> names = null;
            for (final URL url : e.getValue()) {
                InputStream bin = null;
                try {
                    bin = url.openStream();
                    final LineNumberReader in = new LineNumberReader(new InputStreamReader(bin));
                    for (String line; (line = in.readLine()) != null; ) {
                        line = line.trim();
                        if ((line.length() > 0) && (line.charAt(0) != '#') && allNames.add(line) && acceptClassName(e.getKey(), url, line)) {
                            if (names == null) names = new LinkedHashSet<String>(e.getValue().size());
                            names.add(line);
                        }
                    }
                    in.close();
                    bin = null;
                } catch (IOException ex) {
                    handleIOException(e.getKey(), url, ex);
                } finally {
                    if (bin != null) {
                        try {
                            bin.close();
                        } catch (IOException ex) {
                        }
                    }
                }
            }
            if (names != null) map.put(e.getKey(), names);
        }
        return map;
    }
private FTPClient connect() throws FTPException {
        try {
            FTPClient ftp = new FTPClient();
            ftp.connect(host, port);
            int reply = ftp.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                ftp.disconnect();
                System.err.println("FTP server refused connection.");
            }
            ftp.login(userName, password);
            ftp.setFileType(FTP.BINARY_FILE_TYPE);
            return ftp;
        } catch (SocketException e) {
            throw new FTPException("Failed to connect to server", e);
        } catch (IOException e) {
            throw new FTPException("Failed to connect to server", e);
        }
    }
private int create() throws SQLException {
        Connection conn = null;
        Statement st = null;
        ResultSet rs = null;
        String query = null;
        try {
            conn = dataSource.getConnection();
            st = conn.createStatement();
            query = "insert into " + DB.Tbl.users + "(" + col.name + "," + col.login + "," + col.pass + "," + col.passHash + "," + col.email + "," + col.role + "," + col.addDate + ") values('" + name + "','" + login + "','" + pass + "','" + pass.hashCode() + "','" + email + "'," + role + ",now())";
            st.executeUpdate(query, new String[] { col.id });
            rs = st.getGeneratedKeys();
            while (rs.next()) {
                int genId = rs.getInt(1);
                conn.commit();
                return genId;
            }
            throw new SQLException("Не удается получить generatedKey при создании пользователя.");
        } catch (SQLException e) {
            try {
                conn.rollback();
            } catch (Exception e1) {
            }
            throw e;
        } finally {
            try {
                rs.close();
            } catch (Exception e) {
            }
            try {
                st.close();
            } catch (Exception e) {
            }
            try {
                conn.close();
            } catch (Exception e) {
            }
        }
    }
private String getHash(String string) {
        Monitor hashTime = JamonMonitorLogger.getTimeMonitor(Cache.class, "HashTime").start();
        MessageDigest md5 = null;
        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        md5.reset();
        md5.update(string.getBytes());
        byte[] result = md5.digest();
        StringBuffer hexString = new StringBuffer();
        for (int i = 0; i < result.length; i++) {
            hexString.append(Integer.toHexString(0xFF & result[i]));
        }
        String str = hexString.toString();
        hashTime.stop();
        return str;
    }
public static void main(String[] args) {
        try {
            FTPClient p = new FTPClient();
            p.connect("url");
            p.login("login", "pass");
            int sendCommand = p.sendCommand("SYST");
            System.out.println("TryMe.main() - " + sendCommand + " (sendCommand)");
            sendCommand = p.sendCommand("PWD");
            System.out.println("TryMe.main() - " + sendCommand + " (sendCommand)");
            sendCommand = p.sendCommand("NOOP");
            System.out.println("TryMe.main() - " + sendCommand + " (sendCommand)");
            sendCommand = p.sendCommand("PASV");
            System.out.println("TryMe.main() - " + sendCommand + " (sendCommand)");
            p.changeWorkingDirectory("/");
            try {
                printDir(p, "/");
            } catch (Exception e) {
                e.printStackTrace();
            }
            p.logout();
            p.disconnect();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
public HttpResponse executeHttpGetRequest(String uri, Map<String, Object> parameters) throws HttpTestClientException {
        HttpGet httpGet = new HttpGet(uri);
        if (parameters != null) {
            httpGet.setParams(createBasicParameters(parameters));
        }
        return executeHttp(httpGet);
    }
public void deleteProposal(String id) throws Exception {
        String tmp = "";
        PreparedStatement prepStmt = null;
        try {
            if (id == null || id.length() == 0) throw new Exception("Invalid parameter");
            con = database.getConnection();
            String delProposal = "delete from proposal where PROPOSAL_ID='" + id + "'";
            prepStmt = con.prepareStatement(delProposal);
            prepStmt.executeUpdate();
            con.commit();
            prepStmt.close();
            con.close();
        } catch (Exception e) {
            if (!con.isClosed()) {
                con.rollback();
                prepStmt.close();
                con.close();
            }
            throw e;
        }
    }
public void deleteType(String id) throws Exception {
        String tmp = "";
        PreparedStatement prepStmt = null;
        try {
            if (id == null || id.length() == 0) throw new Exception("Invalid parameter");
            con = database.getConnection();
            String delType = "delete from type where TYPE_ID='" + id + "'";
            con.setAutoCommit(false);
            prepStmt = con.prepareStatement("delete from correlation where TYPE_ID='" + id + "' OR CORRELATEDTYPE_ID='" + id + "'");
            prepStmt.executeUpdate();
            prepStmt = con.prepareStatement("delete from composition where TYPE_ID='" + id + "'");
            prepStmt.executeUpdate();
            prepStmt = con.prepareStatement("delete from distribution where TYPE_ID='" + id + "'");
            prepStmt.executeUpdate();
            prepStmt = con.prepareStatement("delete from typename where TYPE_ID='" + id + "'");
            prepStmt.executeUpdate();
            prepStmt = con.prepareStatement("delete from typereference where TYPE_ID='" + id + "'");
            prepStmt.executeUpdate();
            prepStmt = con.prepareStatement("delete from plot where TYPE_ID='" + id + "'");
            prepStmt.executeUpdate();
            prepStmt = con.prepareStatement(delType);
            prepStmt.executeUpdate();
            con.commit();
            prepStmt.close();
            con.close();
        } catch (Exception e) {
            if (!con.isClosed()) {
                con.rollback();
                prepStmt.close();
                con.close();
            }
            throw e;
        }
    }
public void deleteSingle(String tbName, String idFld, String id) throws Exception {
        String tmp = "";
        PreparedStatement prepStmt = null;
        try {
            if (tbName == null || tbName.length() == 0 || id == null || id.length() == 0) throw new Exception("Invalid parameter");
            con = database.getConnection();
            String delSQL = "delete from " + tbName + " where " + idFld + "='" + id + "'";
            con.setAutoCommit(false);
            prepStmt = con.prepareStatement(delSQL);
            prepStmt.executeUpdate();
            con.commit();
            prepStmt.close();
            con.close();
        } catch (Exception e) {
            if (!con.isClosed()) {
                con.rollback();
                prepStmt.close();
                con.close();
            }
            throw e;
        }
    }
public void assign() throws Exception {
        if (proposalIds.equals("") || usrIds.equals("")) throw new Exception("No proposal or peer-viewer selected.");
        String[] pids = proposalIds.split(",");
        String[] uids = usrIds.split(",");
        int pnum = pids.length;
        int unum = uids.length;
        if (pnum == 0 || unum == 0) throw new Exception("No proposal or peer-viewer selected.");
        int i, j;
        String pStr = "update proposal set current_status='assigned' where ";
        for (i = 0; i < pnum; i++) {
            if (i > 0) pStr += " OR ";
            pStr += "PROPOSAL_ID=" + pids[i];
        }
        Calendar date = Calendar.getInstance();
        int day = date.get(Calendar.DATE);
        int month = date.get(Calendar.MONTH);
        int year = date.get(Calendar.YEAR);
        String dt = String.valueOf(year) + "-" + String.valueOf(month + 1) + "-" + String.valueOf(day);
        PreparedStatement prepStmt = null;
        try {
            con = database.getConnection();
            con.setAutoCommit(false);
            prepStmt = con.prepareStatement(pStr);
            prepStmt.executeUpdate();
            pStr = "insert into event (summary,document1,document2,document3,publicComments,privateComments,ACTION_ID,eventDate,ROLE_ID,reviewText,USR_ID,PROPOSAL_ID,SUBJECTUSR_ID) values " + "('','','','','','','assigned','" + dt + "',2,'new'," + userId + ",?,?)";
            prepStmt = con.prepareStatement(pStr);
            for (i = 0; i < pnum; i++) {
                for (j = 0; j < unum; j++) {
                    prepStmt.setString(1, pids[i]);
                    prepStmt.setString(2, uids[j]);
                    prepStmt.executeUpdate();
                }
            }
            con.commit();
        } catch (Exception e) {
            if (!con.isClosed()) {
                con.rollback();
                prepStmt.close();
                con.close();
            }
            throw e;
        }
        event_Form fr = new event_Form();
        for (j = 0; j < unum; j++) {
            fr.setUSR_ID(userId);
            fr.setSUBJECTUSR_ID(uids[j]);
            systemManager.handleEvent(SystemManager.EVENT_PROPOSAL_ASSIGNED, fr, null, null);
        }
    }
public void addAuthors() throws Exception {
        if (proposalIds.equals("") || usrIds.equals("")) throw new Exception("No proposal or author selected.");
        String[] pids = proposalIds.split(",");
        String[] uids = usrIds.split(",");
        int pnum = pids.length;
        int unum = uids.length;
        if (pnum == 0 || unum == 0) throw new Exception("No proposal or author selected.");
        int i, j;
        Calendar date = Calendar.getInstance();
        int day = date.get(Calendar.DATE);
        int month = date.get(Calendar.MONTH);
        int year = date.get(Calendar.YEAR);
        String dt = String.valueOf(year) + "-" + String.valueOf(month + 1) + "-" + String.valueOf(day);
        String pStr = "";
        PreparedStatement prepStmt = null;
        try {
            con = database.getConnection();
            con.setAutoCommit(false);
            pStr = "insert into event (summary,document1,document2,document3,publicComments,privateComments,ACTION_ID,eventDate,ROLE_ID,reviewText,USR_ID,PROPOSAL_ID,SUBJECTUSR_ID) values " + "('','','','','','','member added','" + dt + "',2,'add member'," + userId + ",?,?)";
            prepStmt = con.prepareStatement(pStr);
            for (i = 0; i < pnum; i++) {
                for (j = 0; j < unum; j++) {
                    if (!uids[j].equals(userId)) {
                        prepStmt.setString(1, pids[i]);
                        prepStmt.setString(2, uids[j]);
                        prepStmt.executeUpdate();
                    }
                }
            }
            con.commit();
        } catch (Exception e) {
            if (!con.isClosed()) {
                con.rollback();
                prepStmt.close();
                con.close();
            }
            throw new Exception(e.getMessage() + "\n" + pStr + "\npnum=" + pnum + "\n" + pids[0] + "\nunum=" + unum + "\n" + uids[1] + uids[0]);
        }
    }
public void deleteAuthors() throws Exception {
        if (proposalIds.equals("") || usrIds.equals("")) throw new Exception("No proposal or author selected.");
        String[] pids = proposalIds.split(",");
        String[] uids = usrIds.split(",");
        int pnum = pids.length;
        int unum = uids.length;
        if (pnum == 0 || unum == 0) throw new Exception("No proposal or author selected.");
        int i, j;
        PreparedStatement prepStmt = null;
        try {
            con = database.getConnection();
            con.setAutoCommit(false);
            String pStr = "delete from event where ACTION_ID='member added' AND PROPOSAL_ID=? AND SUBJECTUSR_ID=?";
            prepStmt = con.prepareStatement(pStr);
            for (i = 0; i < pnum; i++) {
                for (j = 0; j < unum; j++) {
                    if (!uids[j].equals(userId)) {
                        prepStmt.setString(1, pids[i]);
                        prepStmt.setString(2, uids[j]);
                        prepStmt.executeUpdate();
                    }
                }
            }
            con.commit();
        } catch (Exception e) {
            if (!con.isClosed()) {
                con.rollback();
                prepStmt.close();
                con.close();
            }
            throw e;
        }
    }