Android
java.io
public class

java.io.ByteArrayInputStream

java.lang.Object
java.io.InputStream Closeable
java.io.ByteArrayInputStream

ByteArrayInputStream is used for streaming over a byte array.

Summary

Fields

protected      byte[]  buf  The byte array containing the bytes to stream over. 
protected      int  count  The total number of bytes initially available in the byte array buf
protected      int  mark  The current mark position. 
protected      int  pos  The current position within the byte array. 

Public Constructors

            ByteArrayInputStream(byte[] buf)
Constructs a new ByteArrayInputStream on the byte array buf.
            ByteArrayInputStream(byte[] buf, int offset, int length)
Constructs a new ByteArrayInputStream on the byte array buf with the position set to offset and the number of bytes available set to offset + length.

Public Methods

  synchronized        int  available()
Returns a int representing then number of bytes that are available before this ByteArrayInputStream will block.
          void  close()
Close the ByteArrayInputStream.
  synchronized        void  mark(int readlimit)
Set a Mark position in this ByteArrayInputStream.
          boolean  markSupported()
Returns a boolean indicating whether or not this ByteArrayInputStream supports mark() and reset().
  synchronized        int  read(byte[] b, int offset, int length)
Reads at most len bytes from this ByteArrayInputStream and stores them in byte array b starting at offset off.
  synchronized        int  read()
Reads a single byte from this ByteArrayInputStream and returns the result as an int.
  synchronized        void  reset()
Reset this ByteArrayInputStream to the last marked location.
  synchronized        long  skip(long n)
Skips count number of bytes in this InputStream.
Methods inherited from class java.io.InputStream
Methods inherited from class java.lang.Object
Methods inherited from interface java.io.Closeable

Details

Fields

protected byte[] buf

The byte array containing the bytes to stream over.

protected int count

The total number of bytes initially available in the byte array buf.

protected int mark

The current mark position. Initially set to 0 or the offset parameter within the constructor.

protected int pos

The current position within the byte array.

Public Constructors

public ByteArrayInputStream(byte[] buf)

Constructs a new ByteArrayInputStream on the byte array buf.

Parameters

buf the byte array to stream over

public ByteArrayInputStream(byte[] buf, int offset, int length)

Constructs a new ByteArrayInputStream on the byte array buf with the position set to offset and the number of bytes available set to offset + length.

Parameters

buf the byte array to stream over
offset the offset in buf to start streaming at
length the number of bytes available to stream over.

Public Methods

public synchronized int available()

Returns a int representing then number of bytes that are available before this ByteArrayInputStream will block. This method returns the number of bytes yet to be read from the underlying byte array.

Returns

  • the number of bytes available before blocking.

public void close()

Close the ByteArrayInputStream. This implementation frees up resources associated with this stream.

Throws

IOException If an error occurs attempting to close this InputStream.

public synchronized void mark(int readlimit)

Set a Mark position in this ByteArrayInputStream. The parameter readLimit is ignored. Sending reset() will reposition the stream back to the marked position.

Parameters

readlimit ignored.

public boolean markSupported()

Returns a boolean indicating whether or not this ByteArrayInputStream supports mark() and reset(). This implementation returns true.

Returns

  • true indicates this stream supports mark/reset, false otherwise.

public synchronized int read(byte[] b, int offset, int length)

Reads at most len bytes from this ByteArrayInputStream and stores them in byte array b starting at offset off. Answer the number of bytes actually read or -1 if no bytes were read and end of stream was encountered. This implementation reads bytes from the target byte array.

Parameters

b the byte array in which to store the read bytes.
offset the offset in b to store the read bytes.
length the maximum number of bytes to store in b.

Returns

  • the number of bytes actually read or -1 if end of stream.

public synchronized int read()

Reads a single byte from this ByteArrayInputStream and returns the result as an int. The low-order byte is returned or -1 of the end of stream was encountered. This implementation returns the next available byte from the target byte array.

Returns

  • the byte read or -1 if end of stream.

public synchronized void reset()

Reset this ByteArrayInputStream to the last marked location. This implementation resets the position to either the marked position, the start position supplied in the constructor or 0 if neither is provided.

public synchronized long skip(long n)

Skips count number of bytes in this InputStream. Subsequent read()'s will not return these bytes unless reset() is used. This implementation skips count number of bytes in the target stream.

Parameters

n the number of bytes to skip.

Returns

  • the number of bytes actually skipped.
Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:56