org.blinkenbyte.io
Class NormalBlockDevice

java.lang.Object
  extended by org.blinkenbyte.io.NormalBlockDevice
All Implemented Interfaces:
BlockDevice

public class NormalBlockDevice
extends java.lang.Object
implements BlockDevice

This class implements a normal BlockDevice by wrapping a ReadWriteDevice.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.blinkenbyte.io.BlockDevice
BlockDevice.DriveGeometry
 
Constructor Summary
NormalBlockDevice()
          Constructs a new uninitialized NormalBlockDevice.
 
Method Summary
 void close()
          Close the device.
 boolean getAutoSectorAlign()
          Returns whether the device is set to automatically align reads/writes to sector boundaries.
 BlockDevice.DriveGeometry getDriveGeometry()
          Throws an exception; since this class is normally used for files, it has no geometry.
 long getFilePointer()
          Returns the current pointer for read and write operations.
 int getSectorSize()
          Returns the sector size of the device.
 int getSectorSizeLog()
          Returns the base 2 logarithm of the sector size of the device.
 long length()
          Returns the size in bytes of the device.
 void open(java.lang.String filename, boolean allowWrite, boolean syncWriteData, boolean syncWriteMetaData, boolean _sectorMode)
          Uses the specified filename and parameters to create a new ReadWriteFile which will be wrapped by this object.
 int read()
          Reads and returns a single byte.
 int read(byte[] b)
          Reads bytes into the array.
 int read(byte[] b, int offset, int len)
          Reads bytes into the array.
 void seek(long pos)
          Seeks the read/write pointer to the specified position.
 void setAutoSectorAlign(boolean _autoSectorAlign)
          Sets whether the device should automatically align read/write requests.
 void setReadWriteDevice(ReadWriteDevice _rwd, boolean _sectorMode)
          Sets the internal ReadWriteDevice this object wraps, and whether sector mode should be enforced.
 void setSectorSize(int _sectorSize)
          Sets the sector size of the device.
 int skipBytes(int n)
          Advances the read/write pointer n bytes.
 void write(byte[] b)
          Writes the contents of b to the device.
 void write(byte[] b, int offset, int len)
          Writes len bytes to the device starting from b[offset].
 void write(int b)
          Writes one byte to the device.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NormalBlockDevice

public NormalBlockDevice()
Constructs a new uninitialized NormalBlockDevice.

Method Detail

close

public void close()
           throws java.io.IOException
Description copied from interface: BlockDevice
Close the device.

Specified by:
close in interface BlockDevice
Throws:
java.io.IOException

setReadWriteDevice

public void setReadWriteDevice(ReadWriteDevice _rwd,
                               boolean _sectorMode)
Sets the internal ReadWriteDevice this object wraps, and whether sector mode should be enforced.


open

public void open(java.lang.String filename,
                 boolean allowWrite,
                 boolean syncWriteData,
                 boolean syncWriteMetaData,
                 boolean _sectorMode)
          throws java.lang.Exception
Uses the specified filename and parameters to create a new ReadWriteFile which will be wrapped by this object.

Specified by:
open in interface BlockDevice
Parameters:
filename - The filename or device name to open
allowWrite - If true, allow write access to the device.
syncWriteData - If true, always flush writes to the device.
syncWriteMetaData - If true, always flush writes of the device's metadata.
_sectorMode - If true, all reads and writes should be on sector boundaries, and exceptions should be thrown if a request is not aligned.
Throws:
java.lang.Exception

getFilePointer

public long getFilePointer()
                    throws java.io.IOException
Description copied from interface: BlockDevice
Returns the current pointer for read and write operations.

Specified by:
getFilePointer in interface BlockDevice
Throws:
java.io.IOException

length

public long length()
            throws java.io.IOException
Description copied from interface: BlockDevice
Returns the size in bytes of the device.

Specified by:
length in interface BlockDevice
Throws:
java.io.IOException

read

public int read()
         throws java.io.IOException
Description copied from interface: BlockDevice
Reads and returns a single byte.

Specified by:
read in interface BlockDevice
Throws:
java.io.IOException

read

public int read(byte[] b)
         throws java.io.IOException
Description copied from interface: BlockDevice
Reads bytes into the array. Unless the end of the device has been reached, at least one byte will be read, and at most b.length bytes.

Specified by:
read in interface BlockDevice
Throws:
java.io.IOException

read

public int read(byte[] b,
                int offset,
                int len)
         throws java.io.IOException
Description copied from interface: BlockDevice
Reads bytes into the array. Unless the end of the device has been reached, at least one byte will be read, and at most len bytes.

Specified by:
read in interface BlockDevice
Throws:
java.io.IOException

seek

public void seek(long pos)
          throws java.io.IOException
Description copied from interface: BlockDevice
Seeks the read/write pointer to the specified position. Position is 0-based.

Specified by:
seek in interface BlockDevice
Throws:
java.io.IOException

skipBytes

public int skipBytes(int n)
              throws java.io.IOException
Description copied from interface: BlockDevice
Advances the read/write pointer n bytes.

Specified by:
skipBytes in interface BlockDevice
Throws:
java.io.IOException

write

public void write(byte[] b)
           throws java.io.IOException
Description copied from interface: BlockDevice
Writes the contents of b to the device.

Specified by:
write in interface BlockDevice
Throws:
java.io.IOException

write

public void write(byte[] b,
                  int offset,
                  int len)
           throws java.io.IOException
Description copied from interface: BlockDevice
Writes len bytes to the device starting from b[offset].

Specified by:
write in interface BlockDevice
Throws:
java.io.IOException

write

public void write(int b)
           throws java.io.IOException
Description copied from interface: BlockDevice
Writes one byte to the device.

Specified by:
write in interface BlockDevice
Throws:
java.io.IOException

getDriveGeometry

public BlockDevice.DriveGeometry getDriveGeometry()
                                           throws java.lang.Exception
Throws an exception; since this class is normally used for files, it has no geometry.

Specified by:
getDriveGeometry in interface BlockDevice
Throws:
java.lang.Exception

getSectorSize

public int getSectorSize()
Description copied from interface: BlockDevice
Returns the sector size of the device.

Specified by:
getSectorSize in interface BlockDevice

setSectorSize

public void setSectorSize(int _sectorSize)
                   throws java.lang.Exception
Description copied from interface: BlockDevice
Sets the sector size of the device.

Specified by:
setSectorSize in interface BlockDevice
Throws:
java.lang.Exception

getSectorSizeLog

public int getSectorSizeLog()
Description copied from interface: BlockDevice
Returns the base 2 logarithm of the sector size of the device.

Specified by:
getSectorSizeLog in interface BlockDevice

getAutoSectorAlign

public boolean getAutoSectorAlign()
Description copied from interface: BlockDevice
Returns whether the device is set to automatically align reads/writes to sector boundaries. If an unaligned read is performed, an aligned read should be performed and the relevant part of the data copied to the buffer. If an unaligned write is performed, an aligned read should be performed to get the values of the bytes not being written, after which an aligned write should be performed.

Specified by:
getAutoSectorAlign in interface BlockDevice

setAutoSectorAlign

public void setAutoSectorAlign(boolean _autoSectorAlign)
Description copied from interface: BlockDevice
Sets whether the device should automatically align read/write requests.

Specified by:
setAutoSectorAlign in interface BlockDevice