class PdfLister {

    /**
     * the printStream you want to write the output to.
     */
    PrintStream out;

    /**
     * Create a new lister object.
     *
     * @param out the PrintStream to write the output to
     */
    public PdfLister(PrintStream out) {
        this.out = out;
    }

    /**
     * Visualizes a PDF object.
     *
     * @param object a com.lowagie.text.pdf object
     */
    public void listAnyObject(PdfObject object) {
        switch (object.type()) {
            case PdfObject.ARRAY:
                listArray((PdfArray) object);
                break;
            case PdfObject.DICTIONARY:
                listDict((PdfDictionary) object);
                break;
            case PdfObject.STRING:
                out.println("(" + object.toString() + ")");
                break;
            default:
                out.println(object.toString());
                break;
        }
    }

    /**
     * Visualizes a PdfDictionary object.
     *
     * @param dictionary a com.lowagie.text.pdf.PdfDictionary object
     */
    public void listDict(PdfDictionary dictionary) {
        out.println("<<");
        PdfName key;
        PdfObject value;
        for (PdfName pdfName : dictionary.getKeys()) {
            key = pdfName;
            value = dictionary.get(key);
            out.print(key.toString());
            out.print(' ');
            listAnyObject(value);
        }
        out.println(">>");
    }

    /**
     * Visualizes a PdfArray object.
     *
     * @param array a com.lowagie.text.pdf.PdfArray object
     */
    public void listArray(PdfArray array) {
        out.println('[');
        array.getElements().forEach(this::listAnyObject);
        out.println(']');
    }

    /**
     * Visualizes a Stream.
     *
     * @param stream the stream to read from
     * @param reader not used currently
     */
    public void listStream(PRStream stream, PdfReaderInstance reader) {<FILL_FUNCTION_BODY>}

    /**
     * Visualizes an imported page
     *
     * @param iPage the imported page
     */
    public void listPage(PdfImportedPage iPage) {
        int pageNum = iPage.getPageNumber();
        PdfReaderInstance readerInst = iPage.getPdfReaderInstance();
        PdfReader reader = readerInst.getReader();

        PdfDictionary page = reader.getPageN(pageNum);
        listDict(page);
        PdfObject obj = PdfReader.getPdfObject(page.get(PdfName.CONTENTS));
        if (obj == null) {
            return;
        }
        switch (obj.type) {
            case PdfObject.STREAM:
                listStream((PRStream) obj, readerInst);
                break;
            case PdfObject.ARRAY:
                for (PdfObject pdfObject : ((PdfArray) obj).getElements()) {
                    PdfObject o = PdfReader.getPdfObject(pdfObject);
                    listStream((PRStream) o, readerInst);
                    out.println("-----------");
                }
                break;
        }
    }
}

        try {
            listDict(stream);
            out.println("startstream");
            byte[] b = PdfReader.getStreamBytes(stream);
//                  byte buf[] = new byte[Math.min(stream.getLength(), 4096)];
//                  int r = 0;
//                  stream.openStream(reader);
//                  for (;;) {
//                      r = stream.readStream(buf, 0, buf.length);
//                      if (r == 0) break;
//                      out.write(buf, 0, r);
//                  }
//                  stream.closeStream();
            int len = b.length - 1;
            for (int k = 0; k < len; ++k) {
                if (b[k] == '\r' && b[k + 1] != '\n') {
                    b[k] = (byte) '\n';
                }
            }
            out.println(new String(b));
            out.println("endstream");
        } catch (IOException e) {
            System.err.println("I/O exception: " + e);
//          } catch (java.util.zip.DataFormatException e) {
//              System.err.println("Data Format Exception: " + e);
        }
    
<no_super_class>