class FileOpenSaveDialog
{
    private final Component mainUI;

    private static final JFileChooser FILE_CHOOSER = new JFileChooser()
    {
        @Override
        public void approveSelection()
        {
            File selectedFile = getSelectedFile();
            if (selectedFile.exists() && getDialogType() == JFileChooser.SAVE_DIALOG)
            {
                int result = JOptionPane.showConfirmDialog(this,
                    "Do you want to overwrite?",
                    "File already exists",
                    JOptionPane.YES_NO_OPTION);
                if (result != JOptionPane.YES_OPTION)
                {
                    cancelSelection();
                    return;
                }
            }
            super.approveSelection();
        }
    };

    /**
     * Constructor.
     * @param parentUI the main UI (JFrame) on top of which File open/save dialog should open.
     * @param fileFilter file Filter, null is allowed when no filter is applicable.
     */
    public FileOpenSaveDialog(Component parentUI, FileFilter fileFilter)
    {
        mainUI = parentUI;
        FILE_CHOOSER.resetChoosableFileFilters();
        FILE_CHOOSER.setFileFilter(fileFilter);
    }

    /**
     * Saves data into a file after the user is prompted to choose the destination.
     *
     * @param bytes byte array to be saved in a file.
     * @param extension file extension.
     * @return true if the file is saved successfully or false if failed.
     * @throws IOException if there is an error in creation of the file.
     */
    public boolean saveFile(byte[] bytes, String extension) throws IOException
    {<FILL_FUNCTION_BODY>}

    /**
     * Saves document into a .pdf file after the user is prompted to choose the destination.
     *
     * @param document document to be saved in a .pdf file.
     * @param extension file extension.
     * @return true if the file is saved successfully or false if failed.
     * @throws IOException if there is an error in creation of the file.
     */
    public boolean saveDocument(PDDocument document, String extension) throws IOException
    {
        int result = FILE_CHOOSER.showSaveDialog(mainUI);
        if (result == JFileChooser.APPROVE_OPTION)
        {
            String filename = FILE_CHOOSER.getSelectedFile().getAbsolutePath();
            if (!filename.endsWith(extension))
            {
                filename += "." + extension;
            }
            document.setAllSecurityToBeRemoved(true);
            document.save(filename);
            return true;
        }
        return false;
    }

    /**
     * open a file prompting user to select the file.
     * @return the file opened.
     * @throws IOException if there is error in opening the file.
     */
    public File openFile() throws IOException
    {
        int result = FILE_CHOOSER.showOpenDialog(mainUI);
        if (result == JFileChooser.APPROVE_OPTION)
        {
            return FILE_CHOOSER.getSelectedFile();
        }
        return null;
    }
}

        int result = FILE_CHOOSER.showSaveDialog(mainUI);
        if (result == JFileChooser.APPROVE_OPTION)
        {
            String filename = FILE_CHOOSER.getSelectedFile().getAbsolutePath();
            if (extension != null && !filename.endsWith(extension))
            {
                filename += "." + extension;
            }
            Files.write(Paths.get(filename), bytes);
            return true;
        }
        return false;
    
<no_super_class>