JBoss Marshalling 1.3.0.CR9

org.jboss.marshalling
Class LimitedByteInput

java.lang.Object
  extended by java.io.InputStream
      extended by org.jboss.marshalling.SimpleByteInput
          extended by org.jboss.marshalling.ByteInputStream
              extended by org.jboss.marshalling.LimitedByteInput
All Implemented Interfaces:
Closeable, ByteInput

public class LimitedByteInput
extends ByteInputStream

A limited byte input stream. Throws an exception if too many bytes are read.


Field Summary
 
Fields inherited from class org.jboss.marshalling.ByteInputStream
byteInput
 
Constructor Summary
LimitedByteInput(ByteInput byteInput, long limit)
          Create a new instance.
 
Method Summary
 int read()
          Reads the next byte of data from the input stream.
 int read(byte[] b, int off, int len)
          Read some bytes from the input stream into the given array.
 long skip(long n)
          Skips over and discards up to n bytes of data from this input stream.
 
Methods inherited from class org.jboss.marshalling.ByteInputStream
available, close, read
 
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

LimitedByteInput

public LimitedByteInput(ByteInput byteInput,
                        long limit)
Create a new instance.

Parameters:
byteInput - the byte input to read from
limit - the maximum number of bytes to read
Method Detail

read

public int read()
         throws IOException
Reads the next byte of data from the input stream. 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.

Specified by:
read in interface ByteInput
Overrides:
read in class ByteInputStream
Returns:
the next byte, or -1 if the end of stream has been reached
Throws:
IOException - if an error occurs

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Read some bytes from the input stream into the given array. Returns the number of bytes actually read (possibly zero), or -1 if the end of stream has been reached.

Specified by:
read in interface ByteInput
Overrides:
read in class ByteInputStream
Parameters:
b - the destination array
off - the offset into the array into which data should be read
len - the number of bytes to attempt to fill in the destination array
Returns:
the number of bytes read (possibly zero), or -1 if the end of stream has been reached
Throws:
IOException - if an error occurs

skip

public long skip(long n)
          throws IOException
Skips over and discards up to n bytes of data from this input stream. If the end of stream is reached, this method returns 0 in order to be consistent with InputStream.skip(long).

Specified by:
skip in interface ByteInput
Overrides:
skip in class ByteInputStream
Parameters:
n - the number of bytes to attempt to skip
Returns:
the number of bytes skipped
Throws:
IOException - if an error occurs

JBoss Marshalling 1.3.0.CR9

Copyright © 2011 JBoss, a division of Red Hat, Inc.