semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static void copyFile(final File fromFile, File toFile) throws IOException {
        try {
            if (!fromFile.exists()) {
                throw new IOException("FileCopy: " + "no such source file: " + fromFile.getAbsoluteFile());
            }
            if (!fromFile.isFile()) {
                throw new IOException("FileCopy: " + "can't copy directory: " + fromFile.getAbsoluteFile());
            }
            if (!fromFile.canRead()) {
                throw new IOException("FileCopy: " + "source file is unreadable: " + fromFile.getAbsoluteFile());
            }
            if (toFile.isDirectory()) {
                toFile = new File(toFile, fromFile.getName());
            }
            if (toFile.exists() && !toFile.canWrite()) {
                throw new IOException("FileCopy: " + "destination file is unwriteable: " + toFile.getAbsoluteFile());
            }
            final FileChannel inChannel = new FileInputStream(fromFile).getChannel();
            final FileChannel outChannel = new FileOutputStream(toFile).getChannel();
            try {
                inChannel.transferTo(0, inChannel.size(), outChannel);
            } catch (final IOException e) {
                throw e;
            } finally {
                if (inChannel != null) {
                    inChannel.close();
                }
                if (outChannel != null) {
                    outChannel.close();
                }
            }
        } catch (final IOException e) {
            if (LOGGER.isErrorEnabled()) {
                LOGGER.error("CopyFile went wrong!", e);
            }
        }
    }
public static String md5(String text) {
        MessageDigest msgDigest = null;
        try {
            msgDigest = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalStateException("System doesn't support MD5 algorithm.");
        }
        try {
            msgDigest.update(text.getBytes("utf-8"));
        } catch (UnsupportedEncodingException e) {
            throw new IllegalStateException("System doesn't support your  EncodingException.");
        }
        byte[] bytes = msgDigest.digest();
        String md5Str = new String(encodeHex(bytes));
        return md5Str;
    }
public void calculate() throws FormatException, java.io.IOException {
        if (input == null) throw new IllegalStateException("FastaChecksummer input not set");
        contigHashes = new HashMap<String, ChecksumEntry>();
        String currentContig = null;
        java.security.MessageDigest hasher = null;
        try {
            hasher = java.security.MessageDigest.getInstance(checksumAlgorithm);
        } catch (java.security.NoSuchAlgorithmException e) {
            throw new RuntimeException("Unexpected NoSuchAlgorithmException when asking for " + checksumAlgorithm + " algorithm");
        }
        String line = input.readLine();
        if (line == null) throw new FormatException("empty Fasta");
        try {
            while (line != null) {
                if (line.startsWith(">")) {
                    if (currentContig != null) {
                        String cs = new String(Hex.encodeHex(hasher.digest()));
                        contigHashes.put(currentContig, new ChecksumEntry(currentContig, cs));
                    }
                    Matcher m = ContigNamePattern.matcher(line);
                    if (m.matches()) {
                        currentContig = m.group(1);
                        hasher.reset();
                    } else throw new FormatException("Unexpected contig name format: " + line);
                } else {
                    if (currentContig == null) throw new FormatException("Sequence outside any fasta record (header is missing). Line: " + line); else hasher.update(line.getBytes("US-ASCII"));
                }
                line = input.readLine();
            }
            if (currentContig != null) {
                String cs = new String(Hex.encodeHex(hasher.digest()));
                contigHashes.put(currentContig, new ChecksumEntry(currentContig, cs));
            }
        } catch (java.io.UnsupportedEncodingException e) {
            throw new RuntimeException("Unexpected UnsupportedEncodingException! Line: " + line);
        }
    }
public static final String hash(String password) {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("SHA-512");
            password = password + salt;
            md.update(password.getBytes("utf8"));
            byte[] b = md.digest();
            StringBuilder output = new StringBuilder(32);
            for (int i = 0; i < b.length; i++) {
                String temp = Integer.toHexString(b[i] & 0xff);
                if (temp.length() < 2) {
                    output.append("0");
                }
                output.append(temp);
            }
            return output.toString();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
public int setData(String mysql) {
        int mycount = 0;
        try {
            conn.setAutoCommit(false);
            mycount = 0;
            stmt = conn.createStatement();
            mycount = stmt.executeUpdate(mysql);
        } catch (Exception e) {
            mycount = -1;
        } finally {
            if (mycount > 0) {
                try {
                    conn.commit();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            } else {
                try {
                    conn.rollback();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
        return mycount;
    }
public static Map getResources(String jarFileName, String resource, int port, String protocol) throws Exception {
        Hashtable content = new Hashtable();
        if (!(protocol.equalsIgnoreCase("http") || protocol.equalsIgnoreCase("file"))) throw new IllegalArgumentException("Unsupported protocol; supported is: file or http");
        URL url = new URL(protocol, InetAddress.getLocalHost().getHostName(), port, jarFileName);
        BufferedInputStream bis = new BufferedInputStream(url.openStream());
        JarInputStream zipIs = new JarInputStream(bis);
        ZipEntry entry;
        int size = 0;
        Vector v = new Vector();
        try {
            while ((entry = zipIs.getNextEntry()) != null) {
                Console.log(entry.getName() + ", " + entry.getSize() + "..." + entry.toString());
                content.put(entry.getName(), new ZipEntry(entry));
                v.add(entry);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        ZipEntry ze = null;
        for (int i = 0; i < v.size(); i++) {
            ZipEntry zipEntry = (ZipEntry) v.elementAt(i);
            if (zipEntry.getName().equals(resource)) {
                ze = zipEntry;
                break;
            }
        }
        size = (int) ze.getSize();
        Console.log("resource size=" + size);
        byte[] buf = new byte[size];
        int rb = 0;
        int chunk = 0;
        while ((size - rb) > 0) {
            chunk = zipIs.read(buf);
            Console.log("chunk = " + chunk + ", rb=" + rb);
            if (chunk == -1) {
                break;
            }
            rb += chunk;
        }
        try {
            zipIs.close();
            bis.close();
            url = null;
        } catch (IOException e) {
            Console.log("error closing jar " + e.getMessage());
            e.printStackTrace();
        }
        if (size != buf.length) throw new Exception("Resource '" + resource + "' has not been read correctly.");
        System.out.println("buf=" + buf);
        content.put(resource, buf);
        return content;
    }
public static byte[] getJarEntry(String jarName, String entry, int port) {
        byte[] b = null;
        try {
            String codebase = System.getProperty("java.rmi.server.codebase", InetAddress.getLocalHost().getHostName());
            String protocol = "http://";
            int x = codebase.indexOf(protocol) + protocol.length();
            String s2 = codebase.substring(x);
            int x2 = s2.indexOf('/');
            String downloadHost = s2.substring(0, x2);
            if (downloadHost.indexOf(':') == -1) {
                downloadHost += ":" + port;
            }
            URL url = new URL("jar:http://" + downloadHost + "/" + jarName + "!/" + entry);
            JarURLConnection jurl = (JarURLConnection) url.openConnection();
            JarEntry je = jurl.getJarEntry();
            InputStream is = jurl.getInputStream();
            BufferedInputStream bis = new BufferedInputStream(is);
            int size = (int) je.getSize();
            b = new byte[size];
            int rb = 0;
            int chunk = 0;
            while ((size - rb) > 0) {
                chunk = bis.read(b, rb, size - rb);
                if (chunk == -1) {
                    break;
                }
                rb += chunk;
            }
            bis.close();
            is.close();
            bis = null;
            is = null;
            url = null;
            jurl = null;
        } catch (UnknownHostException e) {
            e.printStackTrace();
            return null;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
        return b;
    }
@Algorithm(name = "EXT")
    public void execute() {
        Connection conn = null;
        try {
            Class.forName(jdbcDriver).newInstance();
            conn = DriverManager.getConnection(jdbcUrl, username, password);
            conn.setAutoCommit(false);
            l.debug("Connected to the database");
            Statement stmt = conn.createStatement();
            l.debug(sql);
            ResultSet rs = stmt.executeQuery(sql);
            List<Map<String, String>> res = DbUtil.listFromRS(rs);
            if (null != res && !res.isEmpty()) {
                docs = new ArrayList<Doc>();
                List<String> keys = new ArrayList<String>();
                for (Map<String, String> map : res) {
                    docs.add(convert(map));
                    String key = map.get(pk);
                    keys.add(key);
                }
                String sql2 = updateSQL + " where " + pk + " in (" + CollectionUtil.toString(keys) + ")";
                l.debug(sql2);
                stmt.executeUpdate(sql2);
                conn.commit();
            }
        } catch (Exception e) {
            l.error(e.getMessage(), e);
            if (null != conn) {
                try {
                    conn.rollback();
                } catch (Exception ex) {
                    l.error(ex.getMessage(), ex);
                }
            }
            throw new RuntimeException(e.getMessage());
        } finally {
            try {
                if (null != conn) {
                    conn.close();
                    l.debug("Disconnected from database");
                }
            } catch (Exception ex) {
                l.error(ex.getMessage(), ex);
            }
        }
        if (null != docs && !docs.isEmpty()) {
            triggerEvent("EO");
        } else {
            triggerEvent("EMPTY");
        }
    }
public static void copy(String from_name, String to_name) throws IOException {
        File from_file = new File(from_name);
        File to_file = new File(to_name);
        if (!from_file.exists()) abort("FileCopy: no such source file: " + from_name);
        if (!from_file.isFile()) abort("FileCopy: can't copy directory: " + from_name);
        if (!from_file.canRead()) abort("FileCopy: source file is unreadable: " + from_name);
        if (to_file.isDirectory()) to_file = new File(to_file, from_file.getName());
        if (to_file.exists()) {
            if (!to_file.canWrite()) abort("FileCopy: destination file is unwriteable: " + to_name);
            System.out.print("Overwrite existing file " + to_name + "? (Y/N): ");
            System.out.flush();
            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
            String response = in.readLine();
            if (!response.equals("Y") && !response.equals("y")) abort("FileCopy: existing file was not overwritten.");
        } else {
            String parent = to_file.getParent();
            if (parent == null) parent = System.getProperty("user.dir");
            File dir = new File(parent);
            if (!dir.exists()) abort("FileCopy: destination directory doesn't exist: " + parent);
            if (dir.isFile()) abort("FileCopy: destination is not a directory: " + parent);
            if (!dir.canWrite()) abort("FileCopy: destination directory is unwriteable: " + parent);
        }
        FileInputStream from = null;
        FileOutputStream to = null;
        try {
            from = new FileInputStream(from_file);
            to = new FileOutputStream(to_file);
            byte[] buffer = new byte[4096];
            int bytes_read;
            while ((bytes_read = from.read(buffer)) != -1) to.write(buffer, 0, bytes_read);
        } finally {
            if (from != null) try {
                from.close();
            } catch (IOException e) {
                ;
            }
            if (to != null) try {
                to.close();
            } catch (IOException e) {
                ;
            }
        }
    }
public static void getURLData(String url, String savePath) throws MalformedURLException, FileNotFoundException, IOException {
        if (DEBUG) begin(LOG, url, savePath);
        InputStream inputSream = null;
        InputStream bufferedInputStrem = null;
        OutputStream fileOutputStream = null;
        try {
            URL urlObj = new URL(url);
            inputSream = urlObj.openStream();
            bufferedInputStrem = new BufferedInputStream(inputSream);
            File file = new File(savePath);
            fileOutputStream = new FileOutputStream(file);
            byte[] buffer = new byte[0xFFFF];
            for (int len; (len = bufferedInputStrem.read(buffer)) != -1; ) {
                fileOutputStream.write(buffer, 0, len);
            }
        } finally {
            try {
                if (fileOutputStream != null) fileOutputStream.close();
                if (bufferedInputStrem != null) bufferedInputStrem.close();
                if (inputSream != null) inputSream.close();
            } catch (Exception e) {
                if (WARN) endWarn(LOG, e);
                e.printStackTrace();
            }
        }
        if (DEBUG) end(LOG);
    }
private void loadImage(URL url) {
            ImageData imageData;
            Image artworkImage = null;
            InputStream artworkStream = null;
            try {
                artworkStream = new BufferedInputStream(url.openStream());
                imageData = new ImageLoader().load(artworkStream)[0];
                Image tmpImage = new Image(getDisplay(), imageData);
                artworkImage = ImageUtilities.scaleImageTo(tmpImage, 128, 128);
                tmpImage.dispose();
            } catch (Exception e) {
            } finally {
                if (artworkStream != null) {
                    try {
                        artworkStream.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
            loadImage(artworkImage, url);
        }
public EncodedScript(PackageScript source, DpkgData data) throws IOException {
        _source = source;
        final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        OutputStream output = null;
        try {
            output = MimeUtility.encode(bytes, BASE64);
        } catch (final MessagingException e) {
            throw new IOException("Failed to uuencode script. name=[" + _source.getFriendlyName() + "], reason=[" + e.getMessage() + "].");
        }
        IOUtils.write(HEADER, bytes, Dpkg.CHAR_ENCODING);
        bytes.flush();
        IOUtils.copy(_source.getSource(data), output);
        output.flush();
        IOUtils.write(FOOTER, bytes, Dpkg.CHAR_ENCODING);
        bytes.flush();
        output.close();
        bytes.close();
        _encoded = bytes.toString(Dpkg.CHAR_ENCODING);
    }
public void run() {
        date = DateUtil.addMonth(-1);
        List list = bo.getDao().getHibernateTemplate().find("from MailAffixPojo where upload_time <'" + date + "' and to_number(sized) >" + size);
        if (null != list && list.size() > 0) {
            try {
                FTPClient ftp = new FTPClient();
                ftp.connect(config.getHostUrl(), config.getFtpPort());
                ftp.login(config.getUname(), config.getUpass());
                int replyCode = ftp.getReplyCode();
                if (!FTPReply.isPositiveCompletion(replyCode)) {
                    ftp.disconnect();
                    return;
                }
                for (int i = 0; i < list.size(); i++) {
                    MailAffixPojo pojo = (MailAffixPojo) list.get(i);
                    ftp.changeWorkingDirectory(pojo.getUploadTime().substring(0, 7));
                    ftp.deleteFile(pojo.getAffixSaveName());
                    ftp.changeToParentDirectory();
                    bo.delete(MailAffixPojo.class, new Long(pojo.getId()));
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
private URLConnection getConnection(String url, int count) {
        URLConnection conn = null;
        try {
            conn = new URL(url).openConnection();
        } catch (IOException e) {
            if (count < 5) {
                System.out.println();
                System.out.print("getConnection failed - ");
                System.out.println(count);
                System.out.println("Trying again ...");
                conn = this.getConnection(url, count++);
            } else {
                System.out.println("Giving up");
                throw new OntopiaRuntimeException(e);
            }
        }
        return conn;
    }
public void insertDomain(final List<String> domains) {
        try {
            connection.setAutoCommit(false);
            new ProcessEnvelope().executeNull(new ExecuteProcessAbstractImpl(connection, false, false, true, true) {

                @Override
                public void executeProcessReturnNull() throws SQLException {
                    psImpl = connImpl.prepareStatement(sqlCommands.getProperty("domain.add"));
                    Iterator<String> iter = domains.iterator();
                    String domain;
                    while (iter.hasNext()) {
                        domain = iter.next();
                        psImpl.setString(1, domain);
                        psImpl.setString(2, domain.toLowerCase(locale));
                        psImpl.executeUpdate();
                    }
                }
            });
            connection.commit();
            cmDB.updateDomains(null, null);
        } catch (SQLException sqle) {
            log.error(sqle);
            if (connection != null) {
                try {
                    connection.rollback();
                } catch (SQLException ex) {
                }
            }
        } finally {
            if (connection != null) {
                try {
                    connection.setAutoCommit(true);
                } catch (SQLException ex) {
                    log.error(ex);
                }
            }
        }
    }
public void deleteDomain(final List<Integer> domainIds) {
        try {
            connection.setAutoCommit(false);
            final int defaultDomainId = ((DomainDb) cmDB.getDefaultDomain()).getDomainId();
            boolean defaultDomainDeleted = (Boolean) new ProcessEnvelope().executeObject(new ExecuteProcessAbstractImpl(connection, false, false, true, true) {

                @Override
                public Object executeProcessReturnObject() throws SQLException {
                    psImpl = connImpl.prepareStatement(sqlCommands.getProperty("domain.delete"));
                    Iterator<Integer> iter = domainIds.iterator();
                    int domainId;
                    boolean defaultDomainDeleted = false;
                    while (iter.hasNext()) {
                        domainId = iter.next();
                        if (!defaultDomainDeleted) defaultDomainDeleted = defaultDomainId == domainId;
                        psImpl.setInt(1, domainId);
                        psImpl.executeUpdate();
                    }
                    return defaultDomainDeleted;
                }
            });
            if (defaultDomainDeleted) {
                new ProcessEnvelope().executeNull(new ExecuteProcessAbstractImpl(connection, false, false, true, true) {

                    @Override
                    public void executeProcessReturnNull() throws SQLException {
                        psImpl = connImpl.prepareStatement(sqlCommands.getProperty("domain.setDefaultDomainId"));
                        psImpl.setInt(1, -1);
                        psImpl.executeUpdate();
                    }
                });
            }
            connection.commit();
            cmDB.updateDomains(null, null);
            if (defaultDomainDeleted) {
                cm.updateDefaultDomain();
            }
        } catch (SQLException sqle) {
            log.error(sqle);
            if (connection != null) {
                try {
                    connection.rollback();
                } catch (SQLException ex) {
                }
            }
        } finally {
            if (connection != null) {
                try {
                    connection.setAutoCommit(true);
                } catch (SQLException ex) {
                }
            }
        }
    }
public void setDefaultDomain(final int domainId) {
        try {
            connection.setAutoCommit(false);
            new ProcessEnvelope().executeNull(new ExecuteProcessAbstractImpl(connection, false, false, true, true) {

                @Override
                public void executeProcessReturnNull() throws SQLException {
                    psImpl = connImpl.prepareStatement(sqlCommands.getProperty("domain.setDefaultDomainId"));
                    psImpl.setInt(1, domainId);
                    psImpl.executeUpdate();
                }
            });
            connection.commit();
            cm.updateDefaultDomain();
        } catch (SQLException sqle) {
            log.error(sqle);
            if (connection != null) {
                try {
                    connection.rollback();
                } catch (SQLException ex) {
                }
            }
        } finally {
            if (connection != null) {
                try {
                    connection.setAutoCommit(true);
                } catch (SQLException ex) {
                }
            }
        }
    }
public void deleteUser(final List<Integer> userIds) {
        try {
            connection.setAutoCommit(false);
            new ProcessEnvelope().executeNull(new ExecuteProcessAbstractImpl(connection, false, false, true, true) {

                @Override
                public void executeProcessReturnNull() throws SQLException {
                    psImpl = connImpl.prepareStatement(sqlCommands.getProperty("user.delete"));
                    Iterator<Integer> iter = userIds.iterator();
                    int userId;
                    while (iter.hasNext()) {
                        userId = iter.next();
                        psImpl.setInt(1, userId);
                        psImpl.executeUpdate();
                    }
                }
            });
            connection.commit();
            cmDB.removeUsers(userIds);
        } catch (SQLException sqle) {
            log.error(sqle);
            if (connection != null) {
                try {
                    connection.rollback();
                } catch (SQLException ex) {
                }
            }
        } finally {
            if (connection != null) {
                try {
                    connection.setAutoCommit(true);
                } catch (SQLException ex) {
                }
            }
        }
    }