Class AbstractTextFormatWriter

java.lang.Object
org.apache.commons.geometry.io.core.utils.AbstractTextFormatWriter
All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
ObjWriter, TextFacetDefinitionWriter, TextStlWriter

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

    • DEFAULT_LINE_SEPARATOR

      private static final String DEFAULT_LINE_SEPARATOR
      The default line separator value.
      See Also:
    • writer

      private final Writer writer
      Underlying writer instance.
    • lineSeparator

      private String lineSeparator
      Line separator string.
    • doubleFormat

      private DoubleFunction<String> doubleFormat
      Double format function.
  • Constructor Details

    • AbstractTextFormatWriter

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

      protected AbstractTextFormatWriter(Writer writer, DoubleFunction<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 Details

    • getLineSeparator

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

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

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

      public void setDoubleFormat(DoubleFunction<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 AutoCloseable
      Specified by:
      close in interface Closeable
    • getWriter

      protected 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:
      UncheckedIOException - if an I/O error occurs
    • write

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

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

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

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