|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.io.InputStream com.ibm.as400.access.ReaderInputStream
public class ReaderInputStream extends InputStream
A ReaderInputStream represents a Toolbox converter that uses stateful character conversion to convert characters into bytes. That is, it wraps an underlying Reader and reads/caches the appropriate number of characters to return the requested number of bytes. This is especially useful for mixed byte tables where the number of converted bytes is almost never the same as the number of underlying Unicode characters. This class exists primarily for use with JDBC CLOBs, but other components are free to use it as well.
For example, the following code shows two methods that perform essentially the same conversion, except one uses character converters that are part of the Java runtime, and the other uses character converters that are part of the Toolbox:
public static InputStream getJavaConversionStream(String data, String encoding) { byte[] b = data.getBytes(encoding); return new java.io.ByteArrayInputStream(b); } public static InputStream getToolboxConversionStream(String data, String encoding) { StringReader r = new StringReader(data); return new com.ibm.as400.access.ReaderInputStream(r, encoding); }
ConvTableReader
,
InputStreamReader
Constructor and Description |
---|
ReaderInputStream(Reader reader,
int ccsid)
Constructs a ReaderInputStream that will convert Unicode characters into bytes of the specified CCSID. |
ReaderInputStream(Reader reader,
int ccsid,
BidiConversionProperties properties)
Constructs a ReaderInputStream that will convert Unicode characters into bytes of the specified CCSID and bi-directional string type. |
ReaderInputStream(Reader reader,
int ccsid,
BidiConversionProperties properties,
int cacheSize)
Constructs a ReaderInputStream that will convert Unicode characters into bytes of the specified CCSID and bi-directional string type. |
ReaderInputStream(Reader reader,
int ccsid,
int bidiStringType)
Constructs a ReaderInputStream that will convert Unicode characters into bytes of the specified CCSID and bi-directional string type. |
ReaderInputStream(Reader reader,
int ccsid,
int bidiStringType,
int cacheSize)
Constructs a ReaderInputStream that will convert Unicode characters into bytes of the specified CCSID and bi-directional string type. |
ReaderInputStream(Reader reader,
String encoding)
Constructs a ReaderInputStream that will convert Unicode characters into bytes of the specified encoding. |
Modifier and Type | Method and Description |
---|---|
int |
available()
Returns the number of bytes stored in this ReaderInputStream's internal cache. |
void |
close()
Closes this ReaderInputStream and its underlying Reader. |
int |
getBidiStringType()
Returns the bi-directional string type in use by this ReaderInputStream. |
int |
getCacheSize()
Returns the maximum number of characters that may be stored in the internal buffer. |
int |
getCcsid()
Returns the CCSID used by this ReaderInputStream. |
String |
getEncoding()
Returns the encoding used by this ReaderInputStream. |
int |
read()
Reads a single byte. |
int |
read(byte[] buffer)
Reads bytes into the specified array. |
int |
read(byte[] buffer,
int offset,
int length)
Reads bytes into a portion of the specified array. |
long |
skip(long length)
Skips the specified number of bytes. |
Methods inherited from class java.io.InputStream |
---|
mark, markSupported, reset |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ReaderInputStream(Reader reader, String encoding) throws UnsupportedEncodingException
reader
- The Reader from which to read characters.encoding
- The name of a supported Java character encoding.UnsupportedEncodingException
- If the specified character encoding is not supported.public ReaderInputStream(Reader reader, int ccsid) throws UnsupportedEncodingException
reader
- The Reader from which to read characters.ccsid
- The CCSID used to convert characters into bytes.UnsupportedEncodingException
- If the specified CCSID or its corresponding character encoding is not supported.public ReaderInputStream(Reader reader, int ccsid, int bidiStringType) throws UnsupportedEncodingException
reader
- The Reader from which to read characters.ccsid
- The CCSID used to convert characters into bytes.bidiStringType
- The bi-directional string type
.UnsupportedEncodingException
- If the specified CCSID or its corresponding character encoding is not supported.public ReaderInputStream(Reader reader, int ccsid, BidiConversionProperties properties) throws UnsupportedEncodingException
reader
- The Reader from which to read characters.ccsid
- The CCSID used to convert characters into bytes.properties
- The bidi conversion properties.UnsupportedEncodingException
- If the specified CCSID or its corresponding character encoding is not supported.public ReaderInputStream(Reader reader, int ccsid, int bidiStringType, int cacheSize) throws UnsupportedEncodingException
reader
- The Reader from which to read characters.ccsid
- The CCSID used to convert characters into bytes.bidiStringType
- The bi-directional string type
.cacheSize
- The number of characters to store in the internal buffer. The default is 1024. This number must be greater than zero.UnsupportedEncodingException
- If the specified CCSID or its corresponding character encoding is not supported.public ReaderInputStream(Reader reader, int ccsid, BidiConversionProperties properties, int cacheSize) throws UnsupportedEncodingException
reader
- The Reader from which to read characters.ccsid
- The CCSID used to convert characters into bytes.properties
- The bidi conversion properties.cacheSize
- The number of characters to store in the internal buffer. The default is 1024. This number must be greater than zero.UnsupportedEncodingException
- If the specified CCSID or its corresponding character encoding is not supported.Method Detail |
---|
public int available() throws IOException
available
in class InputStream
IOException
public void close() throws IOException
close
in interface Closeable
close
in class InputStream
IOException
- If an I/O exception occurs.public int getBidiStringType()
bi-directional string type
.public int getCacheSize()
public int getCcsid()
public String getEncoding()
public int read() throws IOException
read
in class InputStream
IOException
- If an I/O exception occurs.public int read(byte[] buffer) throws IOException
read
in class InputStream
buffer
- The destination buffer.IOException
- If an I/O exception occurs.public int read(byte[] buffer, int offset, int length) throws IOException
read
in class InputStream
buffer
- The destination buffer.offset
- The offset into the buffer at which to begin storing data.length
- The maximum number of bytes to store.IOException
- If an I/O exception occurs.public long skip(long length) throws IOException
skip
in class InputStream
length
- The number of bytes to skip.IOException
- If an I/O exception occurs.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |