Package org.apache.commons.codec.binary
Class BaseNCodecOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- org.apache.commons.codec.binary.BaseNCodecOutputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
- Direct Known Subclasses:
Base16OutputStream
,Base32OutputStream
,Base64OutputStream
public class BaseNCodecOutputStream extends java.io.FilterOutputStream
Abstract superclass for Base-N output streams.To write the EOF marker without closing the stream, call
eof()
or use an Apache Commons IO CloseShieldOutputStream.- Since:
- 1.5
-
-
Constructor Summary
Constructors Constructor Description BaseNCodecOutputStream(java.io.OutputStream output, BaseNCodec basedCodec, boolean doEncode)
TODO should this be protected?
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes this output stream and releases any system resources associated with the stream.void
eof()
Writes EOF.void
flush()
Flushes this output stream and forces any buffered output bytes to be written out to the stream.boolean
isStrictDecoding()
Returns true if decoding behavior is strict.void
write(byte[] array, int offset, int len)
Writeslen
bytes from the specifiedb
array starting atoffset
to this output stream.void
write(int i)
Writes the specifiedbyte
to this output stream.
-
-
-
Constructor Detail
-
BaseNCodecOutputStream
public BaseNCodecOutputStream(java.io.OutputStream output, BaseNCodec basedCodec, boolean doEncode)
TODO should this be protected?- Parameters:
output
- the underlying output or null.basedCodec
- a BaseNCodec.doEncode
- true to encode, false to decode, TODO should be an enum?
-
-
Method Detail
-
close
public void close() throws java.io.IOException
Closes this output stream and releases any system resources associated with the stream.To write the EOF marker without closing the stream, call
eof()
or use an Apache Commons IO CloseShieldOutputStream.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.FilterOutputStream
- Throws:
java.io.IOException
- if an I/O error occurs.
-
eof
public void eof() throws java.io.IOException
Writes EOF.- Throws:
java.io.IOException
- if an I/O error occurs.- Since:
- 1.11
-
flush
public void flush() throws java.io.IOException
Flushes this output stream and forces any buffered output bytes to be written out to the stream.- Specified by:
flush
in interfacejava.io.Flushable
- Overrides:
flush
in classjava.io.FilterOutputStream
- Throws:
java.io.IOException
- if an I/O error occurs.
-
isStrictDecoding
public boolean isStrictDecoding()
Returns true if decoding behavior is strict. Decoding will raise anIllegalArgumentException
if trailing bits are not part of a valid encoding.The default is false for lenient encoding. Decoding will compose trailing bits into 8-bit bytes and discard the remainder.
- Returns:
- true if using strict decoding
- Since:
- 1.15
-
write
public void write(byte[] array, int offset, int len) throws java.io.IOException
Writeslen
bytes from the specifiedb
array starting atoffset
to this output stream.- Overrides:
write
in classjava.io.FilterOutputStream
- Parameters:
array
- source byte arrayoffset
- where to start reading the byteslen
- maximum number of bytes to write- Throws:
java.io.IOException
- if an I/O error occurs.java.lang.NullPointerException
- if the byte array parameter is nulljava.lang.IndexOutOfBoundsException
- if offset, len or buffer size are invalid
-
write
public void write(int i) throws java.io.IOException
Writes the specifiedbyte
to this output stream.- Overrides:
write
in classjava.io.FilterOutputStream
- Parameters:
i
- source byte- Throws:
java.io.IOException
- if an I/O error occurs.
-
-