|
|||||||||
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.Base64EncoderInputStream
public class Base64EncoderInputStream
Base-64 encoding input stream.
Provides an I/O stream that encodes binary data as base-64 characters. 8-bit bytes (octets) are converted into printable 8-bit characters that encode the data as base-64 (a.k.a. radix-64) ASCII characters as they are read from the input stream.
See Base64Encoder
for more information about base-64
encoding.
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
,
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 short |
m_newlineStyle
Newline output style. |
protected byte[] |
m_outBuf
Output queue. |
protected short |
m_outLen
Current output byte queue length. |
protected short |
m_outPos
Next output byte queue index. |
protected static byte[] |
NEWLINE
Platform-specific newline character sequence. |
static short |
NEWLINE_BYTE
Newline output style: Single byte ('\n'). |
static short |
NEWLINE_NATIVE
Newline output style: Native platform character sequence. |
static short |
NEWLINE_NONE
Newline output style: No newline sequences. |
Fields inherited from class java.io.FilterInputStream |
---|
in |
Constructor Summary | |
---|---|
Base64EncoderInputStream(java.io.InputStream in)
Constructor. |
Method Summary | |
---|---|
void |
close()
Close this input stream. |
static void |
encode(java.io.InputStream in,
java.io.OutputStream out)
Read and convert the contents of an input stream. |
static void |
encode(java.io.InputStream in,
java.io.OutputStream out,
int bufLen)
Read and convert the contents of an input stream. |
void |
encode(java.io.OutputStream out)
Read and convert the contents of this input stream. |
void |
encode(java.io.OutputStream out,
int bufLen)
Read and convert the contents of this 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 8-bit data bytes (octets) from the input stream and convert them into base-64 encoded character bytes. |
int |
setNewline(int style)
Establish the handling of newline sequences for this output stream. |
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 |
---|
public static final short NEWLINE_NONE
public static final short NEWLINE_BYTE
public static final short NEWLINE_NATIVE
protected static final byte[] NEWLINE
protected byte[] m_inBuf
protected byte[] m_outBuf
protected short m_inLen
protected short m_outPos
protected short m_outLen
protected short m_newlineStyle
protected boolean m_eof
Constructor Detail |
---|
public Base64EncoderInputStream(java.io.InputStream 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.Base64EncoderInputStream [-o outfile] file...
args
- Command line arguments.
java.io.IOException
- Thrown if an I/O error occurs.public static void encode(java.io.InputStream in, java.io.OutputStream out) throws java.io.IOException
encode
(in, out, 0).
in
- An input stream containing 8-bit octet data to be converted into base-64
character output.out
- An output stream to which the converted base-64 character output is to be
written.
java.io.IOException
- Thrown if an I/O (read or write) error occurs.
java.lang.NullPointerException
- (unchecked)
Thrown if in or out is null.encode()
public static void encode(java.io.InputStream in, java.io.OutputStream out, int bufLen) throws java.io.IOException
The entire contents of an input stream are read as 8-bit octets and converted into base-64 encoded characters, 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 8-bit octet data to be converted into base-64
character output.out
- An output stream to which the converted base-64 character output is to be
written.bufLen
- Specifies the size, in bytes, of the internal buffer to use for reading
data from the input stream. Specifying a value less than 3 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.encode()
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
An 8-bit binary code (octet) is converted into its corresponding base-64 character encoding 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.
Each 8-bit binary code (octet) is converted into its corresponding base-64
character encoding after being read from the underlying input stream.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 encode(java.io.OutputStream out) throws java.io.IOException
encode
(out, 0).
out
- An output stream to which the converted base-64 character output is to be
written.
java.io.IOException
- Thrown if an I/O (read or write) error occurs.
java.lang.NullPointerException
- (unchecked)
Thrown if out is null.encode()
public void encode(java.io.OutputStream out, int bufLen) throws java.io.IOException
The entire contents of this input stream are read as 8-bit octets and converted into base-64 encoded characters, 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.
out
- An output stream to which the converted base-64 character output is to be
written.bufLen
- Specifies the size, in bytes, of the internal buffer to use for reading
data from the input stream. Specifying a value less than 3 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 out is null.public int setNewline(int style)
This method provides a means for "prettying up" the character input of this stream.
The default style is NEWLINE_NATIVE
.
style
- Specifies the way that newlines are inserted into the input stream.
This value must be one of the NEWLINE_XXX
constants:
NEWLINE_NONE
NEWLINE_BYTE
NEWLINE_NATIVE
System.getProperty()
).
java.lang.IllegalArgumentException
- (unchecked)
Thrown if style is not a valid NEWLINE_XXX
constant.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 |