21 package org.matsim.core.utils.io;
23 import java.io.BufferedWriter;
24 import java.io.IOException;
25 import java.io.OutputStream;
26 import java.io.OutputStreamWriter;
27 import java.io.UncheckedIOException;
28 import java.nio.charset.StandardCharsets;
29 import java.util.zip.GZIPOutputStream;
41 protected static final String
NL =
"\n";
44 protected BufferedWriter
writer = null;
68 protected final void openFile(
final String filename)
throws UncheckedIOException {
70 if (this.useCompression == null) {
84 if (this.useCompression == null || this.useCompression) {
85 this.writer =
new BufferedWriter(
new OutputStreamWriter(outputStream, StandardCharsets.UTF_8));
87 this.writer =
new BufferedWriter(
new OutputStreamWriter(
new GZIPOutputStream(outputStream), StandardCharsets.UTF_8));
89 }
catch (IOException e) {
90 throw new UncheckedIOException(e);
95 if (this.writer != null) {
105 protected final void close() throws UncheckedIOException {
106 if (this.writer != null) {
110 }
catch (IOException e) {
111 throw new UncheckedIOException(e);
static BufferedWriter getBufferedWriter(URL url, Charset charset, boolean append)
final void openOutputStream(OutputStream outputStream)
final void openFile(final String filename)
void assertNotAlreadyOpen()
final void useCompression(final boolean useCompression)