public static class Base64Util.InputStream
extends java.io.InputStream
Base64Util.InputStream will read data from another java.io.InputStream,
given in the constructor, and encode/decode to/from Base64 notation on the fly.Base64Util| Constructor and Description |
|---|
InputStream(java.io.InputStream in)
Constructs a
Base64Util.InputStream in DECODE mode. |
InputStream(java.io.InputStream in,
int options)
Constructs a
Base64Util.InputStream in either ENCODE or DECODE mode. |
| Modifier and Type | Method and Description |
|---|---|
int |
available()
Returns the number of bytes that can be read from this input stream without blocking.
|
void |
close()
Closes this input stream and releases any system resources associated with the stream.
|
void |
mark(int readlimit)
Marks the current position in this input stream.
|
boolean |
markSupported()
Tests if this input stream supports the mark and reset methods.
|
int |
read()
Reads enough of the input stream to convert to/from Base64 and returns the next byte.
|
int |
read(byte[] dest)
Calls
read() repeatedly until the end of stream is reached or len bytes
have been read. |
int |
read(byte[] dest,
int off,
int len)
Calls
read() repeatedly until the end of stream is reached or len bytes
have been read. |
void |
reset()
Repositions this stream to the position at the time the mark method was last called on this
input stream.
|
public InputStream(java.io.InputStream in)
Base64Util.InputStream in DECODE mode.in - the java.io.InputStream from which to read data.public InputStream(java.io.InputStream in,
int options)
Base64Util.InputStream in either ENCODE or DECODE mode.
Valid options:
ENCODE or DECODE: Encode or Decode as data is read.
DONT_BREAK_LINES: don't break lines at 76 characters
(only meaningful when encoding)
<i>Note: Technically, this makes your encoding non-compliant.</i>
Example: new Base64.InputStream( in, Base64.DECODE )
in - the java.io.InputStream from which to read data.options - Specified optionsBase64Util.ENCODE,
Base64Util.DECODE,
Base64Util.DONT_BREAK_LINESpublic int read()
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionpublic int read(byte[] dest,
int off,
int len)
throws java.io.IOException
read() repeatedly until the end of stream is reached or len bytes
have been read. Returns number of bytes read into array or -1 if end of stream is
encountered.read in class java.io.InputStreamdest - array to hold valuesoff - offset for arraylen - max number of bytes to read into arrayjava.io.IOExceptionpublic int read(byte[] dest)
throws java.io.IOException
read() repeatedly until the end of stream is reached or len bytes
have been read. Returns number of bytes read into array or -1 if end of stream is
encountered.read in class java.io.InputStreamdest - array to hold valuesjava.io.IOExceptionpublic int available()
throws java.io.IOException
Returns always 0.
available in class java.io.InputStreamjava.io.IOExceptionpublic void close()
throws java.io.IOException
This method simply performs in.close(). *
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.InputStreamjava.io.IOExceptionpublic void mark(int readlimit)
The readlimit argument tells this input stream to allow that many bytes to be read before the mark position gets invalidated.
This method simply performs in.mark(readlimit).
mark in class java.io.InputStreamreadlimit - - the maximum limit of bytes that can be read before the mark position becomes invalid.public boolean markSupported()
This method simply performs in.markSupported().
markSupported in class java.io.InputStreampublic void reset()
throws java.io.IOException
This method simply performs in.reset().
Stream marks are intended to be used in situations where you need to read ahead a little to see what's in the stream. Often this is most easily done by invoking some general parser. If the stream is of the type handled by the parse, it just chugs along happily. If the stream is not of that type, the parser should throw an exception when it fails. If this happens within readlimit bytes, it allows the outer code to reset the stream and try another parser.
reset in class java.io.InputStreamjava.io.IOException