AddressSpace library v1.0 beta

Class Page

java.lang.Object
  |
  +--Page
Direct Known Subclasses:
SwappingPage

public class Page
extends java.lang.Object

Is the representation of a page for the virtual memory module.

Version:
1.0 June 05 2000
Author:
Dario Maggiorini (dario@dsi.unimi.it)

Field Summary
protected  byte[] data
          Data contained in the page.
protected static byte[] filler
          An helper array used to obtain a zero-fill effect.
protected static int interStep
          The step used to optimize the chicking if the page has content or not.
static int pageSize
          Size of a page.
 
Constructor Summary
Page()
          Create a new empty page.
 
Method Summary
 void dump()
          Dump the page in a string readable format.
 byte[] getData()
          Get the data contained in the page.
 boolean isAllZero()
          Thest if the page has contents beside zero.
 byte read(int offset)
          Read a byte from the page.
 int read(int offset, byte[] buffer)
          Read an array of bytes from the page.
 int read(int offset, byte[] buffer, int len)
          Read an array of bytes from the page.
 int read(int offset, byte[] buffer, int len, int boffset)
          Read an array of bytes from the page.
 int readInt(int offset)
          Read an integer from the page.
 long readLong(int offset)
          Read a long integer from the page.
 short readShort(int offset)
          Read a short int from the page.
 java.lang.String toString()
           
 java.lang.String toString(int id)
          Convert the page in a string.
 int write(int offset, byte v)
          Write a byte in the page.
 int write(int offset, byte[] buffer)
          Write an array of bytes to the page.
 int write(int offset, byte[] buffer, int len)
          Write an array of bytes to the page.
 int write(int offset, byte[] buffer, int len, int boffset)
          Write an array of bytes to the page.
 int writeInt(int offset, int value)
          Write an integer to the page.
 int writeLong(int offset, long value)
          Write a long integer to the page.
 int writeShort(int offset, short value)
          Write a short int to the page.
 void zeroFill()
          Blank a page.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

pageSize

public static final int pageSize
Size of a page.

filler

protected static byte[] filler
An helper array used to obtain a zero-fill effect.

data

protected byte[] data
Data contained in the page.

interStep

protected static final int interStep
The step used to optimize the chicking if the page has content or not.
Constructor Detail

Page

public Page()
Create a new empty page.
The new page should be zero-filled due to posix specifications.
Method Detail

zeroFill

public void zeroFill()
Blank a page.
The content of the page will be all zero bytes.

isAllZero

public boolean isAllZero()
Thest if the page has contents beside zero.
Returns:
true if the page has no content, false otherwise.

read

public byte read(int offset)
Read a byte from the page.
Parameters:
offset - the location of the byte to read.
Returns:
the byte to be read.

read

public int read(int offset,
                byte[] buffer)
Read an array of bytes from the page.
The array is filled until the end of the page is reached.
Parameters:
offset - the location of the bytes to read.
buffer - the buffer to be filled.
Returns:
the number of bytes readed.

read

public int read(int offset,
                byte[] buffer,
                int len)
Read an array of bytes from the page.
The array is filled until a specified amount of bytes are readed or the end of the page is reached.
Parameters:
offset - the location of the bytes to read.
buffer - the buffer to be filled.
len - the number of bytes to read.
Returns:
the number of bytes readed.

read

public int read(int offset,
                byte[] buffer,
                int len,
                int boffset)
Read an array of bytes from the page.
The array is filled starting from a given offset until a specified amount of bytes are readed or the end of the page is reached.
Parameters:
offset - the location of the bytes to read.
buffer - the buffer to be filled.
len - the number of bytes to read.
boffset - the offset inside the buffer.
Returns:
the number of bytes readed.

write

public int write(int offset,
                 byte v)
Write a byte in the page.
Parameters:
offset - the location of the byte to write.
v - the value to write.
Returns:
the number of bytes written (1).

write

public int write(int offset,
                 byte[] buffer)
Write an array of bytes to the page.
The array is written until the end of the page is reached.
Parameters:
offset - the location of the bytes to write.
buffer - the buffer to be written.
Returns:
the number of bytes written

write

public int write(int offset,
                 byte[] buffer,
                 int len)
Write an array of bytes to the page.
The array is written until a specified amount of bytes are transferred or the end of the page is reached.
Parameters:
offset - the location of the bytes to write.
buffer - the buffer to be written.
len - the number of bytes to write.
Returns:
the number of bytes written.

write

public int write(int offset,
                 byte[] buffer,
                 int len,
                 int boffset)
Write an array of bytes to the page.
The array is written starting from a given offset until a specified amount of bytes are transferred or the end of the page is reached.
Parameters:
offset - the location of the bytes to write.
buffer - the buffer to be written.
len - the number of bytes to write.
boffset - the offset inside the buffer.
Returns:
the number of bytes written.

getData

public byte[] getData()
Get the data contained in the page.
The data is returned as a byte array with the same dimensions of the page.
Returns:
the page content.

readShort

public short readShort(int offset)
                throws NotAlignedPointer
Read a short int from the page.
Parameters:
offset - the location of the page where the data is located.
Returns:
the data readed.
Throws:
NotAlignedPointer - exception if the location is aligned with data size.

writeShort

public int writeShort(int offset,
                      short value)
               throws NotAlignedPointer
Write a short int to the page.
Parameters:
offset - the location of the page where the data is located.
Returns:
the number of bytes written to the page.
Throws:
NotAlignedPointer - exception if the location is aligned with data size.

readInt

public int readInt(int offset)
            throws NotAlignedPointer
Read an integer from the page.
Parameters:
offset - the location of the page where the data is located.
Returns:
the data readed.
Throws:
NotAlignedPointer - exception if the location is aligned with data size.

writeInt

public int writeInt(int offset,
                    int value)
             throws NotAlignedPointer
Write an integer to the page.
Parameters:
offset - the location of the page where the data is located.
Returns:
the number of bytes written to the page.
Throws:
NotAlignedPointer - exception if the location is aligned with data size.

readLong

public long readLong(int offset)
              throws NotAlignedPointer
Read a long integer from the page.
Parameters:
offset - the location of the page where the data is located.
Returns:
the data readed.
Throws:
NotAlignedPointer - exception if the location is aligned with data size.

writeLong

public int writeLong(int offset,
                     long value)
              throws NotAlignedPointer
Write a long integer to the page.
Parameters:
offset - the location of the page where the data is located.
Returns:
the number of bytes written to the page.
Throws:
NotAlignedPointer - exception if the location is aligned with data size.

dump

public void dump()
Dump the page in a string readable format.
The dumped output is the result of the toString function.
This function is intended for debugging porpuse.

toString

public java.lang.String toString(int id)
Convert the page in a string.
The resulting string will be an hexadecimal dump of the content of the page.
For each line the starting address will be present and then the content in 16 bytes chunkes will be presented.
Returns:
String a string representing the queue

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

Help is irrilevant
You will be assimilated!

v1.0 beta by Dario Maggiorini