semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static void polishOff(IProgressMonitor monitor, String from, String to, String renameTo) {
        if (monitor != null && monitor.isCanceled()) {
            return;
        }
        try {
            ftpClient = new FTPClient();
            ftpClient.setRemoteAddr(InetAddress.getByName(PrefPageOne.getValue(CONSTANTS.PREF_HOST)));
            ftpClient.setControlPort(PrefPageOne.getIntValue(CONSTANTS.PREF_FTPPORT));
            ftpClient.connect();
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            ftpClient.login((PrefPageOne.getValue(CONSTANTS.PREF_USERNAME)), FTPUtils.decrypt(PrefPageOne.getValue(CONSTANTS.PREF_PASSWORD)));
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (from != null) {
                FTPHolder ftpHolder = new FTPHolder(from, to, renameTo, false);
                synchedSet.add(ftpHolder);
            }
            JobHandler.aquireFTPLock();
            for (Iterator iter = synchedSet.iterator(); iter.hasNext(); ) {
                if (monitor != null && monitor.isCanceled()) {
                    JobHandler.releaseFTPLock();
                    ftpClient.quit();
                    return;
                }
                Thread.yield();
                FTPHolder element = (FTPHolder) iter.next();
                ftpClient.setType(FTPTransferType.ASCII);
                ftpClient.put(element.from, element.to);
                if (element.renameTo != null) {
                    try {
                        ftpClient.delete(element.renameTo);
                    } catch (Exception e) {
                    }
                    ftpClient.rename(element.to, element.renameTo);
                    log.info("RENAME: " + element.to + "To: " + element.renameTo);
                }
            }
            JobHandler.releaseFTPLock();
            ftpClient.quit();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (FTPException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        synchedSet.clear();
    }
protected void generateDiffResults(File outFile) throws IOException {
        FileOutputStream outStream = new FileOutputStream(outFile);
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(outStream, outputCharset));
        intlWrite(out, HTML_STRICT_DOCTYPE + "<html><head><title>${Report.Title}</title>\n" + "<meta http-equiv=\"Content-Type\"" + " content=\"text/html; charset=" + outputCharset + "\">\n" + "<style type=\"text/css\">\n");
        out.write(LOCDiff.getCssText());
        writeCustomStyleInfo(out);
        out.write("</style></head>\n" + "<body>\n" + "<div>\n");
        if (addedTable.length() > 0) {
            out.write("<table border>");
            intlWrite(out, getAddedTableHeader());
            out.write(addedTable.toString());
            out.write("</table><br><br>");
        }
        if (modifiedTable.length() > 0) {
            out.write("<table border>");
            intlWrite(out, getModifiedTableHeader());
            out.write(modifiedTable.toString());
            out.write("</table><br><br>");
        }
        if (deletedTable.length() > 0) {
            out.write("<table border>");
            intlWrite(out, getDeletedTableHeader());
            out.write(deletedTable.toString());
            out.write("</table><br><br>");
        }
        if (unchangedTable.length() > 0) {
            out.write("<table border>");
            intlWrite(out, getUnchangedTableHeader());
            out.write(unchangedTable.toString());
            out.write("</table><br><br>");
        }
        writeSummaryTable(out);
        out.write("</div>");
        redlinesOut.close();
        out.flush();
        InputStream redlines = new FileInputStream(redlinesTempFile);
        byte[] buffer = new byte[4096];
        int bytesRead;
        while ((bytesRead = redlines.read(buffer)) != -1) outStream.write(buffer, 0, bytesRead);
        outStream.write("</BODY></HTML>".getBytes());
        outStream.close();
    }
public String openFileAsText(String resource) throws IOException {
        StringWriter wtr = new StringWriter();
        InputStreamReader rdr = new InputStreamReader(openFile(resource));
        try {
            IOUtils.copy(rdr, wtr);
        } finally {
            IOUtils.closeQuietly(rdr);
        }
        return wtr.toString();
    }
public void writeFile(String resource, InputStream is) throws IOException {
        File f = prepareFsReferenceAsFile(resource);
        FileOutputStream fos = new FileOutputStream(f);
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        try {
            IOUtils.copy(is, bos);
        } finally {
            IOUtils.closeQuietly(is);
            IOUtils.closeQuietly(bos);
        }
    }
public String postEvent(EventDocument eventDoc, Map attachments) {
        if (eventDoc == null || eventDoc.getEvent() == null) return null;
        if (queue == null) {
            sendEvent(eventDoc, attachments);
            return eventDoc.getEvent().getEventId();
        }
        if (attachments != null) {
            Iterator iter = attachments.entrySet().iterator();
            while (iter.hasNext()) {
                Map.Entry entry = (Map.Entry) iter.next();
                if (entry.getValue() instanceof DataHandler) {
                    File file = new File(attachmentStorge + "/" + GuidUtil.generate() + entry.getKey());
                    try {
                        IOUtils.copy(((DataHandler) entry.getValue()).getInputStream(), new FileOutputStream(file));
                        entry.setValue(file);
                    } catch (IOException err) {
                        err.printStackTrace();
                    }
                }
            }
        }
        InternalEventObject eventObj = new InternalEventObject();
        eventObj.setEventDocument(eventDoc);
        eventObj.setAttachments(attachments);
        eventObj.setSessionContext(SessionContextUtil.getCurrentContext());
        eventDoc.getEvent().setEventId(GuidUtil.generate());
        getQueue().post(eventObj);
        return eventDoc.getEvent().getEventId();
    }
public ActionResponse executeAction(ActionRequest request) throws Exception {
        ActionResponse resp = new ActionResponse();
        BufferedReader in = null;
        try {
            URL url = new URL(URL);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            int status = conn.getResponseCode();
            if (status == 200) {
                in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                while (true) {
                    String line = in.readLine();
                    if (line == null) break;
                    resp.addResult("REMOTEVERSION", line);
                }
            } else {
                resp.setErrorCode(ActionResponse.GENERAL_ERROR);
                resp.setErrorMessage("HTTP Error [" + status + "]");
            }
        } catch (Exception e) {
            resp.setErrorCode(ActionResponse.GENERAL_ERROR);
            resp.setErrorMessage(e.getMessage());
        } finally {
            if (in != null) {
                in.close();
            }
        }
        return resp;
    }
static boolean writeProperties(Map<String, String> customProps, File destination) throws IOException {
        synchronized (PropertiesIO.class) {
            L.info(Msg.msg("PropertiesIO.writeProperties.start"));
            File tempFile = null;
            BufferedInputStream existingCfgInStream = null;
            FileInputStream in = null;
            FileOutputStream out = null;
            PrintStream ps = null;
            FileChannel fromChannel = null, toChannel = null;
            String line = null;
            try {
                existingCfgInStream = new BufferedInputStream(destination.exists() ? new FileInputStream(destination) : defaultPropertiesStream());
                tempFile = File.createTempFile("properties-", ".tmp", null);
                ps = new PrintStream(tempFile);
                while ((line = Utils.readLine(existingCfgInStream)) != null) {
                    String lineReady2write = setupLine(line, customProps);
                    ps.println(lineReady2write);
                }
                destination.getParentFile().mkdirs();
                in = new FileInputStream(tempFile);
                out = new FileOutputStream(destination, false);
                fromChannel = in.getChannel();
                toChannel = out.getChannel();
                fromChannel.transferTo(0, fromChannel.size(), toChannel);
                L.info(Msg.msg("PropertiesIO.writeProperties.done").replace("#file#", destination.getAbsolutePath()));
                return true;
            } finally {
                if (existingCfgInStream != null) existingCfgInStream.close();
                if (ps != null) ps.close();
                if (fromChannel != null) fromChannel.close();
                if (toChannel != null) toChannel.close();
                if (out != null) out.close();
                if (in != null) in.close();
                if (tempFile != null && tempFile.exists()) tempFile.delete();
            }
        }
    }
private void writeGif(String filename, String outputFile) throws IOException {
        File file = new File(filename);
        InputStream in = new FileInputStream(file);
        FileOutputStream fout = new FileOutputStream(outputFile);
        int totalRead = 0;
        int readBytes = 0;
        int blockSize = 65000;
        long fileLen = file.length();
        byte b[] = new byte[blockSize];
        while ((long) totalRead < fileLen) {
            readBytes = in.read(b, 0, blockSize);
            totalRead += readBytes;
            fout.write(b, 0, readBytes);
        }
        in.close();
        fout.close();
    }
@Override
    public void alterar(Disciplina t) throws Exception {
        PreparedStatement stmt = null;
        String sql = "UPDATE disciplina SET nm_disciplina = ?, cod_disciplina = ? WHERE id_disciplina = ?";
        try {
            stmt = conexao.prepareStatement(sql);
            stmt.setString(1, t.getNomeDisciplina());
            stmt.setString(2, t.getCodDisciplina());
            stmt.setInt(3, t.getIdDisciplina());
            stmt.executeUpdate();
            conexao.commit();
            int id_disciplina = t.getIdDisciplina();
            excluirTopico(t.getIdDisciplina());
            for (Topico item : t.getTopicos()) {
                criarTopico(item, id_disciplina);
            }
        } catch (SQLException e) {
            conexao.rollback();
            throw e;
        }
    }
@Override
    public void excluir(Disciplina t) throws Exception {
        PreparedStatement stmt = null;
        String sql = "DELETE from disciplina where id_disciplina = ?";
        try {
            stmt = conexao.prepareStatement(sql);
            stmt.setInt(1, t.getIdDisciplina());
            stmt.executeUpdate();
            conexao.commit();
        } catch (SQLException e) {
            conexao.rollback();
            throw e;
        } finally {
            try {
                stmt.close();
                conexao.close();
            } catch (SQLException e) {
                throw e;
            }
        }
    }
public void excluirTopico(Integer idDisciplina) throws Exception {
        String sql = "DELETE from topico WHERE id_disciplina = ?";
        PreparedStatement stmt = null;
        try {
            stmt = conexao.prepareStatement(sql);
            stmt.setInt(1, idDisciplina);
            stmt.executeUpdate();
            conexao.commit();
        } catch (SQLException e) {
            conexao.rollback();
            throw e;
        }
    }
private void removeSessionId(InputStream inputStream, Output output) throws IOException {
        String jsessionid = RewriteUtils.getSessionId(target);
        boolean textContentType = ResourceUtils.isTextContentType(httpClientResponse.getHeader(HttpHeaders.CONTENT_TYPE), target.getDriver().getConfiguration().getParsableContentTypes());
        if (jsessionid == null || !textContentType) {
            IOUtils.copy(inputStream, output.getOutputStream());
        } else {
            String charset = httpClientResponse.getContentCharset();
            if (charset == null) {
                charset = "ISO-8859-1";
            }
            String content = IOUtils.toString(inputStream, charset);
            content = removeSessionId(jsessionid, content);
            if (output.getHeader(HttpHeaders.CONTENT_LENGTH) != null) {
                output.setHeader(HttpHeaders.CONTENT_LENGTH, Integer.toString(content.length()));
            }
            OutputStream outputStream = output.getOutputStream();
            IOUtils.write(content, outputStream, charset);
        }
        inputStream.close();
    }
public ViewProperties(String basePath, String baseFile) throws Exception {
            FileInputStream input = null;
            String file = basePath + "/" + baseFile + ".properties";
            properties = new Properties();
            try {
                URL url = MapViewer.class.getResource(file);
                properties.load(url.openStream());
                viewName = (String) properties.get("view.name");
                viewShape = (String) properties.get("view.shape");
                path = basePath + "/" + (String) properties.get("icon.path");
                iconHeight = getIntProperty("icon.height", 96);
                iconWidth = getIntProperty("icon.width", 96);
                fontSizeSmall = getIntProperty("font.small.size", 10);
                fontSizeMedium = getIntProperty("font.medium.size", 12);
                fontSizeLarge = getIntProperty("font.large.size", 16);
                fontSizeHuge = getIntProperty("font.huge.size", 20);
                if (viewShape.equals("Hexagonal")) {
                    tileHeight = (int) (Math.sqrt(3.0) / 2.0 * iconWidth);
                    tileWidth = (int) (iconWidth * 3.0 / 4.0);
                    tileOffset = (int) (tileHeight / 2.0);
                } else {
                    tileHeight = iconHeight;
                    tileWidth = iconWidth;
                    tileOffset = 0;
                }
            } catch (Exception e) {
                error("Cannot load properties from file [" + file + "]");
                throw e;
            }
        }
private void write(File src, File dst, byte id3v1Tag[], byte id3v2HeadTag[], byte id3v2TailTag[]) throws IOException {
        if (src == null || !src.exists()) throw new IOException(Debug.getDebug("missing src", src));
        if (!src.getName().toLowerCase().endsWith(".mp3")) throw new IOException(Debug.getDebug("src not mp3", src));
        if (dst == null) throw new IOException(Debug.getDebug("missing dst", dst));
        if (dst.exists()) {
            dst.delete();
            if (dst.exists()) throw new IOException(Debug.getDebug("could not delete dst", dst));
        }
        boolean hasId3v1 = new MyID3v1().hasID3v1(src);
        long id3v1Length = hasId3v1 ? ID3_V1_TAG_LENGTH : 0;
        long id3v2HeadLength = new MyID3v2().findID3v2HeadLength(src);
        long id3v2TailLength = new MyID3v2().findID3v2TailLength(src, hasId3v1);
        OutputStream os = null;
        InputStream is = null;
        try {
            dst.getParentFile().mkdirs();
            os = new FileOutputStream(dst);
            os = new BufferedOutputStream(os);
            if (!skipId3v2Head && !skipId3v2 && id3v2HeadTag != null) os.write(id3v2HeadTag);
            is = new FileInputStream(src);
            is = new BufferedInputStream(is);
            is.skip(id3v2HeadLength);
            long total_to_read = src.length();
            total_to_read -= id3v1Length;
            total_to_read -= id3v2HeadLength;
            total_to_read -= id3v2TailLength;
            byte buffer[] = new byte[1024];
            long total_read = 0;
            while (total_read < total_to_read) {
                int remainder = (int) (total_to_read - total_read);
                int readSize = Math.min(buffer.length, remainder);
                int read = is.read(buffer, 0, readSize);
                if (read <= 0) throw new IOException("unexpected EOF");
                os.write(buffer, 0, read);
                total_read += read;
            }
            if (!skipId3v2Tail && !skipId3v2 && id3v2TailTag != null) os.write(id3v2TailTag);
            if (!skipId3v1 && id3v1Tag != null) os.write(id3v1Tag);
        } finally {
            try {
                if (is != null) is.close();
            } catch (Throwable e) {
                Debug.debug(e);
            }
            try {
                if (os != null) os.close();
            } catch (Throwable e) {
                Debug.debug(e);
            }
        }
    }
public Program createNewProgram(int projectID, String name, String description) throws AdaptationException {
        Program program = null;
        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet = null;
        try {
            connection = DriverManager.getConnection(CONN_STR);
            connection.setAutoCommit(false);
            statement = connection.createStatement();
            String query = "INSERT INTO Programs(projectID, name, " + "description, sourcePath) VALUES ( " + projectID + ", " + "'" + name + "', " + "'" + description + "', " + "'" + "[unknown]" + "')";
            log.debug("SQL Query:\n" + query);
            statement.executeUpdate(query);
            query = "SELECT * FROM Programs WHERE " + " projectID   =  " + projectID + "  AND " + " name        = '" + name + "' AND " + " description = '" + description + "'";
            resultSet = statement.executeQuery(query);
            if (!resultSet.next()) {
                connection.rollback();
                String msg = "Attempt to create program failed";
                log.error(msg);
                throw new AdaptationException(msg);
            }
            program = getProgram(resultSet);
            connection.commit();
        } catch (SQLException ex) {
            try {
                connection.rollback();
            } catch (Exception e) {
            }
            String msg = "SQLException in createNewProgram";
            log.error(msg, ex);
            throw new AdaptationException(msg, ex);
        } finally {
            try {
                resultSet.close();
            } catch (Exception ex) {
            }
            try {
                statement.close();
            } catch (Exception ex) {
            }
            try {
                connection.close();
            } catch (Exception ex) {
            }
        }
        return program;
    }
public Program updateProgramPath(int id, String sourcePath) throws AdaptationException {
        Program program = null;
        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet = null;
        try {
            String query = "UPDATE Programs SET " + "sourcePath = '" + sourcePath + "' " + "WHERE id = " + id;
            connection = DriverManager.getConnection(CONN_STR);
            statement = connection.createStatement();
            statement.executeUpdate(query);
            query = "SELECT * from Programs WHERE id = " + id;
            resultSet = statement.executeQuery(query);
            if (!resultSet.next()) {
                connection.rollback();
                String msg = "Attempt to update program failed.";
                log.error(msg);
                throw new AdaptationException(msg);
            }
            program = getProgram(resultSet);
            connection.commit();
        } catch (SQLException ex) {
            try {
                connection.rollback();
            } catch (Exception e) {
            }
            String msg = "SQLException in updateProgramPath";
            log.error(msg, ex);
            throw new AdaptationException(msg, ex);
        } finally {
            try {
                resultSet.close();
            } catch (Exception ex) {
            }
            try {
                statement.close();
            } catch (Exception ex) {
            }
            try {
                connection.close();
            } catch (Exception ex) {
            }
        }
        return program;
    }
public Program deleteProgram(int id) throws AdaptationException {
        Program program = null;
        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet = null;
        try {
            String query = "SELECT * FROM Programs WHERE id = " + id;
            connection = DriverManager.getConnection(CONN_STR);
            statement = connection.createStatement();
            resultSet = statement.executeQuery(query);
            if (!resultSet.next()) {
                connection.rollback();
                String msg = "Attempt to delete program failed.";
                log.error(msg);
                throw new AdaptationException(msg);
            }
            program = getProgram(resultSet);
            query = "DELETE FROM Programs WHERE id = " + id;
            statement.executeUpdate(query);
            connection.commit();
        } catch (SQLException ex) {
            try {
                connection.rollback();
            } catch (Exception e) {
            }
            String msg = "SQLException in deleteProgram";
            log.error(msg, ex);
            throw new AdaptationException(msg, ex);
        } finally {
            try {
                resultSet.close();
            } catch (Exception ex) {
            }
            try {
                statement.close();
            } catch (Exception ex) {
            }
            try {
                connection.close();
            } catch (Exception ex) {
            }
        }
        return program;
    }
private static void copyImage(String srcImg, String destImg) {
        try {
            FileChannel srcChannel = new FileInputStream(srcImg).getChannel();
            FileChannel dstChannel = new FileOutputStream(destImg).getChannel();
            dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
            srcChannel.close();
            dstChannel.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }