Class BasicHeaderPrintWriter

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

    class BasicHeaderPrintWriter
    extends java.io.PrintWriter
    implements HeaderPrintWriter
    Basic class to print lines with headers.

    STUB: Should include code to emit a new line before a header which is not the first thing on the line.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private boolean canClose  
      private PrintWriterGetHeader headerGetter  
      private java.lang.String name  
      • Fields inherited from class java.io.PrintWriter

        out
      • Fields inherited from class java.io.Writer

        lock
    • Constructor Summary

      Constructors 
      Constructor Description
      BasicHeaderPrintWriter​(java.io.OutputStream writeTo, PrintWriterGetHeader headerGetter, boolean canClose, java.lang.String streamName)
      the constructor sets up the HeaderPrintWriter.
      BasicHeaderPrintWriter​(java.io.Writer writeTo, PrintWriterGetHeader headerGetter, boolean canClose, java.lang.String writerName)
      the constructor sets up the HeaderPrintWriter.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) void complete()
      Flushes stream, and optionally also closes it if constructed with canClose equal to true.
      PrintWriterGetHeader getHeader()
      Return the header for the stream.
      java.lang.String getName()
      Gets the name of the wrapped writer or stream
      java.io.PrintWriter getPrintWriter()
      Gets a PrintWriter object for writing to this HeaderPrintWriter.
      void printlnWithHeader​(java.lang.String message)
      Puts out some setup info for the current write and the write(s) that will be put out next.
      • Methods inherited from class java.io.PrintWriter

        append, append, append, checkError, clearError, close, flush, format, format, print, print, print, print, print, print, print, print, print, printf, printf, println, println, println, println, println, println, println, println, println, println, setError, write, write, write, write, write
      • Methods inherited from class java.io.Writer

        nullWriter
      • Methods inherited from class java.lang.Object

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

      • canClose

        private final boolean canClose
      • name

        private final java.lang.String name
    • Constructor Detail

      • BasicHeaderPrintWriter

        BasicHeaderPrintWriter​(java.io.OutputStream writeTo,
                               PrintWriterGetHeader headerGetter,
                               boolean canClose,
                               java.lang.String streamName)
        the constructor sets up the HeaderPrintWriter.

        Parameters:
        writeTo - Where to write to.
        headerGetter - Object to get headers for output lines.
        canClose - If true, complete() will also close writeTo
        streamName - Name of writeTo, e.g. a file name
        See Also:
        PrintWriterGetHeader
      • BasicHeaderPrintWriter

        BasicHeaderPrintWriter​(java.io.Writer writeTo,
                               PrintWriterGetHeader headerGetter,
                               boolean canClose,
                               java.lang.String writerName)
        the constructor sets up the HeaderPrintWriter.

        Parameters:
        writeTo - Where to write to.
        headerGetter - Object to get headers for output lines.
        canClose - If true, complete() will also close writeTo
        writerName - Name of writeTo, e.g. a file name
        See Also:
        PrintWriterGetHeader
    • Method Detail

      • printlnWithHeader

        public void printlnWithHeader​(java.lang.String message)
        Description copied from interface: HeaderPrintWriter
        Puts out some setup info for the current write and the write(s) that will be put out next. It ends with a \n\r.

        All other writes to the stream use the PrintStream interface.

        Specified by:
        printlnWithHeader in interface HeaderPrintWriter
      • getPrintWriter

        public java.io.PrintWriter getPrintWriter()
        Description copied from interface: HeaderPrintWriter
        Gets a PrintWriter object for writing to this HeaderPrintWriter. Users may use the HeaderPrintWriter to access methods not included in this interface or to invoke methods or constructors which require a PrintWriter. Interleaving calls to a printWriter and its associated HeaderPrintWriter is not supported.
        Specified by:
        getPrintWriter in interface HeaderPrintWriter
      • complete

        void complete()
        Flushes stream, and optionally also closes it if constructed with canClose equal to true.