Class AbstractTextFormatWriter

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable
    Direct Known Subclasses:
    ObjWriter, TextFacetDefinitionWriter, TextStlWriter

    public abstract class AbstractTextFormatWriter
    extends java.lang.Object
    implements java.io.Closeable
    Base type for classes that write text-based data formats. This class provides a number of common configuration options and utility methods.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String DEFAULT_LINE_SEPARATOR
      The default line separator value.
      private java.util.function.DoubleFunction<java.lang.String> doubleFormat
      Double format function.
      private java.lang.String lineSeparator
      Line separator string.
      private java.io.Writer writer
      Underlying writer instance.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected AbstractTextFormatWriter​(java.io.Writer writer)
      Construct a new instance that writes content to the given writer.
      protected AbstractTextFormatWriter​(java.io.Writer writer, java.util.function.DoubleFunction<java.lang.String> doubleFormat)
      Construct a new instance that writes content to the given writer and uses the decimal format instance for creating floating-point string representations.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      java.util.function.DoubleFunction<java.lang.String> getDoubleFormat()
      Get the function used to format floating point output.
      java.lang.String getLineSeparator()
      Get the current line separator.
      protected java.io.Writer getWriter()
      Get the underlying writer instance.
      void setDoubleFormat​(java.util.function.DoubleFunction<java.lang.String> doubleFormat)
      Set the function used to format floating point output.
      void setLineSeparator​(java.lang.String lineSeparator)
      Set the line separator.
      protected void write​(char c)
      Write a char value.
      protected void write​(double d)
      Write a double value formatted using the configured decimal format function.
      protected void write​(int n)
      Write an integer value.
      protected void write​(java.lang.String str)
      Write a string.
      protected void writeNewLine()
      Write the configured line separator to the output.
      • Methods inherited from class java.lang.Object

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

      • DEFAULT_LINE_SEPARATOR

        private static final java.lang.String DEFAULT_LINE_SEPARATOR
        The default line separator value.
        See Also:
        Constant Field Values
      • writer

        private final java.io.Writer writer
        Underlying writer instance.
      • lineSeparator

        private java.lang.String lineSeparator
        Line separator string.
      • doubleFormat

        private java.util.function.DoubleFunction<java.lang.String> doubleFormat
        Double format function.
    • Constructor Detail

      • AbstractTextFormatWriter

        protected AbstractTextFormatWriter​(java.io.Writer writer)
        Construct a new instance that writes content to the given writer.
        Parameters:
        writer - writer instance
      • AbstractTextFormatWriter

        protected AbstractTextFormatWriter​(java.io.Writer writer,
                                           java.util.function.DoubleFunction<java.lang.String> doubleFormat)
        Construct a new instance that writes content to the given writer and uses the decimal format instance for creating floating-point string representations.
        Parameters:
        writer - writer instance
        doubleFormat - double format function
    • Method Detail

      • getLineSeparator

        public java.lang.String getLineSeparator()
        Get the current line separator. This value defaults to "\n".
        Returns:
        the current line separator
      • setLineSeparator

        public void setLineSeparator​(java.lang.String lineSeparator)
        Set the line separator.
        Parameters:
        lineSeparator - the line separator to use
      • getDoubleFormat

        public java.util.function.DoubleFunction<java.lang.String> getDoubleFormat()
        Get the function used to format floating point output.
        Returns:
        the double format function
      • setDoubleFormat

        public void setDoubleFormat​(java.util.function.DoubleFunction<java.lang.String> doubleFormat)
        Set the function used to format floating point output.
        Parameters:
        doubleFormat - double format function
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
      • getWriter

        protected java.io.Writer getWriter()
        Get the underlying writer instance.
        Returns:
        writer instance
      • write

        protected void write​(double d)
        Write a double value formatted using the configured decimal format function.
        Parameters:
        d - value to write
        Throws:
        java.io.UncheckedIOException - if an I/O error occurs
      • write

        protected void write​(int n)
        Write an integer value.
        Parameters:
        n - value to write
        Throws:
        java.io.UncheckedIOException - if an I/O error occurs
      • write

        protected void write​(char c)
        Write a char value.
        Parameters:
        c - character to write
        Throws:
        java.io.UncheckedIOException - if an I/O error occurs
      • write

        protected void write​(java.lang.String str)
        Write a string.
        Parameters:
        str - string to write
        Throws:
        java.io.UncheckedIOException - if an I/O error occurs
      • writeNewLine

        protected void writeNewLine()
        Write the configured line separator to the output.
        Throws:
        java.io.UncheckedIOException - if an I/O error occurs