|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.io.InputStream java.io.FilterInputStream tribble.io.Base64DecoderInputStream
public class Base64DecoderInputStream
Base-64 decoding input stream.
Provides an I/O stream that decodes radix-64 characters into binary data. Printable 8-bit bytes (octets) are read from the input stream which encode data as base-64 (a.k.a. radix-64) ASCII characters and are converted into binary data bytes.
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.
Base64EncoderInputStream
,
Base64DecoderOutputStream
,
Base64Encoder
Field Summary | |
---|---|
protected boolean |
m_eof
End of input stream reached. |
protected byte[] |
m_inBuf
Pending input queue. |
protected short |
m_inLen
Pending input queue length. |
protected byte[] |
m_outBuf
Output queue. |
protected short |
m_outLen
Current output byte queue length. |
protected short |
m_outPos
Next output byte queue index. |
Fields inherited from class java.io.FilterInputStream |
---|
in |
Constructor Summary | |
---|---|
Base64DecoderInputStream(java.io.InputStream in)
Constructor. |
|
Base64DecoderInputStream(java.io.Reader in)
Constructor. |
Method Summary | |
---|---|
void |
close()
Close this 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 |
decode(java.io.OutputStream out)
Read and convert the contents of an input stream. |
void |
decode(java.io.OutputStream out,
int bufLen)
Read and convert the contents of an input stream. |
java.io.InputStream |
getInput()
Retrieve the underlying input stream for this output stream. |
static void |
main(java.lang.String[] args)
Test driver. |
int |
read()
Read a character from this input stream. |
int |
read(byte[] buf,
int off,
int len)
Reads up to len bytes of data from this input stream into an array of bytes. |
protected void |
readPending()
Read base-64 encoded data bytes from the input stream and convert them into data bytes (octets). |
Methods inherited from class java.io.FilterInputStream |
---|
available, mark, markSupported, read, reset, skip |
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
protected short m_outPos
protected short m_outLen
protected boolean m_eof
Constructor Detail |
---|
public Base64DecoderInputStream(java.io.InputStream in)
in
- The underlying input stream for this input stream.public Base64DecoderInputStream(java.io.Reader in)
in
- The underlying input stream for this input stream.Method Detail |
---|
public static void main(java.lang.String[] args) throws java.io.IOException
Usage
java tribble.io.Base64DecoderInputStream [-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 flushed after the converted data is written, but is not closed, i.e., method flush() is 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 close() throws java.io.IOException
Any pending base-64 character input is discarded.
Subsequent attempts to read from this input stream will cause exceptions to be thrown.
close
in interface java.io.Closeable
close
in class java.io.FilterInputStream
java.io.IOException
- Thrown if an I/O (read) error occurs.public int read() throws java.io.IOException
A base-64 character encoding is converted into its corresponding 8-bit binary code (octet) after being read from the underlying input stream.
read
in class java.io.FilterInputStream
java.io.IOException
- Thrown if an I/O (read) error occurs.public int read(byte[] buf, int off, int len) throws java.io.IOException
read
in class java.io.FilterInputStream
buf
- The buffer into which the data is read.off
- The start offset within buf to read data into.len
- The maximum number of bytes read into buf.
java.io.IOException
- Thrown if an I/O (read) error occurs.public java.io.InputStream getInput()
Note that this method is not specified by the standard
FilterInputStream
library class, but is provided as a
convenient enhancement.
public void decode(java.io.OutputStream out) throws java.io.IOException
decode
(in, 0).
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 is null.decode()
public void decode(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 this output stream.
Note that the output stream is flushed after the converted data is written, but is not closed, i.e., method flush() is called but close() is not.
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 is null.protected void readPending() throws java.io.IOException
Note that this method should only be called if m_outPos
is
greater than m_outLen
, indicating that the output queue has been
exhausted.
java.io.IOException
- Thrown if an I/O (read) error occurs.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |