semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static void fileCopy(File src, File dst) throws FileNotFoundException, IOException {
        if (src.isDirectory() && (!dst.exists() || dst.isDirectory())) {
            if (!dst.exists()) {
                if (!dst.mkdirs()) throw new IOException("unable to mkdir " + dst);
            }
            File dst1 = new File(dst, src.getName());
            if (!dst1.exists() && !dst1.mkdir()) throw new IOException("unable to mkdir " + dst1);
            dst = dst1;
            File[] files = src.listFiles();
            for (File f : files) {
                if (f.isDirectory()) {
                    dst1 = new File(dst, f.getName());
                    if (!dst1.exists() && !dst1.mkdir()) throw new IOException("unable to mkdir " + dst1);
                } else {
                    dst1 = dst;
                }
                fileCopy(f, dst1);
            }
            return;
        } else if (dst.isDirectory()) {
            dst = new File(dst, src.getName());
        }
        FileChannel ic = new FileInputStream(src).getChannel();
        FileChannel oc = new FileOutputStream(dst).getChannel();
        ic.transferTo(0, ic.size(), oc);
        ic.close();
        oc.close();
    }
public boolean checkWebsite(String URL, String content) {
        boolean run = false;
        try {
            URL url = new URL(URL + "?a=" + Math.random());
            BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
            String line = "";
            while ((line = reader.readLine()) != null) {
                if (line.contains(content)) {
                    run = true;
                }
            }
        } catch (Exception e) {
            run = false;
        }
        return run;
    }
@Override
    public final byte[] getDigest() {
        try {
            final MessageDigest hashing = MessageDigest.getInstance("SHA-256");
            final Charset utf16 = Charset.forName("UTF-16");
            for (final CollationKey wordKey : this.words) {
                hashing.update(wordKey.toByteArray());
            }
            hashing.update(this.locale.toString().getBytes(utf16));
            hashing.update(ByteUtils.toBytesLE(this.collator.getStrength()));
            hashing.update(ByteUtils.toBytesLE(this.collator.getDecomposition()));
            return hashing.digest();
        } catch (final NoSuchAlgorithmException e) {
            FileBasedDictionary.LOG.severe(e.toString());
            return new byte[0];
        }
    }
public void addFinance(int clubid, int quarterid, String date, String desc, String loc, BigDecimal amount) throws FinanceException, SQLException {
        String budgetQuery = "SELECT used, available FROM Budget WHERE club_id=" + clubid + " and quarter_id=" + quarterid + ";";
        String financeUpdate = "INSERT INTO Finance (`club_id`, `transaction_date`, `description`, `location`, `amount`) VALUES ('" + clubid + "', '" + date + "', '" + desc + "', '" + "', '" + loc + "', '" + amount + "');";
        Budget b = new Budget();
        try {
            cn.setAutoCommit(false);
            Statement sm = cn.createStatement();
            ResultSet rs = sm.executeQuery(budgetQuery);
            if (rs.first()) {
                b.used = rs.getBigDecimal(1);
                b.available = rs.getBigDecimal(2);
            } else {
                throw new FinanceException("No budget exists for this club!!");
            }
            if (b.available.compareTo(amount.negate()) >= 0) {
                if (amount.equals(new BigDecimal(0))) ;
                {
                    b.used = b.used.subtract(amount);
                }
                b.available = b.available.add(amount);
                sm = cn.createStatement();
                sm.executeUpdate(financeUpdate);
                sm = cn.createStatement();
                sm.executeUpdate("Update Budget SET used = " + b.used + ", amount = " + b.available + " WHERE club_id=" + clubid + " and quarter_id=" + quarterid + ";");
                cn.commit();
            } else {
                throw new FinanceException("The proposed expenditure is not within the club's budget.");
            }
        } catch (SQLException e) {
            cn.rollback();
            throw e;
        } finally {
            cn.setAutoCommit(true);
        }
    }
@Before
    public void setUp() throws IOException {
        testSbk = File.createTempFile("songbook", "sbk");
        IOUtils.copy(Thread.currentThread().getContextClassLoader().getResourceAsStream("test.sbk"), new FileOutputStream(testSbk));
        test1Sbk = File.createTempFile("songbook", "sbk");
        IOUtils.copy(Thread.currentThread().getContextClassLoader().getResourceAsStream("test1.sbk"), new FileOutputStream(test1Sbk));
    }
public void adicionaCliente(ClienteBean cliente) {
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        String sql = "insert into cliente(nome,cpf,telefone,cursoCargo,bloqueado,ativo,tipo) values(?,?,?,?,?,?,?)";
        try {
            pstmt = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
            pstmt.setString(1, cliente.getNome());
            pstmt.setString(2, cliente.getCPF());
            pstmt.setString(3, cliente.getTelefone());
            pstmt.setString(4, cliente.getCursoCargo());
            pstmt.setString(5, cliente.getBloqueado());
            pstmt.setString(6, cliente.getAtivo());
            pstmt.setString(7, cliente.getTipo());
            pstmt.executeUpdate();
            rs = pstmt.getGeneratedKeys();
            if (rs.next()) {
                cliente.setIdCliente(rs.getLong(1));
            }
            connection.commit();
        } catch (SQLException ex) {
            try {
                connection.rollback();
            } catch (SQLException ex1) {
                throw new RuntimeException("Erro ao inserir cliente.", ex1);
            }
            throw new RuntimeException("Erro ao inserir cliente.", ex);
        } finally {
            try {
                if (rs != null) rs.close();
                if (pstmt != null) pstmt.close();
            } catch (SQLException ex) {
                throw new RuntimeException("Ocorreu um erro no banco de dados.", ex);
            }
        }
    }
public void excluirCliente(String cpf) {
        PreparedStatement pstmt = null;
        String sql = "delete from cliente where cpf = ?";
        try {
            pstmt = connection.prepareStatement(sql);
            pstmt.setString(1, cpf);
            pstmt.executeUpdate();
            connection.commit();
        } catch (SQLException ex) {
            try {
                connection.rollback();
            } catch (SQLException ex1) {
                throw new RuntimeException("Erro ao exclir ciente.", ex1);
            }
            throw new RuntimeException("Erro ao excluir cliente.", ex);
        } finally {
            try {
                if (pstmt != null) {
                    pstmt.close();
                }
            } catch (SQLException ex) {
                throw new RuntimeException("Ocorreu um erro no banco de dados.", ex);
            }
        }
    }
public void alterarCliente(ClienteBean cliente, String cpf) {
        PreparedStatement pstmt = null;
        String sql = "UPDATE cliente SET nome = ?," + "cpf = ?," + "telefone = ?," + "cursoCargo = ?," + "bloqueado = ?," + "ativo = ?," + "tipo = ? WHERE cpf = ?";
        try {
            pstmt = connection.prepareStatement(sql);
            pstmt.setString(1, cliente.getNome());
            pstmt.setString(2, cliente.getCPF());
            pstmt.setString(3, cliente.getTelefone());
            pstmt.setString(4, cliente.getCursoCargo());
            pstmt.setString(5, cliente.getBloqueado());
            pstmt.setString(6, cliente.getAtivo());
            pstmt.setString(7, cliente.getTipo());
            pstmt.setString(8, cpf);
            pstmt.executeUpdate();
            connection.commit();
        } catch (SQLException ex) {
            try {
                connection.rollback();
            } catch (SQLException ex1) {
                throw new RuntimeException("Erro ao atualizar cliente.", ex1);
            }
            throw new RuntimeException("Erro ao atualizar cliente.", ex);
        } finally {
            try {
                if (pstmt != null) pstmt.close();
            } catch (SQLException ex) {
                throw new RuntimeException("Ocorreu um erro no banco de dados.", ex);
            }
        }
    }
private List<String> getHashesFrom(String webPage) {
        Vector<String> out = new Vector();
        try {
            URL url = new URL(webPage);
            BufferedReader r = new BufferedReader(new InputStreamReader(url.openStream()));
            String line;
            while ((line = r.readLine()) != null) {
                out.add(line);
            }
        } catch (Exception X) {
            return null;
        }
        return out;
    }
void copyFile(String src, String dest) throws IOException {
        int amount;
        byte[] buffer = new byte[4096];
        FileInputStream in = new FileInputStream(src);
        FileOutputStream out = new FileOutputStream(dest);
        while ((amount = in.read(buffer)) != -1) out.write(buffer, 0, amount);
        in.close();
        out.close();
    }
private static String connect(String apiURL, boolean secure) throws IOException {
        String baseUrl;
        if (secure) baseUrl = "https://todoist.com/API/"; else baseUrl = "http://todoist.com/API/";
        URL url = new URL(baseUrl + apiURL);
        URLConnection c = url.openConnection();
        BufferedReader in = new BufferedReader(new InputStreamReader(c.getInputStream()));
        StringBuilder toReturn = new StringBuilder("");
        String toAppend;
        while ((toAppend = in.readLine()) != null) toReturn.append(toAppend);
        return toReturn.toString();
    }
public DBAccess(String pathToDb) {
        if (instance != null) {
            throw new IllegalStateException();
        }
        System.setProperty("derby.system.home", pathToDb);
        try {
            boolean exists = new File(pathToDb).exists();
            new EmbeddedDriver();
            Properties props = new Properties();
            if (exists) {
                connection = DriverManager.getConnection(protocol + "rmpDB;", props);
                connection.setAutoCommit(true);
                Statement statement = connection.createStatement();
                try {
                } finally {
                    statement.close();
                }
            } else {
                connection = DriverManager.getConnection(protocol + "rmpDB;create=true", props);
                connection.setAutoCommit(true);
                URL url = Platform.getBundle("ru.spbu.dorms.geo.rmp").getResource("sql/createdb.sql");
                BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
                StringBuilder query = new StringBuilder();
                for (String s = reader.readLine(); s != null; s = reader.readLine()) {
                    if (query.length() > 0) {
                        query.append('\n');
                    }
                    query.append(s);
                }
                reader.close();
                Statement statement = connection.createStatement();
                try {
                    String[] statements = query.toString().split(";(\\s)*");
                    for (String s : statements) {
                        statement.execute(s);
                    }
                } finally {
                    statement.close();
                }
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        instance = this;
    }
static void copy(String src, String dest) throws IOException {
        File ifp = new File(src);
        File ofp = new File(dest);
        if (ifp.exists() == false) {
            throw new IOException("file '" + src + "' does not exist");
        }
        FileInputStream fis = new FileInputStream(ifp);
        FileOutputStream fos = new FileOutputStream(ofp);
        byte[] b = new byte[1024];
        while (fis.read(b) > 0) fos.write(b);
        fis.close();
        fos.close();
    }
public void copyDependancyFiles() {
        for (String[] depStrings : getDependancyFiles()) {
            String source = depStrings[0];
            String target = depStrings[1];
            try {
                File sourceFile = PluginManager.getFile(source);
                IOUtils.copyEverything(sourceFile, new File(WEB_ROOT + target));
            } catch (URISyntaxException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
void load(URL url) throws IOException {
        BufferedReader r = new BufferedReader(new InputStreamReader(url.openStream()));
        Vector3f scale = new Vector3f(1, 1, 1);
        Group currentGroup = new Group();
        currentGroup.name = "default";
        groups.add(currentGroup);
        String line;
        while ((line = r.readLine()) != null) {
            String[] params = line.split(" +");
            if (params.length == 0) continue;
            String command = params[0];
            if (params[0].equals("v")) {
                Vector3f vertex = new Vector3f(Float.parseFloat(params[1]) * scale.x, Float.parseFloat(params[2]) * scale.y, Float.parseFloat(params[3]) * scale.z);
                verticies.add(vertex);
                radius = Math.max(radius, vertex.length());
            }
            if (command.equals("center")) {
                epicenter = new Vector3f(Float.parseFloat(params[1]), Float.parseFloat(params[2]), Float.parseFloat(params[3]));
            } else if (command.equals("f")) {
                Face f = new Face();
                for (int i = 1; i < params.length; i++) {
                    String parts[] = params[i].split("/");
                    Vector3f v = verticies.get(Integer.parseInt(parts[0]) - 1);
                    f.add(v);
                }
                currentGroup.faces.add(f);
            } else if (command.equals("l")) {
                Line l = new Line();
                for (int i = 1; i < params.length; i++) {
                    Vector3f v = verticies.get(Integer.parseInt(params[i]) - 1);
                    l.add(v);
                }
                currentGroup.lines.add(l);
            } else if (command.equals("g") && params.length > 1) {
                currentGroup = new Group();
                currentGroup.name = params[1];
                groups.add(currentGroup);
            } else if (command.equals("scale")) {
                scale = new Vector3f(Float.parseFloat(params[1]), Float.parseFloat(params[2]), Float.parseFloat(params[3]));
            }
        }
        r.close();
    }
private void copyJar(File src, File dst) throws IOException {
        FileChannel srcChannel = null;
        FileChannel dstChannel = null;
        try {
            srcChannel = new FileInputStream(src).getChannel();
            dstChannel = new FileOutputStream(dst).getChannel();
            dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
        } catch (IOException e) {
            fLog.log(Level.SEVERE, e.getMessage(), e);
        } finally {
            srcChannel.close();
            dstChannel.close();
        }
    }
protected InputStream openStreamInternal(String userAgent, Iterator mimeTypes, Iterator encodingTypes) throws IOException {
        if (stream != null) return stream;
        hasBeenOpened = true;
        URL url = null;
        try {
            url = buildURL();
        } catch (MalformedURLException mue) {
            throw new IOException("Unable to make sense of URL for connection");
        }
        if (url == null) return null;
        URLConnection urlC = url.openConnection();
        if (urlC instanceof HttpURLConnection) {
            if (userAgent != null) urlC.setRequestProperty(HTTP_USER_AGENT_HEADER, userAgent);
            if (mimeTypes != null) {
                String acceptHeader = "";
                while (mimeTypes.hasNext()) {
                    acceptHeader += mimeTypes.next();
                    if (mimeTypes.hasNext()) acceptHeader += ",";
                }
                urlC.setRequestProperty(HTTP_ACCEPT_HEADER, acceptHeader);
            }
            if (encodingTypes != null) {
                String encodingHeader = "";
                while (encodingTypes.hasNext()) {
                    encodingHeader += encodingTypes.next();
                    if (encodingTypes.hasNext()) encodingHeader += ",";
                }
                urlC.setRequestProperty(HTTP_ACCEPT_ENCODING_HEADER, encodingHeader);
            }
            contentType = urlC.getContentType();
            contentEncoding = urlC.getContentEncoding();
        }
        return (stream = urlC.getInputStream());
    }
public void insertStringInFile(String file, String textToInsert, long fromByte, long toByte) throws Exception {
        String tmpFile = file + ".tmp";
        BufferedInputStream in = null;
        BufferedOutputStream out = null;
        long byteCount = 0;
        try {
            in = new BufferedInputStream(new FileInputStream(new File(file)));
            out = new BufferedOutputStream(new FileOutputStream(tmpFile));
            long size = fromByte;
            byte[] buf = null;
            if (size == 0) {
            } else {
                buf = new byte[(int) size];
                int length = -1;
                if ((length = in.read(buf)) != -1) {
                    out.write(buf, 0, length);
                    byteCount = byteCount + length;
                } else {
                    String msg = "Failed to read the first '" + size + "' bytes of file '" + file + "'. This might be a programming error.";
                    logger.warning(msg);
                    throw new Exception(msg);
                }
            }
            buf = textToInsert.getBytes();
            int length = buf.length;
            out.write(buf, 0, length);
            byteCount = byteCount + length;
            long skipLength = toByte - fromByte;
            long skippedBytes = in.skip(skipLength);
            if (skippedBytes == -1) {
            } else {
                buf = new byte[4096];
                length = -1;
                while ((length = in.read(buf)) != -1) {
                    out.write(buf, 0, length);
                    byteCount = byteCount + length;
                }
            }
            in.close();
            in = null;
            out.close();
            out = null;
            File fileToDelete = new File(file);
            boolean wasDeleted = fileToDelete.delete();
            if (!wasDeleted) {
                String msg = "Failed to delete the original file '" + file + "' to replace it with the modified file after text insertion.";
                logger.warning(msg);
                throw new Exception(msg);
            }
            File fileToRename = new File(tmpFile);
            boolean wasRenamed = fileToRename.renameTo(fileToDelete);
            if (!wasRenamed) {
                String msg = "Failed to rename tmp file '" + tmpFile + "' to the name of the original file '" + file + "'";
                logger.warning(msg);
                throw new Exception(msg);
            }
        } catch (Exception e) {
            logger.log(Level.WARNING, "Failed to read/write file '" + file + "'.", e);
            throw e;
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    logger.log(Level.FINEST, "Ignoring error closing input file '" + file + "'.", e);
                }
            }
            if (out != null) {
                try {
                    out.close();
                } catch (IOException e) {
                    logger.log(Level.FINEST, "Ignoring error closing output file '" + tmpFile + "'.", e);
                }
            }
        }
    }
public ArrayList<String> showTopLetters() {
        int[] tempArray = new int[engCountLetters.length];
        char[] tempArrayLetters = new char[abcEng.length];
        ArrayList<String> resultTopFiveLetters = new ArrayList<String>();
        tempArray = engCountLetters.clone();
        tempArrayLetters = abcEng.clone();
        int tempCount;
        char tempLetters;
        for (int j = 0; j < (abcEng.length * abcEng.length); j++) {
            for (int i = 0; i < abcEng.length - 1; i++) {
                if (tempArray[i] > tempArray[i + 1]) {
                    tempCount = tempArray[i];
                    tempLetters = tempArrayLetters[i];
                    tempArray[i] = tempArray[i + 1];
                    tempArrayLetters[i] = tempArrayLetters[i + 1];
                    tempArray[i + 1] = tempCount;
                    tempArrayLetters[i + 1] = tempLetters;
                }
            }
        }
        for (int i = tempArrayLetters.length - 1; i > tempArrayLetters.length - 6; i--) {
            resultTopFiveLetters.add(tempArrayLetters[i] + ":" + tempArray[i]);
        }
        return resultTopFiveLetters;
    }
@Override
    public InputStream openStream(long off, long len) throws IOException {
        URLConnection con = url.openConnection();
        if (!(con instanceof HttpURLConnection)) {
            return null;
        }
        long t0 = System.currentTimeMillis();
        HttpURLConnection urlcon = (HttpURLConnection) con;
        urlcon.setRequestProperty("Connection", "Keep-Alive");
        String rangeS = "";
        if (off > 0) rangeS += "bytes=" + off + "-";
        if (len > 0 && off + len < length) rangeS += (len - 1);
        if (rangeS.length() > 0) {
            urlcon.setRequestProperty("Range", rangeS);
        }
        urlcon.setRequestProperty("Content-Type", "application/octet-stream");
        InputStream in = urlcon.getInputStream();
        rangeS = urlcon.getHeaderField("Content-Range");
        long responseOff = 0;
        long responseEnd = -1;
        if (rangeS != null) {
            int start = rangeS.indexOf(' ') + 1;
            int end = rangeS.indexOf('-', start);
            String offS = rangeS.substring(start, end).trim();
            responseOff = Long.parseLong(offS);
            start = end + 1;
            end = rangeS.indexOf('/', start);
            String lenS = rangeS.substring(start, end).trim();
            responseEnd = 1 + Long.parseLong(lenS);
        }
        while (responseOff < off && responseOff <= responseEnd) {
            long s = in.skip(off - responseOff);
            if (s <= 0) {
                break;
            }
            responseOff += s;
        }
        length = urlcon.getHeaderFieldInt("Content-Length", -1);
        long respTime = System.currentTimeMillis() - t0;
        if (responseTime < 0) {
            responseTime = respTime;
        } else {
            responseTime = Math.round(0.5 * responseTime + 0.5 * respTime);
        }
        return in;
    }
private void readHomePage(ITestThread testThread) throws IOException {
        if (null == testThread) {
            throw new IllegalArgumentException("Test thread may not be null.");
        }
        final InputStream urlIn = new URL(testUrl).openStream();
        final int availableBytes = urlIn.available();
        if (0 == availableBytes) {
            throw new IllegalStateException("Zero bytes on target host.");
        }
        in = new BufferedReader(new InputStreamReader(urlIn));
        String line;
        while (null != in && null != (line = in.readLine())) {
            page.append(line);
            page.append('\n');
            if (0 != lineDelay) {
                OS.sleep(lineDelay);
            }
            if (testThread.isActionStopped()) {
                break;
            }
        }
    }