Package org.apache.commons.codec.binary
Class BaseNCodecOutputStream<C extends BaseNCodec,T extends BaseNCodecOutputStream<C,T,B>,B extends BaseNCodecOutputStream.AbstractBuilder<T,C,B>>
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- org.apache.commons.codec.binary.BaseNCodecOutputStream<C,T,B>
-
- Type Parameters:
C- A BaseNCodec subclass.T- A BaseNCodecInputStream subclass.B- A subclass.
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
- Direct Known Subclasses:
Base16OutputStream,Base32OutputStream,Base64OutputStream
public class BaseNCodecOutputStream<C extends BaseNCodec,T extends BaseNCodecOutputStream<C,T,B>,B extends BaseNCodecOutputStream.AbstractBuilder<T,C,B>> 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
- See Also:
Base16OutputStream,Base32OutputStream,Base64OutputStream
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBaseNCodecOutputStream.AbstractBuilder<T,C extends BaseNCodec,B extends BaseNCodecOutputStream.AbstractBuilder<T,C,B>>Builds output stream instances inBaseNCodecformat.
-
Constructor Summary
Constructors Modifier Constructor Description BaseNCodecOutputStream(java.io.OutputStream outputStream, C basedCodec, boolean doEncode)Constructs a new instance.protectedBaseNCodecOutputStream(BaseNCodecOutputStream.AbstractBuilder<T,C,B> builder)Constructs a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes this output stream and releases any system resources associated with the stream.voideof()Writes EOF.voidflush()Flushes this output stream and forces any buffered output bytes to be written out to the stream.booleanisStrictDecoding()Returns true if decoding behavior is strict.voidwrite(byte[] array, int offset, int len)Writeslenbytes from the specifiedbarray starting atoffsetto this output stream.voidwrite(int i)Writes the specifiedbyteto this output stream.
-
-
-
Constructor Detail
-
BaseNCodecOutputStream
protected BaseNCodecOutputStream(BaseNCodecOutputStream.AbstractBuilder<T,C,B> builder)
Constructs a new instance.- Parameters:
builder- A builder.- Since:
- 1.20.0
-
BaseNCodecOutputStream
public BaseNCodecOutputStream(java.io.OutputStream outputStream, C basedCodec, boolean doEncode)
Constructs a new instance. TODO should this be protected?- Parameters:
outputStream- 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:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.FilterOutputStream- Throws:
java.io.IOException- if an I/O error occurs.
-
eof
public void eof()
Writes EOF.- 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:
flushin interfacejava.io.Flushable- Overrides:
flushin 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 anIllegalArgumentExceptionif 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
Writeslenbytes from the specifiedbarray starting atoffsetto this output stream.- Overrides:
writein classjava.io.FilterOutputStream- Parameters:
array- source byte array.offset- where to start reading the bytes.len- 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 null.java.lang.IndexOutOfBoundsException- if offset, len or buffer size are invalid.
-
write
public void write(int i) throws java.io.IOException
Writes the specifiedbyteto this output stream.- Overrides:
writein classjava.io.FilterOutputStream- Parameters:
i- source byte.- Throws:
java.io.IOException- if an I/O error occurs.
-
-