Top Description Fields Constructors Methods
org.apache.derby.iapi.services.io

public final Class InputStreamUtil

extends Object
Class Inheritance
Imports
java.io.*

Utility methods for InputStream that are stand-ins for a small subset of DataInput methods. This avoids pushing a DataInputStream just to get this functionality.

Field Summary

Modifier and TypeField and Description
private static final int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static void
readFully(InputStream
Whence to read
in
,
byte[]
The byte array to fill
b
,
int
Position in byte array where we should start writing
offset
,
int
Number of bytes to read
len
)

Read a number of bytes into an array.

public static int

Returns:

the number of bytes read
readLoop
(InputStream
Whence to read
in
,
byte[]
The byte array to fill
b
,
int
Position in byte array where we should start writing
offset
,
int
Number of bytes to read
len
)

Read a number of bytes into an array.

public static int

Returns:

the byte
readUnsignedByte
(InputStream
Whence to read a byte
in
)

Read an unsigned byte from an InputStream, throwing an EOFException if the end of the input is reached.

public static void
skipFully(InputStream
InputStream to be skipped.
is
,
long
number of bytes to skip. if skippedBytes >= zero, do nothing.
skippedBytes
)

Skips requested number of bytes, throws EOFException if there is too few bytes in the stream.

public static final long

Returns:

The number of bytes skipped.
skipPersistent
(InputStream
byte stream
in
,
long
the number of bytes to skip
bytesToSkip
)

Tries harder to skip the requested number of bytes.

public static long

Returns:

number of bytes skipped in fact.
skipUntilEOF
(InputStream
InputStream to be skipped.
is
)

Skips until EOF, returns number of bytes skipped.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

SKIP_FRAGMENT_SIZEback to summary
private static final int SKIP_FRAGMENT_SIZE

Constructor Detail

InputStreamUtilback to summary
public InputStreamUtil()

Method Detail

readFullyback to summary
public static void readFully(InputStream in, byte[] b, int offset, int len) throws IOException

Read a number of bytes into an array.

Parameters
in:InputStream

Whence to read

b:byte[]

The byte array to fill

offset:int

Position in byte array where we should start writing

len:int

Number of bytes to read

Exceptions
IOException:
if an I/O error occurs.
EOFException:
if the end of the stream is reached
See Also
DataInput#readFully
readLoopback to summary
public static int readLoop(InputStream in, byte[] b, int offset, int len) throws IOException

Read a number of bytes into an array. Keep reading in a loop until len bytes are read or EOF is reached or an exception is thrown. Return the number of bytes read. (InputStream.read(byte[],int,int) does not guarantee to read len bytes even if it can do so without reaching EOF or raising an exception.)

Parameters
in:InputStream

Whence to read

b:byte[]

The byte array to fill

offset:int

Position in byte array where we should start writing

len:int

Number of bytes to read

Returns:int

the number of bytes read

Exceptions
IOException:
if an I/O error occurs.
readUnsignedByteback to summary
public static int readUnsignedByte(InputStream in) throws IOException

Read an unsigned byte from an InputStream, throwing an EOFException if the end of the input is reached.

Parameters
in:InputStream

Whence to read a byte

Returns:int

the byte

Exceptions
IOException:
if an I/O error occurs.
EOFException:
if the end of the stream is reached
See Also
DataInput#readUnsignedByte
skipFullyback to summary
public static void skipFully(InputStream is, long skippedBytes) throws IOException

Skips requested number of bytes, throws EOFException if there is too few bytes in the stream.

Parameters
is:InputStream

InputStream to be skipped.

skippedBytes:long

number of bytes to skip. if skippedBytes >= zero, do nothing.

Exceptions
IOException:
if IOException occurs. It doesn't contain EOFException.
EOFException:
if EOF meets before requested number of bytes are skipped.
NullPointerException:
if the param 'is' equals null.
skipPersistentback to summary
public static final long skipPersistent(InputStream in, long bytesToSkip) throws IOException

Tries harder to skip the requested number of bytes.

Note that even if the method fails to skip the requested number of bytes, it will not throw an exception. If this happens, the caller can be sure that end-of-stream has been reached.

Parameters
in:InputStream

byte stream

bytesToSkip:long

the number of bytes to skip

Returns:long

The number of bytes skipped.

Exceptions
IOException:
if reading from the stream fails
skipUntilEOFback to summary
public static long skipUntilEOF(InputStream is) throws IOException

Skips until EOF, returns number of bytes skipped.

Parameters
is:InputStream

InputStream to be skipped.

Returns:long

number of bytes skipped in fact.

Exceptions
IOException:
if IOException occurs. It doesn't contain EOFException.
NullPointerException:
if the param 'is' equals null.