|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.gcube.contentmanagement.baselayer.BaseLayerStream
public class BaseLayerStream
This class provides a wrapper for arbitrary input streams. The intention here is to provide streams of known length, since some of the implementations of RawFileContentManager need this property. This version also provides some very basic support to determine the length of a stream by reading it into memory.
Field Summary | |
---|---|
static int |
END_OF_STREAM
Value that will be returned, when the stream end of the stream is reached and next byte was requested, e.g. |
static long |
NO_LIMIT
Defines that there is no limit set, on how many bytes to read at most from this stream. |
static long |
STREAM_LENGTH_IMPLICITE
Defines that the stream has no size, that is known before, so the length is given implicitely by reading until the END_OF_STREAM occurs. |
static int |
URL_CONNECTION_LENGTH_UNKNOWN
Defines the constant used by java.net.URLConnection to indicate, that the length of the content is unknown |
Constructor Summary | |
---|---|
BaseLayerStream(java.io.InputStream istream)
Convenience constructor, if length is unknown. |
|
BaseLayerStream(java.io.InputStream istream,
long length)
Contructor for a stream with a given length |
Method Summary | |
---|---|
void |
dispose()
Closes the BaseLayerStream which implies that all bound resources should be freed. |
java.io.InputStream |
getBufferedStream()
Returns a buffered stream for the wrapped stream |
int |
getBufferSize()
Return the number of bytes used for buffering |
static int |
getDefaultBufferSize()
Returns the default buffer size, which should be used in order to have buffers in similar size and therefore reduce overhead because calls for read(byte[]) will almost everytime fill the array entirely. |
long |
getLength()
Returns the defined length of the stream |
long |
getLimit()
Returns the limit |
java.io.InputStream |
getStream()
Returns the wrapped input stream |
void |
handleStartOffset(BasicStorageHints hints)
Evaluates whether a start offset has been requested by a hint and if so, performs the requested action. |
boolean |
hasImpliciteLength()
Returns whether the stream has an implicite length |
boolean |
isBuffered()
tells whether the stream is known to be buffered or not. |
boolean |
needsLimitTreatment()
A limit has been set for this stream |
void |
setBuffered(boolean isBuffered)
Sets if the stream is known to use some sort of internal buffering or is decorated by a BufferedInputStream already. |
void |
setBufferSize(int size)
Sets the size of the buffer used by this stream, initially set to getDefaultBufferSize() |
static void |
setDefaultBufferSize(int size)
Sets the default buffer size, which should be used in order to have buffers in similar size and therefore reduce overhead because calls for read(byte[]) will almost everytime fill the array entirely. |
void |
setLimit(BasicStorageHints hints)
Sets the limit iff this has been requested within the hints. |
void |
setLimit(long maximumLength)
Defines a maximum number of bytes that should be read from this stream. |
BaseLayerStream |
toFixedLengthStream()
Generic solution to determine stream length. |
long |
writeToStreamRespectingLimit(java.io.OutputStream out)
Writes the content of this stream to a output stream. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int URL_CONNECTION_LENGTH_UNKNOWN
URLConnection.getContentLength()
,
Constant Field Valuespublic static final long STREAM_LENGTH_IMPLICITE
public static final long NO_LIMIT
public static final int END_OF_STREAM
read()
.-1
to be consistend with many of
the InputStream
implementations in the java.io
-Package.
InputStream.read()
,
InputStream.read(byte[])
,
FileInputStream.read()
,
Constant Field ValuesConstructor Detail |
---|
public BaseLayerStream(java.io.InputStream istream)
WARNING: May harmful to execution speed. Prefer setting the length if known.
istream
- the stream that should be wrappedpublic BaseLayerStream(java.io.InputStream istream, long length)
istream
- the stream that should be wrappedlength
- the length in bytes of the streamMethod Detail |
---|
public static void setDefaultBufferSize(int size)
read(byte[])
will almost everytime fill the array entirely.
size
- the size a buffer should useInputStream.read(byte[])
public static int getDefaultBufferSize()
read(byte[])
will almost everytime fill the array entirely.
InputStream.read(byte[])
public void setBufferSize(int size)
getDefaultBufferSize()
size
- number of bytes to use for bufferingpublic int getBufferSize()
public java.io.InputStream getStream()
public java.io.InputStream getBufferedStream()
isBuffered()
public boolean isBuffered()
java.io.BufferedInputStream
BufferedInputStream
public void setBuffered(boolean isBuffered)
isBuffered
- true, if the wrapped stream is buffered itselfpublic long getLength()
public boolean hasImpliciteLength()
public void setLimit(long maximumLength)
If this number has been read, it should be considered as if stream ended there. The number can exceed the actual number of bytes that the stream contains, in other words, the end of stream still needs to be checked.
maximumLength
- the number of bytespublic boolean needsLimitTreatment()
public long getLimit()
public void setLimit(BasicStorageHints hints) throws ValueNotValidException
Implicitely handles also a start offste (if set), because otherwise the result will be false.
hints
- the hints that should be used to determine limit
ValueNotValidException
- if something goes wrongBasicStorageHints#HINT_NAME_LIMIT_CONTENT_LENGTH_READ
public void handleStartOffset(BasicStorageHints hints) throws ValueNotValidException
hints
- the hints where this may get requested
BaseLayerException
- if something goes wrong
ValueNotValidException
public long writeToStreamRespectingLimit(java.io.OutputStream out) throws BaseLayerException
While doing this, any imposed limit on the bytes to transfer is taken care of.
out
- the stream to which the content should be written
BaseLayerException
- if something goes wrongpublic void dispose() throws BaseLayerException
BaseLayerException
- if something goes wrongpublic BaseLayerStream toFixedLengthStream() throws BaseLayerException
BaseLayerException
- if something goes wrong
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |