|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object ikrs.httpd.resource.AbstractResource ikrs.httpd.resource.InterruptableResource
public class InterruptableResource
The interruptable resource does not refer to Thread interruption, but to a Resource that allows to stop the read process at a random point, then resuming it (after the last read byte) and telling the observer the read process would be at byte position 0 (adjusting the old length value, off course). It can be used to read a portion of data from the beginning of the underlying input stream (such as header data), then stopping and - after processing the received data - passing the resource to a different instance telling the byte position would be still at the beginning of the stream. This should be used to avoid copying the rest of the stream into a new buffer resource, but continue reading at the current position. The method for resetting the stream index is the 'resetBytePosition()' method. Note that this class uses the ikrs.io.BytePositionInputStream, which does not support the 'mark()' and 'reset()' methods yet.
Constructor Summary | |
---|---|
InterruptableResource(HTTPHandler handler,
CustomLogger logger,
Resource resource,
boolean useFairLocks)
Create a new InterruptableResource from the given Resource. |
Method Summary | |
---|---|
boolean |
close()
Closes this resource. |
long |
getBytePosition()
Get the current read position (since initialization or last 'resetBytePosition()' call). |
BytePositionInputStream |
getInputStream()
Get the input stream from this resource. |
long |
getLength()
This method returns the *actual* length of the underlying resource. |
java.io.OutputStream |
getOutputStream()
Get the output stream to this resource. |
boolean |
isOpen()
This method determines if this resource was alerady opened or not. |
boolean |
isReadOnly()
This method returns true if the underlying resource is read-only (in general). |
void |
open(boolean readOnly)
This method opens the underlying resource. |
long |
resetBytePosition()
Resets the current byte position to 0. |
Methods inherited from class ikrs.httpd.resource.AbstractResource |
---|
getHTTPHandler, getHypertextAccessFile, getLogger, getMetaData, getReadLock, getWriteLock, setHypertextAccessFile |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public InterruptableResource(HTTPHandler handler, CustomLogger logger, Resource resource, boolean useFairLocks) throws java.lang.NullPointerException
logger
- A custom logger to write log messages to (must not be null).pb
- The process builder to use (must not be null).useFairLocks
- If set to true the class will use fair read locks (writing isn't
possible at all with this class).
java.lang.NullPointerException
- If logger or pb is null.Method Detail |
---|
public long getBytePosition()
public long resetBytePosition()
public void open(boolean readOnly) throws ReadOnlyException, java.io.IOException
open
in interface Resource
open
in class AbstractResource
readOnly
- if set to true, the resource will be opened in read-only mode.
ReadOnlyException
- If the underlying resource is read-only in general.
java.io.IOException
- If any other IO error occurs.isReadOnly()
public boolean isOpen() throws java.io.IOException
isOpen
in interface Resource
isOpen
in class AbstractResource
java.io.IOException
- If any IO error occurs.public boolean isReadOnly() throws java.io.IOException
isReadOnly
in interface Resource
isReadOnly
in class AbstractResource
java.io.IOException
- If any IO error occurs.public long getLength() throws java.io.IOException
getLength
in interface Resource
getLength
in class AbstractResource
java.io.IOException
- If any IO error occurs.public java.io.OutputStream getOutputStream() throws ReadOnlyException, java.io.IOException
getOutputStream
in interface Resource
getOutputStream
in class AbstractResource
ReadOnlyException
- If this resource was opened with the read-only flag set.
java.io.IOException
- If any other IO error occurs.public BytePositionInputStream getInputStream() throws java.io.IOException
getInputStream
in interface Resource
getInputStream
in class AbstractResource
java.io.IOException
- If any IO error occurs.public boolean close() throws java.io.IOException
close
in interface Resource
close
in class AbstractResource
java.io.IOException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |