Top Description Fields Constructors Methods
org.glassfish.grizzly.http.multipart

pack-priv final Class MultipartEntryNIOReader

extends NIOReader
Class Inheritance
Imports
java.io.IOException, java.nio.ByteBuffer, .CharBuffer, java.nio.charset.Charset, .CharsetDecoder, .CodingErrorAction, org.glassfish.grizzly.ReadHandler, org.glassfish.grizzly.http.io.NIOInputStream, .NIOReader, org.glassfish.grizzly.utils.Charsets

Stream implementation to read MultipartEntry content in the character mode.
Since
2.0.1

Field Summary

Modifier and TypeField and Description
private float
private CharsetDecoder
private String
private ReadHandler
private boolean
private final MultipartEntry
private int
private NIOInputStream
private final CharBuffer
singleCharBuf

CharBuffer for converting a single character at a time.

Constructor Summary

AccessConstructor and Description
public
MultipartEntryNIOReader(final MultipartEntry
MultipartEntry the {@link NIOInputStream belongs to.
multipartEntry
)

Constructs a new NIOInputStream using the specified requestNIOInputStream

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements abstract java.io.Reader.close.

Implements java.io.Closeable.close.

Closes the stream and releases any system resources associated with it.

private int

Returns:

the number of bytes actually read
fillChar
(final int
how much content should attempt to be read
requestedLen
,
final CharBuffer dst)

Used to convert bytes to char.

private CharsetDecoder
getDecoder()

Returns: the CharsetDecoder that should be used when converting content from binary to character

protected void
initialize(final NIOInputStream requestInputStream, final String encoding)

public boolean
public boolean
public void
mark(int readAheadLimit)

Overrides java.io.Reader.mark.

Marks the present position in the stream.

public boolean

Returns:

false
markSupported
()

Overrides java.io.Reader.markSupported.

This Reader implementation does not support marking.

public void
notifyAvailable(final ReadHandler handler)

Implements org.glassfish.grizzly.InputSource.notifyAvailable.

Notify the specified ReadHandler when any number of bytes or characters can be read without blocking.

public void
notifyAvailable(final ReadHandler handler, final int size)

Implements org.glassfish.grizzly.InputSource.notifyAvailable.

Notify the specified ReadHandler when the number of bytes that can be read without blocking is greater or equal to the specified size.

pack-priv void
onDataCame()

Append available bytes to the input stream

public int
read(final CharBuffer target)

Overrides java.io.Reader.read.

Implements java.lang.Readable.read.

Attempts to read characters into the specified character buffer.

public int
read()

Overrides java.io.Reader.read.

Reads a single character.

public int
read(final char[] cbuf)

Overrides java.io.Reader.read.

Reads characters into an array.

public int
read(final char[] cbuf, final int off, final int len)

Implements abstract java.io.Reader.read.

Reads characters into a portion of an array.

public boolean
ready()

Overrides java.io.Reader.ready.

Tells whether this stream is ready to be read.

public int
protected void
public void
reset()

Overrides java.io.Reader.reset.

Resets the stream.

private static boolean
shouldNotifyNow(final int
the amount of data that must be available for a ReadHandler to be notified.
size
,
final int
the amount of data currently available.
available
)

Returns: true if the handler should be notified during a call to notifyAvailable(ReadHandler) or notifyAvailable(ReadHandler, int), otherwise false

public long
skip(final long n)

Overrides java.io.Reader.skip.

Skips characters.

Field Detail

averageCharsPerByteback to summary
private float averageCharsPerByte
decoderback to summary
private CharsetDecoder decoder
encodingback to summary
private String encoding
handlerback to summary
private ReadHandler handler
isClosedback to summary
private boolean isClosed
multipartEntryback to summary
private final MultipartEntry multipartEntry
requestedSizeback to summary
private int requestedSize
requestNIOInputStreamback to summary
private NIOInputStream requestNIOInputStream
singleCharBufback to summary
private final CharBuffer singleCharBuf

CharBuffer for converting a single character at a time.

Constructor Detail

MultipartEntryNIOReaderback to summary
public MultipartEntryNIOReader(final MultipartEntry multipartEntry)

Constructs a new NIOInputStream using the specified requestNIOInputStream

Parameters
multipartEntry:MultipartEntry

MultipartEntry the {@link NIOInputStream belongs to.

Method Detail

closeback to summary
public void close() throws IOException

Implements abstract java.io.Reader.close.

Implements java.io.Closeable.close.

Doc from java.io.Reader.close.

Closes the stream and releases any system resources associated with it. Once the stream has been closed, further read(), ready(), mark(), reset(), or skip() invocations will throw an IOException. Closing a previously closed stream has no effect.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
fillCharback to summary
private int fillChar(final int requestedLen, final CharBuffer dst) throws IOException

Used to convert bytes to char.

Parameters
requestedLen:int

how much content should attempt to be read

Returns:int

the number of bytes actually read

Exceptions
IOException:
if an I/O error occurs while reading content
getDecoderback to summary
private CharsetDecoder getDecoder()
Returns:CharsetDecoder

the CharsetDecoder that should be used when converting content from binary to character

initializeback to summary
protected void initialize(final NIOInputStream requestInputStream, final String encoding)
isFinishedback to summary
public boolean isFinished()

Implements org.glassfish.grizzly.InputSource.isFinished.

Annotations
@Override
isReadyback to summary
public boolean isReady()

Implements org.glassfish.grizzly.InputSource.isReady.

Annotations
@Override
markback to summary
public void mark(int readAheadLimit) throws IOException

Overrides java.io.Reader.mark.

Doc from java.io.Reader.mark.

Marks the present position in the stream. Subsequent calls to reset() will attempt to reposition the stream to this point. Not all character-input streams support the mark() operation.

Annotations
@Override
Exceptions
IOException:
If the stream does not support mark(), or if some other I/O error occurs
markSupportedback to summary
public boolean markSupported()

Overrides java.io.Reader.markSupported.

This Reader implementation does not support marking.

Returns:boolean

false

Annotations
@Override
notifyAvailableback to summary
public void notifyAvailable(final ReadHandler handler)

Implements org.glassfish.grizzly.InputSource.notifyAvailable.

Doc from org.glassfish.grizzly.InputSource.notifyAvailable.

Notify the specified ReadHandler when any number of bytes or characters can be read without blocking.

Invoking this method is equivalent to calling: notifyAvailable(handler, 1).

Annotations
@Override
notifyAvailableback to summary
public void notifyAvailable(final ReadHandler handler, final int size)

Implements org.glassfish.grizzly.InputSource.notifyAvailable.

Doc from org.glassfish.grizzly.InputSource.notifyAvailable.

Notify the specified ReadHandler when the number of bytes that can be read without blocking is greater or equal to the specified size.

Annotations
@Override
onDataCameback to summary
pack-priv void onDataCame()

Append available bytes to the input stream

readback to summary
public int read(final CharBuffer target) throws IOException

Overrides java.io.Reader.read.

Implements java.lang.Readable.read.

Doc from java.io.Reader.read.

Attempts to read characters into the specified character buffer. The buffer is used as a repository of characters as-is: the only changes made are the results of a put operation. No flipping or rewinding of the buffer is performed. If the length of the specified character buffer is zero, then no characters will be read and zero will be returned.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
readback to summary
public int read() throws IOException

Overrides java.io.Reader.read.

Doc from java.io.Reader.read.

Reads a single character. This method will block until a character is available, an I/O error occurs, or the end of the stream is reached.

Subclasses that intend to support efficient single-character input should override this method.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
readback to summary
public int read(final char[] cbuf) throws IOException

Overrides java.io.Reader.read.

Doc from java.io.Reader.read.

Reads characters into an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.

If the length of cbuf is zero, then no characters are read and 0 is returned; otherwise, there is an attempt to read at least one character. If no character is available because the stream is at its end, the value -1 is returned; otherwise, at least one character is read and stored into cbuf.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
readback to summary
public int read(final char[] cbuf, final int off, final int len) throws IOException

Implements abstract java.io.Reader.read.

Doc from java.io.Reader.read.

Reads characters into a portion of an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.

If len is zero, then no characters are read and 0 is returned; otherwise, there is an attempt to read at least one character. If no character is available because the stream is at its end, the value -1 is returned; otherwise, at least one character is read and stored into cbuf.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
readyback to summary
public boolean ready() throws IOException

Overrides java.io.Reader.ready.

Doc from java.io.Reader.ready.

Tells whether this stream is ready to be read.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
readyDataback to summary
public int readyData()

Implements org.glassfish.grizzly.InputSource.readyData.

Annotations
@Override
recycleback to summary
protected void recycle()
resetback to summary
public void reset() throws IOException

Overrides java.io.Reader.reset.

Doc from java.io.Reader.reset.

Resets the stream. If the stream has been marked, then attempt to reposition it at the mark. If the stream has not been marked, then attempt to reset it in some way appropriate to the particular stream, for example by repositioning it to its starting point. Not all character-input streams support the reset() operation, and some support reset() without supporting mark().

Annotations
@Override
Exceptions
IOException:
If the stream has not been marked, or if the mark has been invalidated, or if the stream does not support reset(), or if some other I/O error occurs
shouldNotifyNowback to summary
private static boolean shouldNotifyNow(final int size, final int available)
Parameters
size:int

the amount of data that must be available for a ReadHandler to be notified.

available:int

the amount of data currently available.

Returns:boolean

true if the handler should be notified during a call to notifyAvailable(ReadHandler) or notifyAvailable(ReadHandler, int), otherwise false

skipback to summary
public long skip(final long n) throws IOException

Overrides java.io.Reader.skip.

Doc from java.io.Reader.skip.

Skips characters. This method will block until some characters are available, an I/O error occurs, or the end of the stream is reached. If the stream is already at its end before this method is invoked, then no characters are skipped and zero is returned.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs