|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.xlightweb.BodyDataSource
public class BodyDataSource
I/O resource capable of providing body data in a blocking way. Read operations will be suspended,
if not enough data is available.
The BBodyDataSource wraps a NonBlockingBodyDataSource
Field Summary | |
---|---|
static int |
DEFAULT_RECEIVE_TIMEOUT
|
Method Summary | |
---|---|
void |
close()
|
int |
getReceiveTimeoutSec()
gets receive time out by reading data |
boolean |
isMultipart()
return true if the body is a mulipart |
boolean |
isOpen()
returns, if the connection is open. |
void |
markReadPosition()
Marks the read position in the connection. |
int |
read(ByteBuffer buffer)
. |
byte |
readByte()
|
ByteBuffer[] |
readByteBuffer()
read the body |
ByteBuffer[] |
readByteBufferByDelimiter(String delimiter)
|
ByteBuffer[] |
readByteBufferByDelimiter(String delimiter,
int maxLength)
|
ByteBuffer[] |
readByteBufferByLength(int length)
|
byte[] |
readBytes()
read the body |
byte[] |
readBytesByDelimiter(String delimiter)
|
byte[] |
readBytesByDelimiter(String delimiter,
int maxLength)
|
byte[] |
readBytesByLength(int length)
|
double |
readDouble()
|
int |
readInt()
|
long |
readLong()
|
IPart |
readPart()
read the next part of the mulipart body. |
List<IPart> |
readParts()
return all parts of the multipart body. |
short |
readShort()
|
String |
readString()
read the body |
String |
readString(String encoding)
read the body |
String |
readStringByDelimiter(String delimiter)
|
String |
readStringByDelimiter(String delimiter,
int maxLength)
|
String |
readStringByDelimiter(String delimiter,
int maxLength,
String encoding)
read a string by using a delimiter |
String |
readStringByDelimiter(String delimiter,
String encoding)
read a string by using a delimiter |
String |
readStringByLength(int length)
|
String |
readStringByLength(int length,
String encoding)
read a string by using a length definition |
void |
removeReadMark()
remove the read mark |
boolean |
resetToReadMark()
Resets to the marked read position. |
void |
setReceiveTimeoutSec(int timeout)
sets the receive time out by reading data |
int |
size()
get the body size |
InputStream |
toInputStream()
returns this ReadableByteChannel as InputStream |
Reader |
toReader()
returns this ReadableByteChannel as Reader |
String |
toString()
|
long |
transferTo(BodyDataSink dataSink)
transfer the available data of the this source channel to the given data sink |
long |
transferTo(BodyDataSink dataSink,
int length)
transfer the data of the this source channel to the given data sink |
long |
transferTo(OutputStream dataSink)
transfer the available data of the this source channel to the given data sink |
long |
transferTo(WritableByteChannel target)
transfers the content to the given channel |
long |
transferTo(WritableByteChannel target,
int length)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int DEFAULT_RECEIVE_TIMEOUT
Method Detail |
---|
public void setReceiveTimeoutSec(int timeout)
timeout
- the receive timeoutpublic int getReceiveTimeoutSec()
public boolean isOpen()
isOpen
in interface Channel
public final boolean isMultipart()
public void close() throws IOException
close
in interface Closeable
close
in interface Channel
IOException
public int size() throws IOException
IOException
- if an exception occurspublic void markReadPosition()
public boolean resetToReadMark()
public void removeReadMark()
public IPart readPart() throws NoMultipartTypeException, IOException
isMultipart()
can
be used to verify if the body is a multipart one
// ... BlockingBodyDataSource body = response.getBlockingBody(); if (body.isMultipart()) { IPart part = body.readPart(); // ... } else { // ... }
IOException
- if an exception occurs
NoMultipartTypeException
- if the body type is not a multipart typepublic List<IPart> readParts() throws NoMultipartTypeException, IOException
isMultipart()
can
be used to verify if the body is a multipart one
// ... BlockingBodyDataSource body = response.getBlockingBody(); if (body.isMultipart()) { Listparts = body.readParts(); // ... } else { // ... }
IOException
- if an exception occurs
NoMultipartTypeException
- if the surrounding body type is not a multipart typepublic ByteBuffer[] readByteBuffer() throws IOException
IOException
- if an exception occurspublic byte[] readBytes() throws IOException
IOException
- if an exception occurspublic String readString() throws IOException
IOException
- if an exception occurspublic String readString(String encoding) throws IOException
encoding
- the encoding
IOException
- if an exception occurspublic int read(ByteBuffer buffer) throws IOException
read
in interface ReadableByteChannel
read
in interface IDataSource
IOException
public byte readByte() throws IOException, BufferUnderflowException, SocketTimeoutException
readByte
in interface IDataSource
IOException
BufferUnderflowException
SocketTimeoutException
public short readShort() throws IOException, BufferUnderflowException, SocketTimeoutException
readShort
in interface IDataSource
IOException
BufferUnderflowException
SocketTimeoutException
public int readInt() throws IOException, BufferUnderflowException, SocketTimeoutException
readInt
in interface IDataSource
IOException
BufferUnderflowException
SocketTimeoutException
public long readLong() throws IOException, BufferUnderflowException, SocketTimeoutException
readLong
in interface IDataSource
IOException
BufferUnderflowException
SocketTimeoutException
public double readDouble() throws IOException, BufferUnderflowException, SocketTimeoutException
readDouble
in interface IDataSource
IOException
BufferUnderflowException
SocketTimeoutException
public ByteBuffer[] readByteBufferByDelimiter(String delimiter) throws IOException, BufferUnderflowException, SocketTimeoutException
readByteBufferByDelimiter
in interface IDataSource
IOException
BufferUnderflowException
SocketTimeoutException
public ByteBuffer[] readByteBufferByDelimiter(String delimiter, int maxLength) throws IOException, BufferUnderflowException, MaxReadSizeExceededException, SocketTimeoutException
readByteBufferByDelimiter
in interface IDataSource
IOException
BufferUnderflowException
MaxReadSizeExceededException
SocketTimeoutException
public ByteBuffer[] readByteBufferByLength(int length) throws IOException, BufferUnderflowException, SocketTimeoutException
readByteBufferByLength
in interface IDataSource
IOException
BufferUnderflowException
SocketTimeoutException
public byte[] readBytesByDelimiter(String delimiter) throws IOException, BufferUnderflowException, SocketTimeoutException
readBytesByDelimiter
in interface IDataSource
IOException
BufferUnderflowException
SocketTimeoutException
public byte[] readBytesByDelimiter(String delimiter, int maxLength) throws IOException, BufferUnderflowException, MaxReadSizeExceededException, SocketTimeoutException
readBytesByDelimiter
in interface IDataSource
IOException
BufferUnderflowException
MaxReadSizeExceededException
SocketTimeoutException
public byte[] readBytesByLength(int length) throws IOException, BufferUnderflowException, SocketTimeoutException
readBytesByLength
in interface IDataSource
IOException
BufferUnderflowException
SocketTimeoutException
public String readStringByDelimiter(String delimiter) throws IOException, BufferUnderflowException, UnsupportedEncodingException, SocketTimeoutException
readStringByDelimiter
in interface IDataSource
IOException
BufferUnderflowException
UnsupportedEncodingException
SocketTimeoutException
public String readStringByDelimiter(String delimiter, String encoding) throws IOException, BufferUnderflowException, UnsupportedEncodingException, SocketTimeoutException
delimiter
- the delimiterencoding
- encoding
IOException
- If some other I/O error occurs
UnsupportedEncodingException
- if the default encoding is not supported
BufferUnderflowException
- if not enough data is available
SocketTimeoutException
- if a timeout occurspublic String readStringByDelimiter(String delimiter, int maxLength) throws IOException, BufferUnderflowException, UnsupportedEncodingException, MaxReadSizeExceededException, SocketTimeoutException
readStringByDelimiter
in interface IDataSource
IOException
BufferUnderflowException
UnsupportedEncodingException
MaxReadSizeExceededException
SocketTimeoutException
public String readStringByDelimiter(String delimiter, int maxLength, String encoding) throws IOException, BufferUnderflowException, UnsupportedEncodingException, MaxReadSizeExceededException, SocketTimeoutException
delimiter
- the delimitermaxLength
- the max length of bytes that should be read. If the limit is exceeded a MaxReadSizeExceededException will been thrownencoding
- the encoding
MaxReadSizeExceededException
- If the max read length has been exceeded and the delimiter hasn�t been found
IOException
- If some other I/O error occurs
UnsupportedEncodingException
- If the given encoding is not supported
BufferUnderflowException
- if not enough data is available
SocketTimeoutException
- if the timout is reachedpublic String readStringByLength(int length) throws IOException, BufferUnderflowException, UnsupportedEncodingException, SocketTimeoutException
readStringByLength
in interface IDataSource
IOException
BufferUnderflowException
UnsupportedEncodingException
SocketTimeoutException
public String readStringByLength(int length, String encoding) throws IOException, BufferUnderflowException, UnsupportedEncodingException, SocketTimeoutException
length
- the amount of bytes to readencoding
- the encoding
IOException
- If some other I/O error occurs
SocketTimeoutException
- if the timeout is reached
BufferUnderflowException
- if not enough data is available
UnsupportedEncodingException
public long transferTo(WritableByteChannel target, int length) throws IOException, BufferUnderflowException, SocketTimeoutException
transferTo
in interface IDataSource
IOException
BufferUnderflowException
SocketTimeoutException
public long transferTo(WritableByteChannel target) throws IOException, BufferUnderflowException, SocketTimeoutException
target
- the target channel
ClosedChannelException
- If either this channel or the target channel is closed
IOException
- If some other I/O error occurs
BufferUnderflowException
SocketTimeoutException
public long transferTo(BodyDataSink dataSink) throws ProtocolException, IOException, ClosedChannelException, BufferUnderflowException
dataSink
- the data sink
ClosedChannelException
- If either this channel or the target channel is closed
IOException
- If some other I/O error occurs
BufferUnderflowException
- if not enough data is available
ProtocolException
public long transferTo(OutputStream dataSink) throws ProtocolException, IOException, ClosedChannelException, BufferUnderflowException
dataSink
- the data sink
ClosedChannelException
- If either this channel or the target channel is closed
IOException
- If some other I/O error occurs
BufferUnderflowException
- if not enough data is available
ProtocolException
public long transferTo(BodyDataSink dataSink, int length) throws ProtocolException, IOException, ClosedChannelException, BufferUnderflowException
dataSink
- the data sinklength
- the size to transfer
ClosedChannelException
- If either this channel or the target channel is closed
IOException
- If some other I/O error occurs
BufferUnderflowException
- if not enough data is available
ProtocolException
public InputStream toInputStream()
ReadableByteChannel
as InputStream
public Reader toReader()
ReadableByteChannel
as Reader
public String toString()
toString
in class Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |