Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

juju.reattore.io.impl
Class ChannelFileSource  view ChannelFileSource download ChannelFileSource.java

java.lang.Object
  extended byjuju.reattore.io.impl.ChannelFileSource
All Implemented Interfaces:
juju.reattore.io.BulkByteSource, juju.reattore.io.ByteSource, juju.reattore.io.CachableSource, juju.reattore.io.FileSource, juju.reattore.io.Source

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

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


Field Summary
private  java.nio.ByteBuffer bb
           
private  juju.reattore.io.Cache cache
           
private static int CHECK_INTERVAL
           
private  int checkIn
           
private  java.nio.channels.FileChannel fch
           
private  java.io.File file
           
private  boolean firstRead
           
private  boolean oversized
           
private  int readSize
           
private  int size
           
private  long stamp
           
 
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.
private  void read()
           
 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(juju.reattore.io.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.
private  void setup()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cache

private juju.reattore.io.Cache cache

file

private java.io.File file

fch

private java.nio.channels.FileChannel fch

size

private int size

readSize

private int readSize

bb

private java.nio.ByteBuffer bb

oversized

private boolean oversized

firstRead

private boolean firstRead

CHECK_INTERVAL

private static final int CHECK_INTERVAL
See Also:
Constant Field Values

stamp

private long stamp

checkIn

private int checkIn
Constructor Detail

ChannelFileSource

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

Method Detail

setup

private void setup()

read

private void read()
           throws java.io.IOException

setReadSize

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


getBulk

public java.nio.ByteBuffer getBulk()
                            throws java.io.IOException
Description copied from interface: juju.reattore.io.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 juju.reattore.io.BulkByteSource

get

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

Specified by:
get in interface juju.reattore.io.ByteSource

get

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

Specified by:
get in interface juju.reattore.io.ByteSource

remaining

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

Specified by:
remaining in interface juju.reattore.io.ByteSource

release

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

Specified by:
release in interface juju.reattore.io.CachableSource

dispose

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

Specified by:
dispose in interface juju.reattore.io.Source

rewind

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

Specified by:
rewind in interface juju.reattore.io.CachableSource

isExpired

public boolean isExpired()
Description copied from interface: juju.reattore.io.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 juju.reattore.io.CachableSource

setCacheCallback

public void setCacheCallback(juju.reattore.io.Cache ch)
Description copied from interface: juju.reattore.io.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 juju.reattore.io.CachableSource