class ExtractXMP implements Callable<Integer>
{
    // Expected for CLI app to write to System.out/System.err
    @SuppressWarnings("squid:S106")
    private final PrintStream SYSOUT;
    @SuppressWarnings("squid:S106")
    private final PrintStream SYSERR;

    @CommandLine.Option(names = "-page", description = "extract the XMP information from a specific page (1 based)")
    private int page = 0;

    @CommandLine.Option(names = "-password", description = "the password for the PDF or certificate in keystore.", arity = "0..1", interactive = true)    
    private String password = "";

    @CommandLine.Option(names = "-console", description = "Send text to console instead of file")
    private boolean toConsole = false;

    @CommandLine.Option(names = {"-i", "--input"}, description = "the PDF file", required = true)
    private File infile;

    @CommandLine.Option(names = {"-o", "--output"}, description = "the exported text file")
    private File outfile;

    /**
     * Constructor.
     */
    public ExtractXMP()
    {
        SYSOUT = System.out;
        SYSERR = System.err;
    }

    /**
     * Infamous main method.
     *
     * @param args Command line arguments, should be one and a reference to a file.
     */
    public static void main(String[] args)
    {
        // suppress the Dock icon on OS X
        System.setProperty("apple.awt.UIElement", "true");

        int exitCode = new CommandLine(new ExtractXMP()).execute(args);
        System.exit(exitCode);
    }

    /**
     * Starts the xmp extraction.
     */
    @Override
    public Integer call()
    {<FILL_FUNCTION_BODY>}    
}

        if (outfile == null)
        {
            String outPath = FilenameUtils.removeExtension(infile.getAbsolutePath()) + ".xml";
            outfile = new File(outPath);
        }
        
        try (PDDocument document = Loader.loadPDF(infile, password))
        {
            PDDocumentCatalog catalog = document.getDocumentCatalog();
            PDMetadata meta;
            if (page == 0)
            {
                meta = catalog.getMetadata();
            }
            else
            {
                if (page > document.getNumberOfPages())
                {
                    SYSERR.println("Page " + page + " doesn't exist");
                    return 1;
                }
                meta = document.getPage(page - 1).getMetadata();
            }
            if (meta == null)
            {
                SYSERR.println("No XMP metadata available");
                return 1;
            }
            try (PrintStream ps = toConsole ? SYSOUT : new PrintStream(outfile))
            {
                ps.write(meta.toByteArray());
            }
        }
        catch (IOException ioe)
        {
            SYSERR.println( "Error extracting text for document [" + ioe.getClass().getSimpleName() + "]: " + ioe.getMessage());
            return 4;
        }

        return 0;
    
<no_super_class>