class SignatureOptions implements Closeable
{
    private COSDocument visualSignature;
    private int preferredSignatureSize;
    private int pageNo;

    // the pdf to be read
    // this is done analog to PDDocument
    private RandomAccessRead pdfSource = null;

    public static final int DEFAULT_SIGNATURE_SIZE = 0x2500;

    /**
     * Creates the default signature options.
     */
    public SignatureOptions()
    {
        pageNo = 0;
    }

    /**
     * Set the 0-based page number.
     *
     * @param pageNo the page number
     */
    public void setPage(int pageNo)
    {
        this.pageNo = pageNo;
    }

    /**
     * Get the 0-based page number.
     *
     * @return the page number
     */
    public int getPage()
    {
        return pageNo;
    }

    /**
     * Reads the visual signature from the given file.
     *
     * @param file the file containing the visual signature
     * @throws IOException when something went wrong during parsing
     */
    public void setVisualSignature(File file) throws IOException
    {
        initFromRandomAccessRead(new RandomAccessReadBufferedFile(file));
    }

    /**
     * Reads the visual signature from the given input stream.
     *
     * @param is the input stream containing the visual signature
     * @throws IOException when something went wrong during parsing
     */
    public void setVisualSignature(InputStream is) throws IOException
    {
        initFromRandomAccessRead(new RandomAccessReadBuffer(is));
    }
    
    private void initFromRandomAccessRead(RandomAccessRead rar) throws IOException
    {
        pdfSource = rar;
        PDFParser parser = new PDFParser(pdfSource);
        visualSignature = parser.parse().getDocument();
    }

    /**
     * Reads the visual signature from the given visual signature properties
     *
     * @param visSignatureProperties the <code>PDVisibleSigProperties</code> object containing the
     * visual signature
     *
     * @throws IOException when something went wrong during parsing
     */
    public void setVisualSignature(PDVisibleSigProperties visSignatureProperties) throws IOException
    {
        setVisualSignature(visSignatureProperties.getVisibleSignature());
    }

    /**
     * Get the visual signature.
     *
     * @return the visual signature
     */
    public COSDocument getVisualSignature()
    {
        return visualSignature;
    }

    /**
     * Get the preferred size of the signature.
     *
     * @return the preferred size of the signature in bytes.
     */
    public int getPreferredSignatureSize()
    {
        return preferredSignatureSize;
    }

    /**
     * Set the preferred size of the signature.
     *
     * @param size the size of the signature in bytes. Only values above 0 will be considered.
     */
    public void setPreferredSignatureSize(int size)
    {
        if (size > 0)
        {
            preferredSignatureSize = size;
        }
    }

    /**
     * Closes the visual signature COSDocument, if any. Do not call this before you're saved your
     * signed PDF document, or saving will fail because COSStream objects held both by the
     * COSDocument and by the signed document would no longer be available.
     *
     * @throws IOException if the document could not be closed
     */
    @Override
    public void close() throws IOException
    {<FILL_FUNCTION_BODY>}
}

        try
        {
            if (visualSignature != null)
            {
                visualSignature.close();
            }
        }
        finally
        {
            if (pdfSource != null)
            {
                pdfSource.close();
            }
        }
    
<no_super_class>