semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void command() {
        JFileChooser chooser = new JFileChooser();
        chooser.setCurrentDirectory(new File(dir));
        int returnVal = chooser.showOpenDialog(null);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            filename = chooser.getSelectedFile().getAbsolutePath();
            String f2 = "";
            for (int i = 0; i < filename.length(); ++i) {
                if (filename.charAt(i) != '\\') {
                    f2 = f2 + filename.charAt(i);
                } else f2 = f2 + '/';
            }
            filename = f2;
            if (filename.contains(dir)) {
                filename = filename.substring(dir.length());
            } else {
                try {
                    FileChannel srcFile = new FileInputStream(filename).getChannel();
                    FileChannel dstFile;
                    filename = "ueditor_files/" + chooser.getSelectedFile().getName();
                    File newFile;
                    if (!(newFile = new File(dir + filename)).createNewFile()) {
                        dstFile = new FileInputStream(dir + filename).getChannel();
                        newFile = null;
                    } else {
                        dstFile = new FileOutputStream(newFile).getChannel();
                    }
                    dstFile.transferFrom(srcFile, 0, srcFile.size());
                    srcFile.close();
                    dstFile.close();
                    System.out.println("file copyed to: " + dir + filename);
                } catch (Exception e) {
                    e.printStackTrace();
                    label.setIcon(InputText.iconX);
                    filename = null;
                    for (Group g : groups) {
                        g.updateValidity(true);
                    }
                    return;
                }
            }
            label.setIcon(InputText.iconV);
            for (Group g : groups) {
                g.updateValidity(true);
            }
        }
    }
private void insertContent(ImageData imageData, Element element) {
        URL url = getClass().getResource(imageData.getURL());
        try {
            File imageFileRead = new File(url.toURI());
            FileInputStream inputStream = new FileInputStream(imageFileRead);
            String imageFileWritePath = "htmlReportFiles" + "/" + imageData.getURL();
            File imageFileWrite = new File(imageFileWritePath);
            String[] filePathTokens = imageFileWritePath.split("/");
            String directoryPathCreate = filePathTokens[0];
            int i = 1;
            while (i < filePathTokens.length - 1) {
                directoryPathCreate = directoryPathCreate + "/" + filePathTokens[i];
                i++;
            }
            File fileDirectoryPathCreate = new File(directoryPathCreate);
            if (!fileDirectoryPathCreate.exists()) {
                boolean successfulFileCreation = fileDirectoryPathCreate.mkdirs();
                if (successfulFileCreation == false) {
                    throw new ExplanationException("Unable to create folders in path " + directoryPathCreate);
                }
            }
            FileOutputStream fileOutputStream = new FileOutputStream(imageFileWrite);
            byte[] data = new byte[1024];
            int readDataNumberOfBytes = 0;
            while (readDataNumberOfBytes != -1) {
                readDataNumberOfBytes = inputStream.read(data, 0, data.length);
                if (readDataNumberOfBytes != -1) {
                    fileOutputStream.write(data, 0, readDataNumberOfBytes);
                }
            }
            inputStream.close();
            fileOutputStream.close();
        } catch (Exception ex) {
            throw new ExplanationException(ex.getMessage());
        }
        String caption = imageData.getCaption();
        Element imageElement = element.addElement("img");
        if (imageData.getURL().charAt(0) != '/') imageElement.addAttribute("src", "htmlReportFiles" + "/" + imageData.getURL()); else imageElement.addAttribute("src", "htmlReportFiles" + imageData.getURL());
        imageElement.addAttribute("alt", "image not available");
        if (caption != null) {
            element.addElement("br");
            element.addText(caption);
        }
    }
public static void get_PK_data() {
        try {
            FileWriter file_writer = new FileWriter("xml_data/PK_data_dump.xml");
            BufferedWriter file_buffered_writer = new BufferedWriter(file_writer);
            URL fdt = new URL("http://opendata.5t.torino.it/get_pk");
            URLConnection url_connection = fdt.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(url_connection.getInputStream()));
            String input_line;
            int num_lines = 0;
            while ((input_line = in.readLine()) != null) {
                file_buffered_writer.write(input_line + "\n");
                num_lines++;
            }
            System.out.println("Parking :: Writed " + num_lines + " lines.");
            in.close();
        } catch (Exception e) {
            System.err.println("Error: " + e.getMessage());
        }
    }
private static String makeMD5(String str) {
        byte[] bytes = new byte[32];
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(str.getBytes("iso-8859-1"), 0, str.length());
            bytes = md.digest();
        } catch (Exception e) {
            return null;
        }
        return convertToHex(bytes);
    }
public int addDecisionInstruction(int condition, String frameSlot, String linkName, int objectId, String attribute, int positive, int negative) throws FidoDatabaseException, ObjectNotFoundException, InstructionNotFoundException {
        try {
            Connection conn = null;
            Statement stmt = null;
            try {
                if ((condition == ConditionalOperatorTable.CONTAINS_LINK) || (condition == ConditionalOperatorTable.NOT_CONTAINS_LINK)) {
                    ObjectTable ot = new ObjectTable();
                    if (ot.contains(objectId) == false) throw new ObjectNotFoundException(objectId);
                }
                conn = fido.util.FidoDataSource.getConnection();
                conn.setAutoCommit(false);
                stmt = conn.createStatement();
                if (contains(stmt, positive) == false) throw new InstructionNotFoundException(positive);
                if (contains(stmt, negative) == false) throw new InstructionNotFoundException(negative);
                String sql = "insert into Instructions (Type, Operator, FrameSlot, LinkName, ObjectId, AttributeName) " + "values (2, " + condition + ", '" + frameSlot + "', '" + linkName + "', " + objectId + ", '" + attribute + "')";
                stmt.executeUpdate(sql);
                int id = getCurrentId(stmt);
                InstructionGroupTable groupTable = new InstructionGroupTable();
                groupTable.deleteInstruction(stmt, id);
                if (positive != -1) groupTable.addInstructionAt(stmt, id, 1, positive);
                if (negative != -1) groupTable.addInstructionAt(stmt, id, 2, negative);
                conn.commit();
                return id;
            } catch (SQLException e) {
                if (conn != null) conn.rollback();
                throw e;
            } finally {
                if (stmt != null) stmt.close();
                if (conn != null) conn.close();
            }
        } catch (SQLException e) {
            throw new FidoDatabaseException(e);
        }
    }
public void modifyDecisionInstruction(int id, int condition, String frameSlot, String linkName, int objectId, String attribute, int positive, int negative) throws FidoDatabaseException, ObjectNotFoundException, InstructionNotFoundException {
        try {
            Connection conn = null;
            Statement stmt = null;
            try {
                if ((condition == ConditionalOperatorTable.CONTAINS_LINK) || (condition == ConditionalOperatorTable.NOT_CONTAINS_LINK)) {
                    ObjectTable ot = new ObjectTable();
                    if (ot.contains(objectId) == false) throw new ObjectNotFoundException(objectId);
                }
                conn = fido.util.FidoDataSource.getConnection();
                conn.setAutoCommit(false);
                stmt = conn.createStatement();
                if (contains(stmt, positive) == false) throw new InstructionNotFoundException(positive);
                if (contains(stmt, negative) == false) throw new InstructionNotFoundException(negative);
                String sql = "update Instructions set Operator = " + condition + ", " + "                        FrameSlot = '" + frameSlot + "', " + "                        LinkName = '" + linkName + "', " + "                        ObjectId = " + objectId + ", " + "                        AttributeName = '" + attribute + "' " + "where InstructionId = " + id;
                stmt.executeUpdate(sql);
                InstructionGroupTable groupTable = new InstructionGroupTable();
                groupTable.deleteInstruction(stmt, id);
                if (positive != -1) groupTable.addInstructionAt(stmt, id, 1, positive);
                if (negative != -1) groupTable.addInstructionAt(stmt, id, 2, negative);
                conn.commit();
            } catch (SQLException e) {
                if (conn != null) conn.rollback();
                throw e;
            } finally {
                if (stmt != null) stmt.close();
                if (conn != null) conn.close();
            }
        } catch (SQLException e) {
            throw new FidoDatabaseException(e);
        }
    }
public int addCollectionInstruction() throws FidoDatabaseException {
        try {
            Connection conn = null;
            Statement stmt = null;
            try {
                String sql = "insert into Instructions (Type, Operator) " + "values (1, 0)";
                conn = fido.util.FidoDataSource.getConnection();
                stmt = conn.createStatement();
                stmt.executeUpdate(sql);
                return getCurrentId(stmt);
            } catch (SQLException e) {
                if (conn != null) conn.rollback();
                throw e;
            } finally {
                if (stmt != null) stmt.close();
                if (conn != null) conn.close();
            }
        } catch (SQLException e) {
            throw new FidoDatabaseException(e);
        }
    }
public void delete(int id) throws FidoDatabaseException {
        try {
            Connection conn = null;
            Statement stmt = null;
            try {
                conn = fido.util.FidoDataSource.getConnection();
                conn.setAutoCommit(false);
                stmt = conn.createStatement();
                String sql = "delete from Instructions where InstructionId = " + id;
                stmt.executeUpdate(sql);
                sql = "delete from InstructionGroups where InstructionId = " + id;
                stmt.executeUpdate(sql);
                conn.commit();
            } catch (SQLException e) {
                if (conn != null) conn.rollback();
                throw e;
            } finally {
                if (stmt != null) stmt.close();
                if (conn != null) conn.close();
            }
        } catch (SQLException e) {
            throw new FidoDatabaseException(e);
        }
    }
public ChatClient registerPlayer(int playerId, String playerLogin) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest md = MessageDigest.getInstance("SHA-256");
        md.reset();
        md.update(playerLogin.getBytes("UTF-8"), 0, playerLogin.length());
        byte[] accountToken = md.digest();
        byte[] token = generateToken(accountToken);
        ChatClient chatClient = new ChatClient(playerId, token);
        players.put(playerId, chatClient);
        return chatClient;
    }
private String encryptPassword(String password) {
        String result = password;
        if (password != null) {
            try {
                MessageDigest md5 = MessageDigest.getInstance("MD5");
                md5.reset();
                md5.update(password.getBytes());
                BigInteger hash = new BigInteger(1, md5.digest());
                result = hash.toString(16);
                if ((result.length() % 2) != 0) {
                    result = "0" + result;
                }
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
                getLogger().error("Cannot generate MD5", e);
            }
        }
        return result;
    }
private int saveToTempTable(ArrayList cons, String tempTableName, boolean truncateFirst) throws SQLException {
        if (truncateFirst) {
            this.executeUpdate("TRUNCATE TABLE " + tempTableName);
            Categories.dataDb().debug("TABLE " + tempTableName + " TRUNCATED.");
        }
        PreparedStatement ps = null;
        int rows = 0;
        try {
            String insert = "INSERT INTO " + tempTableName + " VALUES (?)";
            ps = this.conn.prepareStatement(insert);
            for (int i = 0; i < cons.size(); i++) {
                ps.setLong(1, ((Long) cons.get(i)).longValue());
                rows = ps.executeUpdate();
                if ((i % 500) == 0) {
                    this.conn.commit();
                }
            }
            this.conn.commit();
        } catch (SQLException sqle) {
            this.conn.rollback();
            throw sqle;
        } finally {
            if (ps != null) {
                ps.close();
            }
        }
        return rows;
    }
public static void copyFile(File sourceFile, File destFile, boolean overwrite) throws IOException, DirNotFoundException, FileNotFoundException, FileExistsAlreadyException {
        File destDir = new File(destFile.getParent());
        if (!destDir.exists()) {
            throw new DirNotFoundException(destDir.getAbsolutePath());
        }
        if (!sourceFile.exists()) {
            throw new FileNotFoundException(sourceFile.getAbsolutePath());
        }
        if (!overwrite && destFile.exists()) {
            throw new FileExistsAlreadyException(destFile.getAbsolutePath());
        }
        FileInputStream in = new FileInputStream(sourceFile);
        FileOutputStream out = new FileOutputStream(destFile);
        byte[] buffer = new byte[8 * 1024];
        int count = 0;
        do {
            out.write(buffer, 0, count);
            count = in.read(buffer, 0, buffer.length);
        } while (count != -1);
        in.close();
        out.close();
    }
private boolean verifyPassword(String password, byte[] hash) {
        boolean returnValue = false;
        try {
            MessageDigest msgDigest = MessageDigest.getInstance("SHA-1");
            msgDigest.update(password.getBytes("UTF-8"));
            byte[] digest = msgDigest.digest();
            returnValue = Arrays.equals(hash, digest);
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(AuthentificationState.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(AuthentificationState.class.getName()).log(Level.SEVERE, null, ex);
        }
        return returnValue;
    }
@Override
    public void doExecute(String[] args) {
        if (args.length != 2) {
            printUsage();
        } else {
            int fileNo = 0;
            try {
                fileNo = Integer.parseInt(args[1]) - 1;
            } catch (NumberFormatException e) {
                printUsage();
                return;
            }
            if (fileNo < 0) {
                printUsage();
                return;
            }
            StorageFile[] files = (StorageFile[]) ctx.getRemoteDir().listFiles();
            try {
                StorageFile file = files[fileNo];
                File outFile = getOutFile(file);
                FileOutputStream out = new FileOutputStream(outFile);
                InputStream in = file.openStream();
                IOUtils.copy(in, out);
                IOUtils.closeQuietly(out);
                afterSave(outFile);
                if (outFile.exists()) {
                    print("File written to: " + outFile.getAbsolutePath());
                }
            } catch (IOException e) {
                printError("Failed to load file. " + e.getMessage());
            } catch (Exception e) {
                printUsage();
                return;
            }
        }
    }
static InputStream getUrlStream(String url) throws IOException {
        System.out.print("getting : " + url + " ... ");
        long start = System.currentTimeMillis();
        URLConnection c = new URL(url).openConnection();
        InputStream is = c.getInputStream();
        System.out.print((System.currentTimeMillis() - start) + "ms\n");
        return is;
    }
public static void copy(FileInputStream in, File destination) throws IOException {
        FileChannel srcChannel = null;
        FileChannel dstChannel = null;
        try {
            srcChannel = in.getChannel();
            dstChannel = new FileOutputStream(destination).getChannel();
            dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
        } finally {
            if (srcChannel != null) {
                srcChannel.close();
            }
            if (dstChannel != null) {
                dstChannel.close();
            }
        }
    }
public static void copyFile(String fromFile, String toFile) {
        FileInputStream from = null;
        FileOutputStream to = null;
        try {
            from = new FileInputStream(fromFile);
            to = new FileOutputStream(toFile);
            byte[] buffer = new byte[4096];
            int bytesRead;
            while ((bytesRead = from.read(buffer)) != -1) to.write(buffer, 0, bytesRead);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (from != null) try {
                from.close();
            } catch (IOException e) {
                ;
            }
            if (to != null) try {
                to.close();
            } catch (IOException e) {
                ;
            }
        }
    }
public boolean executeUpdate(String strSql) throws SQLException {
        getConnection();
        boolean flag = false;
        stmt = con.createStatement();
        logger.info("###############::执行SQL语句操作(更新数据 无参数):" + strSql);
        try {
            if (0 < stmt.executeUpdate(strSql)) {
                close_DB_Object();
                flag = true;
                con.commit();
            }
        } catch (SQLException ex) {
            logger.info("###############Error DBManager Line126::执行SQL语句操作(更新数据 无参数):" + strSql + "失败!");
            flag = false;
            con.rollback();
            throw ex;
        }
        return flag;
    }
public boolean executeUpdate(String strSql, HashMap<Integer, Object> prams) throws SQLException, ClassNotFoundException {
        getConnection();
        boolean flag = false;
        try {
            pstmt = con.prepareStatement(strSql);
            setParamet(pstmt, prams);
            logger.info("###############::执行SQL语句操作(更新数据 有参数):" + strSql);
            if (0 < pstmt.executeUpdate()) {
                close_DB_Object();
                flag = true;
                con.commit();
            }
        } catch (SQLException ex) {
            logger.info("###############Error DBManager Line121::执行SQL语句操作(更新数据 无参数):" + strSql + "失败!");
            flag = false;
            con.rollback();
            throw ex;
        } catch (ClassNotFoundException ex) {
            logger.info("###############Error DBManager Line152::执行SQL语句操作(更新数据 无参数):" + strSql + "失败! 参数设置类型错误!");
            con.rollback();
            throw ex;
        }
        return flag;
    }
public void run() {
        FileInputStream src;
        FileOutputStream dest;
        try {
            dest = new FileOutputStream(srcName);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return;
        }
        FileChannel destC = dest.getChannel();
        FileChannel srcC;
        ByteBuffer buf = ByteBuffer.allocateDirect(BUFFER_SIZE);
        try {
            int fileNo = 0;
            while (true) {
                int i = 1;
                String destName = srcName + "_" + fileNo;
                src = new FileInputStream(destName);
                srcC = src.getChannel();
                while ((i > 0)) {
                    i = srcC.read(buf);
                    buf.flip();
                    destC.write(buf);
                    buf.compact();
                }
                srcC.close();
                src.close();
                fileNo++;
            }
        } catch (IOException e1) {
            e1.printStackTrace();
            return;
        }
    }
@Override
    public List<SheetFullName> importSheets(INetxiliaSystem workbookProcessor, WorkbookId workbookName, URL url, IProcessingConsole console) throws ImportException {
        try {
            return importSheets(workbookProcessor, workbookName, url.openStream(), console);
        } catch (Exception e) {
            throw new ImportException(url, "Cannot open workbook:" + e, e);
        }
    }
public void copy(File src, File dest) throws FileNotFoundException, IOException {
        FileInputStream srcStream = new FileInputStream(src);
        FileOutputStream destStream = new FileOutputStream(dest);
        FileChannel srcChannel = srcStream.getChannel();
        FileChannel destChannel = destStream.getChannel();
        srcChannel.transferTo(0, srcChannel.size(), destChannel);
        destChannel.close();
        srcChannel.close();
        destStream.close();
        srcStream.close();
    }