APIdia Launch Partner
Top Description Fields Constructors Methods
com.sun.jndi.ldap.sasl

public Class SaslInputStream

extends InputStream
Class Inheritance
Imports
javax.security.sasl.Sasl, .SaslClient, .SaslException, java.io.IOException, .EOFException, .InputStream

This class is used by clients of Java SASL that need to create an input stream that uses SaslClient's unwrap() method to decode the SASL buffers sent by the SASL server. Extend from InputStream instead of FilterInputStream because we need to override less methods in InputStream. That is, the behavior of the default implementations in InputStream matches more closely with the behavior we want in SaslInputStream.
Author
Rosanna Lee

Field Summary

Modifier and TypeField and Description
private byte[]
private int
private static final boolean
private InputStream
private byte[]
private int
private byte[]
private SaslClient

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public int
available()

Overrides java.io.InputStream.available.

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected.

public void
close()

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Closes this input stream and releases any system resources associated with the stream.

private int

Returns:

The number of unwrapped bytes available
fill
()

Fills the buf with more data by reading a SASL buffer, unwrapping it, and leaving the bytes in buf for read() to return.

private static int
networkByteOrderToInt(byte[] buf, int start, int count)

Returns the integer represented by 4 bytes in network byte order.

public int
read()

Implements abstract java.io.InputStream.read.

Reads the next byte of data from the input stream.

public int
read(byte[] inBuf, int start, int count)

Overrides java.io.InputStream.read.

Reads up to len bytes of data from the input stream into an array of bytes.

private int

Returns:

The number of bytes actually read; -1 if none read
readFully
(byte[] inBuf, int total)

Read requested number of bytes before returning.

Inherited from java.io.InputStream:
markmarkSupportednullInputStreamreadreadAllBytesreadNBytesreadNBytesresetskipskipNBytestransferTo

Field Detail

bufback to summary
private byte[] buf
bufPosback to summary
private int bufPos
debugback to summary
private static final boolean debug
inback to summary
private InputStream in
lenBufback to summary
private byte[] lenBuf
recvMaxBufSizeback to summary
private int recvMaxBufSize
saslBufferback to summary
private byte[] saslBuffer
scback to summary
private SaslClient sc

Constructor Detail

SaslInputStreamback to summary
pack-priv SaslInputStream(SaslClient sc, InputStream in) throws SaslException

Method Detail

availableback to summary
public int available() throws IOException

Overrides java.io.InputStream.available.

Doc from java.io.InputStream.available.

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected. The read might be on the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes.

Note that while some implementations of InputStream will return the total number of bytes in the stream, many will not. It is never correct to use the return value of this method to allocate a buffer intended to hold all data in this stream.

A subclass's implementation of this method may choose to throw an IOException if this input stream has been closed by invoking the close() method.

Exceptions
IOException:
if an I/O error occurs.
closeback to summary
public void close() throws IOException

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.InputStream.close.

Closes this input stream and releases any system resources associated with the stream.

Exceptions
IOException:
if an I/O error occurs.
fillback to summary
private int fill() throws IOException

Fills the buf with more data by reading a SASL buffer, unwrapping it, and leaving the bytes in buf for read() to return.

Returns:int

The number of unwrapped bytes available

networkByteOrderToIntback to summary
private static int networkByteOrderToInt(byte[] buf, int start, int count)

Returns the integer represented by 4 bytes in network byte order.

readback to summary
public int read() throws IOException

Implements abstract java.io.InputStream.read.

Doc from java.io.InputStream.read.

Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

Exceptions
IOException:
if an I/O error occurs.
readback to summary
public int read(byte[] inBuf, int start, int count) throws IOException

Overrides java.io.InputStream.read.

Doc from java.io.InputStream.read.

Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read. The number of bytes actually read is returned as an integer.

This method blocks until input data is available, end of file is detected, or an exception is thrown.

If len is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at end of file, the value -1 is returned; otherwise, at least one byte is read and stored into b.

The first byte read is stored into element b[off], the next one into b[off+1], and so on. The number of bytes read is, at most, equal to len. Let k be the number of bytes actually read; these bytes will be stored in elements b[off] through b[off+k-1], leaving elements b[off+k] through b[off+len-1] unaffected.

In every case, elements b[0] through b[off-1] and elements b[off+len] through b[b.length-1] are unaffected.

Exceptions
IOException:
If the first byte cannot be read for any reason other than end of file, or if the input stream has been closed, or if some other I/O error occurs.
readFullyback to summary
private int readFully(byte[] inBuf, int total) throws IOException

Read requested number of bytes before returning.

Returns:int

The number of bytes actually read; -1 if none read