Package org.matsim.core.utils.io
Class AbstractMatsimWriter
- java.lang.Object
-
- org.matsim.core.utils.io.AbstractMatsimWriter
-
- Direct Known Subclasses:
MatsimXmlWriter
,PopulationWriter
public abstract class AbstractMatsimWriter extends Object
A simple, abstract helper class to open files for writing with support for gzip-compression.- Author:
- mrieser
-
-
Field Summary
Fields Modifier and Type Field Description protected static String
NL
The Unix newline character.protected Boolean
useCompression
Whether or not the output is gzip-compressed.protected BufferedWriter
writer
The writer output can be written to.
-
Constructor Summary
Constructors Constructor Description AbstractMatsimWriter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
close()
Closes the file if it is still open.protected void
openFile(String filename)
Opens the specified file for writing.protected void
openOutputStream(OutputStream outputStream)
Uses the specified OutputStream for writing.void
useCompression(boolean useCompression)
Sets whether the file should be gzip-compressed or not.
-
-
-
Field Detail
-
NL
protected static final String NL
The Unix newline character.- See Also:
- Constant Field Values
-
writer
protected BufferedWriter writer
The writer output can be written to.
-
useCompression
protected Boolean useCompression
Whether or not the output is gzip-compressed. Ifnull
, the usage of compression is decided by the filename (whether it ends with .gz or not).
-
-
Constructor Detail
-
AbstractMatsimWriter
public AbstractMatsimWriter()
-
-
Method Detail
-
useCompression
public final void useCompression(boolean useCompression)
Sets whether the file should be gzip-compressed or not. Must be set before the file is opened for writing. If not set explicitly, the usage of compression is defined by the ending of the filename.- Parameters:
useCompression
-
-
openFile
protected final void openFile(String filename) throws UncheckedIOException
Opens the specified file for writing.- Parameters:
filename
-- Throws:
UncheckedIOException
-
openOutputStream
protected final void openOutputStream(OutputStream outputStream)
Uses the specified OutputStream for writing.
-
close
protected final void close() throws UncheckedIOException
Closes the file if it is still open.- Throws:
UncheckedIOException
-
-