Class AbstractTextFormatWriter
java.lang.Object
org.apache.commons.geometry.io.core.utils.AbstractTextFormatWriter
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Direct Known Subclasses:
ObjWriter
,TextFacetDefinitionWriter
,TextStlWriter
Base type for classes that write text-based data formats. This class
provides a number of common configuration options and utility methods.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final String
The default line separator value.private DoubleFunction
<String> Double format function.private String
Line separator string.private final Writer
Underlying writer instance. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractTextFormatWriter
(Writer writer) Construct a new instance that writes content to the given writer.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. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Get the function used to format floating point output.Get the current line separator.protected Writer
Get the underlying writer instance.void
setDoubleFormat
(DoubleFunction<String> doubleFormat) Set the function used to format floating point output.void
setLineSeparator
(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 a string.protected void
Write the configured line separator to the output.
-
Field Details
-
DEFAULT_LINE_SEPARATOR
The default line separator value.- See Also:
-
writer
Underlying writer instance. -
lineSeparator
Line separator string. -
doubleFormat
Double format function.
-
-
Constructor Details
-
AbstractTextFormatWriter
Construct a new instance that writes content to the given writer.- Parameters:
writer
- writer instance
-
AbstractTextFormatWriter
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 instancedoubleFormat
- double format function
-
-
Method Details
-
getLineSeparator
Get the current line separator. This value defaults to "\n".- Returns:
- the current line separator
-
setLineSeparator
Set the line separator.- Parameters:
lineSeparator
- the line separator to use
-
getDoubleFormat
Get the function used to format floating point output.- Returns:
- the double format function
-
setDoubleFormat
Set the function used to format floating point output.- Parameters:
doubleFormat
- double format function
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
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
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
-