nachos.machine
Class OpenFileWithPosition

java.lang.Object
  |
  +--nachos.machine.OpenFile
        |
        +--nachos.machine.OpenFileWithPosition
Direct Known Subclasses:
ArrayFile

public abstract class OpenFileWithPosition
extends OpenFile

An OpenFile that maintains a current file position.


Field Summary
protected  int position
          The current value of the file pointer.
 
Constructor Summary
OpenFileWithPosition()
          Allocate a new OpenFileWithPosition.
 
Method Summary
 int read(byte[] buf, int offset, int length)
          Read this file starting at the current file pointer and return the number of bytes successfully read.
 void seek(int position)
          Set the value of the current file pointer.
 int tell()
          Get the value of the current file pointer, or -1 if this file has no pointer.
 int write(byte[] buf, int offset, int length)
          Write this file starting at the current file pointer and return the number of bytes successfully written.
 
Methods inherited from class nachos.machine.OpenFile
close, length, read, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

position

protected int position
The current value of the file pointer.
Constructor Detail

OpenFileWithPosition

public OpenFileWithPosition()
Allocate a new OpenFileWithPosition.
Method Detail

seek

public void seek(int position)
Description copied from class: OpenFile
Set the value of the current file pointer.
Overrides:
seek in class OpenFile

tell

public int tell()
Description copied from class: OpenFile
Get the value of the current file pointer, or -1 if this file has no pointer.
Overrides:
tell in class OpenFile

read

public int read(byte[] buf,
                int offset,
                int length)
Description copied from class: OpenFile
Read this file starting at the current file pointer and return the number of bytes successfully read. Advances the file pointer by this amount. If no bytes could be* read because of a fatal error, returns -1.
Overrides:
read in class OpenFile
Tags copied from class: OpenFile
Parameters:
buf - the buffer to store the bytes in.
offset - the offset in the buffer to start storing bytes.
length - the number of bytes to read.
Returns:
the actual number of bytes successfully read, or -1 on failure.

write

public int write(byte[] buf,
                 int offset,
                 int length)
Description copied from class: OpenFile
Write this file starting at the current file pointer and return the number of bytes successfully written. Advances the file pointer by this amount. If no bytes could be written because of a fatal error, returns -1.
Overrides:
write in class OpenFile
Tags copied from class: OpenFile
Parameters:
buf - the buffer to get the bytes from.
offset - the offset in the buffer to start getting.
length - the number of bytes to write.
Returns:
the actual number of bytes successfully written, or -1 on failure.