Package org.simpleframework.http.message
Class FileUploadConsumer.ByteCounter
java.lang.Object
org.simpleframework.http.message.FileUploadConsumer.ByteCounter
- All Implemented Interfaces:
ByteCursor
- Enclosing class:
FileUploadConsumer
The
ByteCounter is a wrapper for a cursor that can
be used to restrict the number of bytes consumed. This will
count the bytes consumed and ensure that any requested data is
restricted to a chunk less than or equal to the remaining bytes.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ByteCursorThis is the cursor that this counter will delegate to. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanisOpen()Determines whether the cursor is still open.booleanisReady()Determines whether the cursor is ready for reading.voidpush(byte[] data) Pushes the provided data on to the cursor.voidpush(byte[] data, int off, int len) Pushes the provided data on to the cursor.intread(byte[] data) Reads a block of bytes from the underlying stream.intread(byte[] data, int off, int len) Reads a block of bytes from the underlying stream.intready()Provides the number of bytes that can be read from the stream without blocking.intreset(int len) Moves the cursor backward within the stream.
-
Field Details
-
cursor
This is the cursor that this counter will delegate to.
-
-
Constructor Details
-
ByteCounter
Constructor for theCounterobject. This is used to create a special cursor that counts the bytes read and limits reads to the remaining bytes left in the part series.- Parameters:
cursor- this is the cursor that is delegated to
-
-
Method Details
-
isOpen
Determines whether the cursor is still open. The cursor is considered open if there are still bytes to read. If there is still bytes buffered and the underlying transport is closed then the cursor is still considered open.- Specified by:
isOpenin interfaceByteCursor- Returns:
- true if the read method does not return a -1 value
- Throws:
IOException
-
isReady
Determines whether the cursor is ready for reading. When the cursor is ready then it guarantees that some amount of bytes can be read from the underlying stream without blocking.- Specified by:
isReadyin interfaceByteCursor- Returns:
- true if some data can be read without blocking
- Throws:
IOException
-
ready
Provides the number of bytes that can be read from the stream without blocking. This is typically the number of buffered or available bytes within the stream. When this reaches zero then the cursor may perform a blocking read.- Specified by:
readyin interfaceByteCursor- Returns:
- the number of bytes that can be read without blocking
- Throws:
IOException
-
read
Reads a block of bytes from the underlying stream. This will read up to the requested number of bytes from the underlying stream. If there are no ready bytes on the stream this can return zero, representing the fact that nothing was read.- Specified by:
readin interfaceByteCursor- Parameters:
data- this is the array to read the bytes in to- Returns:
- this returns the number of bytes read from the stream
- Throws:
IOException
-
read
Reads a block of bytes from the underlying stream. This will read up to the requested number of bytes from the underlying stream. If there are no ready bytes on the stream this can return zero, representing the fact that nothing was read.- Specified by:
readin interfaceByteCursor- Parameters:
data- this is the array to read the bytes in tooff- this is the offset to begin writing the bytes tolen- this is the number of bytes that are requested- Returns:
- this returns the number of bytes read from the stream
- Throws:
IOException
-
push
Pushes the provided data on to the cursor. Data pushed on to the cursor will be the next data read from the cursor. This complements theresetmethod which will reset the cursors position on a stream. Allowing data to be pushed on to the cursor allows more flexibility.- Specified by:
pushin interfaceByteCursor- Parameters:
data- this is the data to be pushed on to the cursor- Throws:
IOException
-
push
Pushes the provided data on to the cursor. Data pushed on to the cursor will be the next data read from the cursor. This complements theresetmethod which will reset the cursors position on a stream. Allowing data to be pushed on to the cursor allows more flexibility.- Specified by:
pushin interfaceByteCursor- Parameters:
data- this is the data to be pushed on to the cursoroff- this is the offset to begin reading the byteslen- this is the number of bytes that are to be used- Throws:
IOException
-
reset
Moves the cursor backward within the stream. This ensures that any bytes read from the last read can be pushed back in to the stream so that they can be read again. This will throw an exception if the reset can not be performed.- Specified by:
resetin interfaceByteCursor- Parameters:
len- this is the number of bytes to reset back- Returns:
- this is the number of bytes that have been reset
- Throws:
IOException
-