FileDocCategorySizeDatePackage
SimpleTextInputStream.javaAPI DocExample4214Sat Feb 03 11:43:42 GMT 2001jdbc.SimpleText

SimpleTextInputStream

public class SimpleTextInputStream extends InputStream

Fields Summary
protected CommonValue
value
protected int
type
public static final int
STREAM_TYPE_ASCII
public static final int
STREAM_TYPE_UNICODE
public static final int
STREAM_TYPE_BINARY
protected int
length
protected int
currentOffset
Constructors Summary
public SimpleTextInputStream(CommonValue value, int type, int length)

        this.value = value;
        this.type = type;
        this.length = length;
    
Methods Summary
public intavailable()

        int bytes = 0;

        if (length > 0) {
            bytes = length - currentOffset;
        }
        return bytes;
    
public intread()

        int  singleByte;
        byte buffer[];

        // Allocate a single byte buffer

        buffer = new byte[1];

        // Read a single byte of data

        singleByte = read(buffer);

        // If not end of data, return the byte read

        if (singleByte != -1) {
            singleByte = buffer[0];
        }

        return singleByte;
    
public synchronized intread(byte[] b)

        int toRead = b.length;

        // If the value given is null, return end of data

        if (value == null) {
            return -1;
        }

        if (value.isNull()) {
            return -1;
        }

        // Calculate the number of bytes to return

        int copyBytes = length - currentOffset;

        // Is there more data to get?

        if (copyBytes <= 0) {
            return -1;
        }

        // Only copy up to the size of the given buffer

        if (copyBytes > toRead) {
            copyBytes = toRead;
        }

        // Get the data as a byte array

        byte data[];

        try {
            data = value.getBytes();
        }
        catch (SQLException ex) {
            return -1;
        }

        // Copy the data.  The type of InputStream should be checked.
        // We'll assume binary data for the SimpleText driver

        System.arraycopy(data, currentOffset, b, 0, copyBytes);

        // Increment our offset

        currentOffset += copyBytes;

        // Return the number of bytes copied

        return copyBytes;