Class EndstreamOutputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable

    class EndstreamOutputStream
    extends java.io.BufferedOutputStream
    This class is only for the readUntilEndStream method, to prevent a final CR LF or LF (but not a final CR!) from being written to the output, unless the beginning of the stream is assumed to be ASCII. Only the 3-param write() method is implemented. This solves PDFBOX-2079 and PDFBOX-2120 and avoids making readUntilEndStream() even more complex than it already is.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private boolean hasCR  
      private boolean hasLF  
      private boolean mustFilter  
      private int pos  
      • Fields inherited from class java.io.BufferedOutputStream

        buf, count
      • Fields inherited from class java.io.FilterOutputStream

        out
    • Constructor Summary

      Constructors 
      Constructor Description
      EndstreamOutputStream​(java.io.OutputStream out)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void flush()
      write out a single CR if one was kept.
      void write​(byte[] b, int off, int len)
      Write CR and/or LF that were kept, then writes len bytes from the specified byte array starting at offset off to this output stream, except trailing CR, CR LF, or LF.
      • Methods inherited from class java.io.BufferedOutputStream

        write
      • Methods inherited from class java.io.FilterOutputStream

        close, write
      • Methods inherited from class java.io.OutputStream

        nullOutputStream
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • hasCR

        private boolean hasCR
      • hasLF

        private boolean hasLF
      • pos

        private int pos
      • mustFilter

        private boolean mustFilter
    • Constructor Detail

      • EndstreamOutputStream

        EndstreamOutputStream​(java.io.OutputStream out)
    • Method Detail

      • write

        public void write​(byte[] b,
                          int off,
                          int len)
                   throws java.io.IOException
        Write CR and/or LF that were kept, then writes len bytes from the specified byte array starting at offset off to this output stream, except trailing CR, CR LF, or LF. No filtering will be done for the entire stream if the beginning is assumed to be ASCII.
        Overrides:
        write in class java.io.BufferedOutputStream
        Parameters:
        b - byte array.
        off - offset.
        len - length of segment to write.
        Throws:
        java.io.IOException
      • flush

        public void flush()
                   throws java.io.IOException
        write out a single CR if one was kept. Don't write kept CR LF or LF, and then call the base method to flush.
        Specified by:
        flush in interface java.io.Flushable
        Overrides:
        flush in class java.io.BufferedOutputStream
        Throws:
        java.io.IOException