juju.reattore.io.impl
Class ChannelFileSource

java.lang.Object
  |
  +--juju.reattore.io.impl.ChannelFileSource
All Implemented Interfaces:
BulkByteSource, ByteSource, CachableSource, FileSource, Source

public class ChannelFileSource
extends java.lang.Object
implements FileSource, CachableSource, BulkByteSource

A byte source that serves from a file using channels. Implemented by reading the whole file into a byte buffer.


Field Summary
 
Fields inherited from interface juju.reattore.io.Source
EOF
 
Constructor Summary
ChannelFileSource(java.io.File file)
          Create a new source around the given file.
 
Method Summary
 void dispose()
          Called when the user is finished with this source.
 int get()
          Gets the next byte from the stream.
 int get(byte[] into, int offset, int length)
          Bulk get operation.
 java.nio.ByteBuffer getBulk()
          Returns the next chunk of the source in a ByteBuffer.
 boolean isExpired()
          Called before the source is used, and may be used to mark this source as expired and in need of re-generation.
 void release()
          Releases this source from the cache.
 int remaining()
          Returns the number of elements remaining in the stream.
 void rewind()
          Resets this source into the original state.
 void setCacheCallback(Cache ch)
          Binds this source to a cache.
 void setReadSize(int to)
          Test method that changes the maximum size a file may be before it is chunked into parts.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChannelFileSource

public ChannelFileSource(java.io.File file)
                  throws java.io.IOException
Create a new source around the given file.

Parameters:
file - The file to wrap around.
Throws:
java.io.IOException - if the file cannot be opened.
Method Detail

setReadSize

public void setReadSize(int to)
Test method that changes the maximum size a file may be before it is chunked into parts.

Parameters:
to - The maximum size in bytes.

getBulk

public java.nio.ByteBuffer getBulk()
                            throws java.io.IOException
Description copied from interface: BulkByteSource
Returns the next chunk of the source in a ByteBuffer. This buffer should be read until empty. Subsequent calls advance on by the buffer size and ignore any unread data in the buffer. The buffer is empty (remaining = 0) on EOF.

Specified by:
getBulk in interface BulkByteSource
Returns:
The next chunk of the source in a buffer.
Throws:
java.io.IOException - on error.
See Also:
BulkByteSource

get

public int get()
        throws java.io.IOException
Description copied from interface: ByteSource
Gets the next byte from the stream.

Specified by:
get in interface ByteSource
Returns:
The next byte, or EOF on end of stream.
Throws:
java.io.IOException - on error.
See Also:
ByteSource

get

public int get(byte[] into,
               int offset,
               int length)
        throws java.io.IOException
Description copied from interface: ByteSource
Bulk get operation.

Specified by:
get in interface ByteSource
Parameters:
into - The buffer to get into.
offset - The offset in the buffer to begin writing at.
length - The maximum number of elements to read.
Returns:
The number of elements read.
Throws:
java.io.IOException - on error.
See Also:
ByteSource

remaining

public int remaining()
              throws java.io.IOException
Description copied from interface: ByteSource
Returns the number of elements remaining in the stream.

Specified by:
remaining in interface ByteSource
Returns:
Number remaining, or a negative number if it is unknown.
Throws:
java.io.IOException - on error.
See Also:
ByteSource

release

public void release()
Description copied from interface: CachableSource
Releases this source from the cache. Used to release any resources.

Specified by:
release in interface CachableSource
See Also:
CachableSource

dispose

public void dispose()
Description copied from interface: Source
Called when the user is finished with this source. The source is invalid after this call.

Specified by:
dispose in interface Source
See Also:
Source

rewind

public void rewind()
Description copied from interface: CachableSource
Resets this source into the original state. Called before placing back into the cache.

Specified by:
rewind in interface CachableSource
See Also:
CachableSource

isExpired

public boolean isExpired()
Description copied from interface: CachableSource
Called before the source is used, and may be used to mark this source as expired and in need of re-generation. May not always be called before re-use.

Specified by:
isExpired in interface CachableSource
Returns:
true If this source is expired and should be re-loaded.
See Also:
CachableSource

setCacheCallback

public void setCacheCallback(Cache ch)
Description copied from interface: CachableSource
Binds this source to a cache. The source must call Cache.onClose() when closed and allow the cache to cancel the close.

Specified by:
setCacheCallback in interface CachableSource
Parameters:
ch - The cache to bind to.
See Also:
CachableSource


Copyright © 2002-2003 Michael Hope. All Rights Reserved.