jwutil.io
Class MyFileChannelImpl

java.lang.Object
  extended by java.nio.channels.spi.AbstractInterruptibleChannel
      extended by java.nio.channels.FileChannel
          extended by jwutil.io.MyFileChannelImpl
All Implemented Interfaces:
java.io.Closeable, java.nio.channels.ByteChannel, java.nio.channels.Channel, java.nio.channels.GatheringByteChannel, java.nio.channels.InterruptibleChannel, java.nio.channels.ReadableByteChannel, java.nio.channels.ScatteringByteChannel, java.nio.channels.WritableByteChannel

public class MyFileChannelImpl
extends java.nio.channels.FileChannel
implements java.nio.channels.ReadableByteChannel, java.nio.channels.WritableByteChannel

An implementation of FileChannel that is backed by a FileInputStream, FileOutputStream, or RandomAccessFile. This is useful on virtual machines that do not support the normal FileChannel methods (like JDK 1.3). Not all functionality has been implemented yet.

Version:
$Id: MyFileChannelImpl.java 2279 2005-05-28 10:24:54Z joewhaley $
Author:
John Whaley

Nested Class Summary
 
Nested classes/interfaces inherited from class java.nio.channels.FileChannel
java.nio.channels.FileChannel.MapMode
 
Field Summary
protected  long currentPosition
           
protected  java.io.FileInputStream fis
           
protected  java.io.FileOutputStream fos
           
protected  java.io.RandomAccessFile raf
           
 
Method Summary
 void force(boolean arg0)
           
static java.nio.channels.FileChannel getFileChannel(java.lang.Object o)
          Gets the file channel for the given object.
protected  void implCloseChannel()
           
 java.nio.channels.FileLock lock(long arg0, long arg1, boolean arg2)
           
 java.nio.MappedByteBuffer map(java.nio.channels.FileChannel.MapMode arg0, long arg1, long arg2)
           
 long position()
           
 java.nio.channels.FileChannel position(long arg0)
           
 int read(java.nio.ByteBuffer b)
           
 long read(java.nio.ByteBuffer[] b, int offset, int length)
           
 int read(java.nio.ByteBuffer arg0, long arg1)
           
 long size()
           
 long transferFrom(java.nio.channels.ReadableByteChannel arg0, long arg1, long arg2)
           
 long transferTo(long arg0, long arg1, java.nio.channels.WritableByteChannel arg2)
           
 java.nio.channels.FileChannel truncate(long arg0)
           
 java.nio.channels.FileLock tryLock(long arg0, long arg1, boolean arg2)
           
 int write(java.nio.ByteBuffer b)
           
 long write(java.nio.ByteBuffer[] b, int offset, int length)
           
 int write(java.nio.ByteBuffer arg0, long arg1)
           
 
Methods inherited from class java.nio.channels.FileChannel
lock, read, tryLock, write
 
Methods inherited from class java.nio.channels.spi.AbstractInterruptibleChannel
begin, close, end, isOpen
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.nio.channels.Channel
close, isOpen
 
Methods inherited from interface java.nio.channels.Channel
close, isOpen
 

Field Detail

fis

protected java.io.FileInputStream fis

fos

protected java.io.FileOutputStream fos

raf

protected java.io.RandomAccessFile raf

currentPosition

protected long currentPosition
Method Detail

getFileChannel

public static java.nio.channels.FileChannel getFileChannel(java.lang.Object o)
                                                    throws java.io.IOException
Gets the file channel for the given object. Assumes the object either has a getChannel() method, or it is a FileInputStream, FileOutputStream, or RandomAccessFile.

Parameters:
o - object to get file channel from
Returns:
the file channel
Throws:
java.io.IOException - if an IO exception occurred while getting the channel

read

public int read(java.nio.ByteBuffer b)
         throws java.io.IOException
Specified by:
read in interface java.nio.channels.ReadableByteChannel
Specified by:
read in class java.nio.channels.FileChannel
Throws:
java.io.IOException
See Also:
ReadableByteChannel.read(ByteBuffer)

read

public long read(java.nio.ByteBuffer[] b,
                 int offset,
                 int length)
          throws java.io.IOException
Specified by:
read in interface java.nio.channels.ScatteringByteChannel
Specified by:
read in class java.nio.channels.FileChannel
Throws:
java.io.IOException
See Also:
ScatteringByteChannel.read(ByteBuffer[], int, int)

write

public int write(java.nio.ByteBuffer b)
          throws java.io.IOException
Specified by:
write in interface java.nio.channels.WritableByteChannel
Specified by:
write in class java.nio.channels.FileChannel
Throws:
java.io.IOException
See Also:
WritableByteChannel.write(ByteBuffer)

write

public long write(java.nio.ByteBuffer[] b,
                  int offset,
                  int length)
           throws java.io.IOException
Specified by:
write in interface java.nio.channels.GatheringByteChannel
Specified by:
write in class java.nio.channels.FileChannel
Throws:
java.io.IOException
See Also:
GatheringByteChannel.write(ByteBuffer[], int, int)

position

public long position()
              throws java.io.IOException
Specified by:
position in class java.nio.channels.FileChannel
Throws:
java.io.IOException
See Also:
FileChannel.position()

position

public java.nio.channels.FileChannel position(long arg0)
                                       throws java.io.IOException
Specified by:
position in class java.nio.channels.FileChannel
Throws:
java.io.IOException
See Also:
FileChannel.position(long)

size

public long size()
          throws java.io.IOException
Specified by:
size in class java.nio.channels.FileChannel
Throws:
java.io.IOException
See Also:
FileChannel.size()

truncate

public java.nio.channels.FileChannel truncate(long arg0)
                                       throws java.io.IOException
Specified by:
truncate in class java.nio.channels.FileChannel
Throws:
java.io.IOException
See Also:
FileChannel.truncate(long)

force

public void force(boolean arg0)
           throws java.io.IOException
Specified by:
force in class java.nio.channels.FileChannel
Throws:
java.io.IOException
See Also:
FileChannel.force(boolean)

read

public int read(java.nio.ByteBuffer arg0,
                long arg1)
         throws java.io.IOException
Specified by:
read in class java.nio.channels.FileChannel
Throws:
java.io.IOException
See Also:
FileChannel.read(ByteBuffer, long)

write

public int write(java.nio.ByteBuffer arg0,
                 long arg1)
          throws java.io.IOException
Specified by:
write in class java.nio.channels.FileChannel
Throws:
java.io.IOException
See Also:
FileChannel.write(ByteBuffer, long)

implCloseChannel

protected void implCloseChannel()
                         throws java.io.IOException
Specified by:
implCloseChannel in class java.nio.channels.spi.AbstractInterruptibleChannel
Throws:
java.io.IOException
See Also:
AbstractInterruptibleChannel.implCloseChannel()

transferFrom

public long transferFrom(java.nio.channels.ReadableByteChannel arg0,
                         long arg1,
                         long arg2)
                  throws java.io.IOException
Specified by:
transferFrom in class java.nio.channels.FileChannel
Throws:
java.io.IOException
See Also:
FileChannel.transferFrom(ReadableByteChannel, long, long)

transferTo

public long transferTo(long arg0,
                       long arg1,
                       java.nio.channels.WritableByteChannel arg2)
                throws java.io.IOException
Specified by:
transferTo in class java.nio.channels.FileChannel
Throws:
java.io.IOException
See Also:
FileChannel.transferTo(long, long, WritableByteChannel)

lock

public java.nio.channels.FileLock lock(long arg0,
                                       long arg1,
                                       boolean arg2)
                                throws java.io.IOException
Specified by:
lock in class java.nio.channels.FileChannel
Throws:
java.io.IOException
See Also:
FileChannel.lock(long, long, boolean)

map

public java.nio.MappedByteBuffer map(java.nio.channels.FileChannel.MapMode arg0,
                                     long arg1,
                                     long arg2)
                              throws java.io.IOException
Specified by:
map in class java.nio.channels.FileChannel
Throws:
java.io.IOException
See Also:
FileChannel.map(MapMode, long, long)

tryLock

public java.nio.channels.FileLock tryLock(long arg0,
                                          long arg1,
                                          boolean arg2)
                                   throws java.io.IOException
Specified by:
tryLock in class java.nio.channels.FileChannel
Throws:
java.io.IOException
See Also:
FileChannel.tryLock(long, long, boolean)


Copyright © 2004-2008 SUIF Compiler Group. All Rights Reserved.