com.alachisoft.jvcache.web.caching
Class CacheStream

java.lang.Object
  extended by com.alachisoft.jvcache.web.caching.CacheStream

public final class CacheStream
extends java.lang.Object

CacheStream is derived from System.IO.Stream. It is designed to put/fetch BLOB using standard Stream interface.


Method Summary
 boolean canRead()
          Check whether stream supports reading.
 boolean canSeek()
          Gets a value indicating whether the current stream supports seeking.
 boolean canWrite()
          Gets a value indicating whether the current stream supports writing.
 void close()
          Closes the current stream and releases any resources associated with the current stream.
 void flush()
           
 java.io.BufferedInputStream getBufferedInputStream()
          Gets java.io.BufferedInputStream of given buffer size.
 java.io.BufferedInputStream getBufferedInputStream(int bufferSize)
          Gets java.io.BufferedInputStream of given buffer size.
 java.io.BufferedOutputStream getBufferedOutputStream()
          Gets java.io.BufferedOutputStream of given buffer size.
 java.io.BufferedOutputStream getBufferedOutputStream(int bufferSize)
          Gets java.io.BufferedOutputStream of given buffer size.
 long length()
          Gets the length of the stream.
 long position()
          Gets the position within current stream.
 int read(byte[] buffer, int offset, int count)
          Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
 long seek(long offset)
          Sets the position within the current stream.
 void setLength(long value)
          Sets the length of the stream.
 void write(byte[] buffer, int offset, int count)
          Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getBufferedInputStream

public java.io.BufferedInputStream getBufferedInputStream(int bufferSize)
                                                   throws java.lang.Exception
Gets java.io.BufferedInputStream of given buffer size. CacheStream does not buffer the data. Each read/write operation performed on the stream is propagated to cache. However this can cause performance issues if small chunks of data are being read/written from/to stream. java.io.BufferedInputStream supports buffering of data. This method returns an instance of java.io.BufferedInputStream which encapsulates CacheStream.

Parameters:
bufferSize - size of of buffer stream
Returns:
An instance ofjava.io.BufferedInputStream of specified buffer size.
Throws:
java.lang.Exception

getBufferedOutputStream

public java.io.BufferedOutputStream getBufferedOutputStream(int bufferSize)
                                                     throws java.lang.Exception
Gets java.io.BufferedOutputStream of given buffer size. CacheStream does not buffer the data. Each read/write operation performed on the stream is propagated to cache. However this can cause performance issues if small chunks of data are being read/written from/to stream. java.io.BufferedOutputStream supports buffering of data. This method returns an instance of java.io.BufferedOutputStream which encapsulates CacheStream.

Parameters:
bufferSize - size of of buffer stream
Returns:
An instance ofjava.io.BufferedOutputStream of specified buffer size.
Throws:
java.lang.Exception

getBufferedInputStream

public java.io.BufferedInputStream getBufferedInputStream()
                                                   throws java.lang.Exception
Gets java.io.BufferedInputStream of given buffer size. CacheStream does not buffer the data. Each read/write operation performed on the stream is propagated to cache. However this can cause performance issues if small chunks of data are being read/written from/to stream. java.io.BufferedInputStream supports buffering of data. This method returns an instance of java.io.BufferedInputStream which encapsulates CacheStream.

Returns:
An instance ofjava.io.BufferedInputStream of 4kb.
Throws:
java.lang.Exception

getBufferedOutputStream

public java.io.BufferedOutputStream getBufferedOutputStream()
                                                     throws java.lang.Exception
Gets java.io.BufferedOutputStream of given buffer size. CacheStream does not buffer the data. Each read/write operation performed on the stream is propagated to cache. However this can cause performance issues if small chunks of data are being read/written from/to stream. java.io.BufferedOutputStream supports buffering of data. This method returns an instance of java.io.BufferedOutputStream which encapsulates CacheStream.

Parameters:
bufferSize - size of of buffer stream
Returns:
An instance ofjava.io.BufferedOutputStream of specified buffer size.
Throws:
java.lang.Exception

length

public long length()
            throws java.lang.Exception
Gets the length of the stream.

Returns:
length of current stream
Throws:
java.lang.Exception

canRead

public boolean canRead()
Check whether stream supports reading.

Returns:
True' if stream is opened with either StreamMode.Read or StreamMode.ReadWithoutLock.

canSeek

public boolean canSeek()
Gets a value indicating whether the current stream supports seeking.

Returns:
Alwasy returns 'False' because CacheStream does not support seek operation.

canWrite

public boolean canWrite()
Gets a value indicating whether the current stream supports writing.

Returns:
Returns 'True' if stream is opened with StreamMode.Write

flush

public void flush()

position

public long position()
              throws java.lang.Exception
Gets the position within current stream.

Returns:
Always return 'False' as Stream does not support seeking
Throws:
java.lang.Exception

read

public int read(byte[] buffer,
                int offset,
                int count)
         throws java.lang.Exception
Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.

Parameters:
buffer - An array of bytes. When this method returns, the buffer contains the specified byte array with the values between offset and (offset + count - 1) replaced by the bytes read from the current source.
offset - The zero-based byte offset in buffer at which to begin storing the data read from the current stream.
count - The maximum number of bytes to be read from the current stream.
Returns:
The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available or zero (0) if the end of the stream has been reached.
Throws:
java.lang.Exception

seek

public long seek(long offset)
          throws NotSupportedException
Sets the position within the current stream.

Parameters:
offset - A value of type SeekOrigin indicating the reference point used to obtain the new position.
Returns:
A value of type SeekOrigin indicating the reference point used to obtain the new position.
Throws:
NotSupportedException - Stream does not support seeking

setLength

public void setLength(long value)
               throws NotSupportedException
Sets the length of the stream.

Parameters:
value - The desired length of the current stream in bytes.
Throws:
NotSupportedException - Stream does not support both writing and seeking

write

public void write(byte[] buffer,
                  int offset,
                  int count)
           throws java.lang.Exception
Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.

Parameters:
buffer - An array of bytes. This method copies count bytes from buffer to the current stream.
offset - The zero-based byte offset in buffer at which to begin copying bytes to the current stream.
count - The number of bytes to be written to the current stream.
Throws:
java.lang.Exception

close

public void close()
           throws java.lang.Exception
Closes the current stream and releases any resources associated with the current stream.

Throws:
java.lang.Exception