Skip to content

Commit fb09a1d

Browse files
committed
[CODEC-183] BaseNCodecOutputStream only supports writing EOF on close().
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@1640000 13f79535-47bb-0310-9956-ffa450edef68
1 parent 9bc3701 commit fb09a1d

1 file changed

Lines changed: 25 additions & 3 deletions

File tree

src/main/java/org/apache/commons/codec/binary/BaseNCodecOutputStream.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@
2727

2828
/**
2929
* Abstract superclass for Base-N output streams.
30-
*
30+
* <p>
31+
* To write the EOF marker without closing the stream, call {@link #eof()} or use an <a
32+
* href="https://commons.apache.org/proper/commons-io/">Apache Commons IO</a> <a href=
33+
* "https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/output/CloseShieldOutputStream.html"
34+
* >CloseShieldOutputStream</a>.
35+
* </p>
36+
*
3137
* @since 1.5
3238
* @version $Id$
3339
*/
@@ -134,20 +140,36 @@ public void flush() throws IOException {
134140

135141
/**
136142
* Closes this output stream and releases any system resources associated with the stream.
143+
* <p>
144+
* To write the EOF marker without closing the stream, call {@link #eof()} or use an
145+
* <a href="https://commons.apache.org/proper/commons-io/">Apache Commons IO</a> <a href=
146+
* "https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/output/CloseShieldOutputStream.html"
147+
* >CloseShieldOutputStream</a>.
148+
* </p>
137149
*
138150
* @throws IOException
139151
* if an I/O error occurs.
140152
*/
141153
@Override
142154
public void close() throws IOException {
155+
eof();
156+
flush();
157+
out.close();
158+
}
159+
160+
/**
161+
* Writes EOF.
162+
*
163+
* @throws IOException
164+
* if an I/O error occurs.
165+
*/
166+
public void eof() throws IOException {
143167
// Notify encoder of EOF (-1).
144168
if (doEncode) {
145169
baseNCodec.encode(singleByte, 0, EOF, context);
146170
} else {
147171
baseNCodec.decode(singleByte, 0, EOF, context);
148172
}
149-
flush();
150-
out.close();
151173
}
152174

153175
}

0 commit comments

Comments
 (0)