nachos.machine
Class ArrayFile

java.lang.Object
  extended by nachos.machine.OpenFile
      extended by nachos.machine.OpenFileWithPosition
          extended by nachos.machine.ArrayFile

public class ArrayFile
extends OpenFileWithPosition

A read-only OpenFile backed by a byte array.


Field Summary
 
Fields inherited from class nachos.machine.OpenFileWithPosition
position
 
Constructor Summary
ArrayFile(byte[] array)
          Allocate a new ArrayFile.
 
Method Summary
 void close()
          Close this file and release any associated system resources.
 int length()
          Get the length of this file.
 int read(int position, byte[] buf, int offset, int length)
          Read this file starting at the specified position and return the number of bytes successfully read.
 int write(int position, byte[] buf, int offset, int length)
          Write this file starting at the specified position and return the number of bytes successfully written.
 
Methods inherited from class nachos.machine.OpenFileWithPosition
read, seek, tell, write
 
Methods inherited from class nachos.machine.OpenFile
getFileSystem, getName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayFile

public ArrayFile(byte[] array)
Allocate a new ArrayFile.

Parameters:
array - the array backing this file.
Method Detail

length

public int length()
Description copied from class: OpenFile
Get the length of this file.

Overrides:
length in class OpenFile
Returns:
the length of this file, or -1 if this file has no length.

close

public void close()
Description copied from class: OpenFile
Close this file and release any associated system resources.

Overrides:
close in class OpenFile

read

public int read(int position,
                byte[] buf,
                int offset,
                int length)
Description copied from class: OpenFile
Read this file starting at the specified position and return the number of bytes successfully read. If no bytes were read because of a fatal error, returns -1

Overrides:
read in class OpenFile
Parameters:
position - the offset in the file at which to start reading.
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(int position,
                 byte[] buf,
                 int offset,
                 int length)
Description copied from class: OpenFile
Write this file starting at the specified position and return the number of bytes successfully written. If no bytes were written because of a fatal error, returns -1.

Overrides:
write in class OpenFile
Parameters:
position - the offset in the file at which to start writing.
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.