uk.me.parabola.imgfmt.sys
Class FileImgChannel

java.lang.Object
  extended by uk.me.parabola.imgfmt.sys.FileImgChannel
All Implemented Interfaces:
java.io.Closeable, java.nio.channels.ByteChannel, java.nio.channels.Channel, java.nio.channels.ReadableByteChannel, java.nio.channels.WritableByteChannel, ImgChannel

public class FileImgChannel
extends java.lang.Object
implements ImgChannel

This is an implementation of ImgChannel that delegates to a regular channel. It can therefore be used to read or write regular files on the file system.

Author:
Steve Ratcliffe

Constructor Summary
FileImgChannel(java.nio.channels.FileChannel channel)
           
FileImgChannel(java.lang.String filename)
           
FileImgChannel(java.lang.String filename, java.lang.String mode)
           
 
Method Summary
 void close()
           
 boolean isOpen()
           
 long position()
          Get the file position.
 void position(long pos)
          Set the position within the file.
 int read(java.nio.ByteBuffer dst)
           
 int write(java.nio.ByteBuffer src)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileImgChannel

public FileImgChannel(java.lang.String filename)

FileImgChannel

public FileImgChannel(java.lang.String filename,
                      java.lang.String mode)

FileImgChannel

public FileImgChannel(java.nio.channels.FileChannel channel)
Method Detail

read

public int read(java.nio.ByteBuffer dst)
         throws java.io.IOException
Specified by:
read in interface java.nio.channels.ReadableByteChannel
Throws:
java.io.IOException

isOpen

public boolean isOpen()
Specified by:
isOpen in interface java.nio.channels.Channel

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Specified by:
close in interface java.nio.channels.Channel
Throws:
java.io.IOException

write

public int write(java.nio.ByteBuffer src)
          throws java.io.IOException
Specified by:
write in interface java.nio.channels.WritableByteChannel
Throws:
java.io.IOException

position

public long position()
Get the file position. Note that this is a logical position relative to the beginning of the file (the file within the .img file, not the beginning of the .img file itself).

Specified by:
position in interface ImgChannel
Returns:
The offset in bytes from the beginning of the file.

position

public void position(long pos)
Set the position within the file.

Specified by:
position in interface ImgChannel
Parameters:
pos - The position to set.