|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.io.OutputStream java.io.FilterOutputStream tribble.io.Base64DecoderOutputStream
public class Base64DecoderOutputStream
Base-64 decoding output stream.
Provides an I/O stream that decodes base-64 characters into binary data. Printable 8-bit characters that encode data as base-64 (a.k.a. radix-64) ASCII characters are converted into 8-bit bytes (octets) as they are written to the output stream.
See Base64Decoder
for more information about base-64
decoding.
Copyright ©2005-2009 by David R. Tribble, all rights reserved.
Permission is granted to any person or entity except those designated by
by the United States Department of State as a terrorist, or terrorist
government or agency, to use and distribute this source code provided
that the original copyright notice remains present and unaltered.
Base64DecoderInputStream
,
Base64EncoderOutputStream
,
Base64Decoder
Field Summary | |
---|---|
protected byte[] |
m_inBuf
Pending input queue, composed of groups of 8-bit octets. |
protected short |
m_inLen
Pending input queue length. |
protected byte[] |
m_outBuf
Output queue, composed of groups of 6-bit sextets. |
Fields inherited from class java.io.FilterOutputStream |
---|
out |
Constructor Summary | |
---|---|
Base64DecoderOutputStream(java.io.OutputStream out)
Constructor. |
Method Summary | |
---|---|
void |
close()
Flush and close this output stream. |
void |
decode(java.io.InputStream in)
Read and convert the contents of an input stream. |
void |
decode(java.io.InputStream in,
int bufLen)
Read and convert the contents of an input stream. |
static void |
decode(java.io.InputStream in,
java.io.OutputStream out)
Read and convert the contents of an input stream. |
static void |
decode(java.io.InputStream in,
java.io.OutputStream out,
int bufLen)
Read and convert the contents of an input stream. |
void |
finish()
Complete all pending output to this output stream. |
void |
flush()
Flush all pending output to this output stream. |
java.io.OutputStream |
getOutput()
Retrieve the underlying output stream for this output stream. |
static void |
main(java.lang.String[] args)
Test driver. |
void |
write(byte[] data,
int off,
int len)
Write a set of bytes to this output stream. |
void |
write(int c)
Write a byte to this output stream. |
protected void |
writePending()
Convert pending input data bytes into base-64 character bytes and write them to the output stream. |
Methods inherited from class java.io.FilterOutputStream |
---|
write |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected byte[] m_inBuf
protected byte[] m_outBuf
protected short m_inLen
Constructor Detail |
---|
public Base64DecoderOutputStream(java.io.OutputStream out)
out
- The underlying output stream for this output stream.
java.lang.NullPointerException
- (unchecked)
Thrown if out is null.Method Detail |
---|
public static void main(java.lang.String[] args) throws java.io.IOException
Usage
java tribble.io.Base64DecoderOutputStream [-o outfile] file...
args
- Command line arguments.
java.io.IOException
- Thrown if an I/O (write) error occurs.public static void decode(java.io.InputStream in, java.io.OutputStream out) throws java.io.IOException
decode
(in, out, 0).
in
- An input stream containing base-64 encoded character data to be converted
into binary 8-bit octet data.out
- An output stream to which is written the decoded binary 8-bit octet data
bytes.
java.io.IOException
- Thrown if an I/O (read or write) error occurs.
java.lang.NullPointerException
- (unchecked)
Thrown if in or out is null.decode()
public static void decode(java.io.InputStream in, java.io.OutputStream out, int bufLen) throws java.io.IOException
The entire contents of an input stream are read as base-64 encoded characters and converted into 8-bit octets, which are then written to an output stream.
Note that the output stream is finished and flushed after the converted
data is written, but is not closed, i.e., methods finish()
and flush()
are called but close()
is not.
in
- An input stream containing base-64 encoded character data to be converted
into binary 8-bit octet data.out
- An output stream to which is written the decoded binary 8-bit octet data
bytes.bufLen
- Specifies the size, in bytes, of the internal buffer to use for reading
data from the input stream. Specifying a value less than 4 causes a
default size of 64K (65,536) to be used.
java.io.IOException
- Thrown if an I/O (read or write) error occurs.
java.lang.NullPointerException
- (unchecked)
Thrown if in or out is null.decode()
public void finish() throws java.io.IOException
All pending base-64 character output is completed.
java.io.IOException
- Thrown if an I/O (write) error occurs.
java.lang.NullPointerException
- (unchecked)
Thrown if the underlying output stream is closed.flush()
public void flush() throws java.io.IOException
Any pending base-64 character output is written to the underlying output stream, then the underlying output stream itself is flushed.
Note that output characters may still remain pending after this operation
if the last bytes written to this stream do not constitute a complete
24-bit octet group. Use the finish()
method to force
completion of the output stream.
flush
in interface java.io.Flushable
flush
in class java.io.FilterOutputStream
java.io.IOException
- Thrown if an I/O (write) error occurs.
java.lang.NullPointerException
- (unchecked)
Thrown if the underlying output stream is closed.finish()
public void close() throws java.io.IOException
Any pending base-64 character output is completed, and the final padding characters (if any) are written to the underlying output stream.
Subsequent attempts to write to this output stream will cause exceptions to be thrown.
close
in interface java.io.Closeable
close
in class java.io.FilterOutputStream
java.io.IOException
- Thrown if an I/O (write) error occurs.finish()
,
flush()
public void write(int c) throws java.io.IOException
The 8-bit byte is converted into its corresponding base-64 character encoding before being written to the underlying output stream.
write
in class java.io.FilterOutputStream
c
- A character code.
Note that only the lower 8 bits are written to the underlying output
stream, and the upper 24 bits are ignored.
java.io.IOException
- Thrown if an I/O (write) error occurs.
java.lang.NullPointerException
- (unchecked)
Thrown if the underlying output stream is closed.public void write(byte[] data, int off, int len) throws java.io.IOException
The 8-bit bytes are converted into their corresponding base-64 character encoding before being written to the underlying output stream.
write
in class java.io.FilterOutputStream
data
- An array of bytes to write.off
- Index of the first byte within data to write.len
- Number of bytes from data to write.
java.io.IOException
- Thrown if an I/O (write) error occurs.
java.lang.NullPointerException
- (unchecked)
Thrown if the underlying output stream is closed.
java.lang.IndexOutOfBoundsException
- (unchecked)
Thrown if off or len specify a negative offset or
length.public java.io.OutputStream getOutput()
Note that this method is not specified by the standard
FilterOutputStream
library class, but is provided as a
convenient enhancement.
public void decode(java.io.InputStream in) throws java.io.IOException
decode
(in, 0).
in
- An input stream containing base-64 encoded character data to be converted
into binary 8-bit octet data.
java.io.IOException
- Thrown if an I/O (read or write) error occurs.
java.lang.NullPointerException
- (unchecked)
Thrown if in is null.decode()
public void decode(java.io.InputStream in, int bufLen) throws java.io.IOException
The entire contents of an input stream are read as base-64 encoded characters and converted into 8-bit octets, which are then written to this output stream.
Note that the output stream is finished and flushed after the converted
data is written, but is not closed, i.e., methods finish()
and flush()
are called but close()
is not.
in
- An input stream containing base-64 encoded character data to be converted
into binary 8-bit octet data.bufLen
- Specifies the size, in bytes, of the internal buffer to use for reading
data from the input stream. Specifying a value less than 4 causes a
default size of 64K (65,536) to be used.
java.io.IOException
- Thrown if an I/O (read or write) error occurs.
java.lang.NullPointerException
- (unchecked)
Thrown if in is null.protected void writePending() throws java.io.IOException
java.io.IOException
- Thrown if an I/O (write) error occurs, or if a base-64 character
conversion error occurs.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |