<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>mr795 new document title</title>
</head>
<body>
<div>public class RAMDisk implements BlockDevice {</div>
<div></div>
<div>&nbsp; private static final int DEFAULTBLOCKSIZE = 256,</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; DEFAULTNUMBEROFBLOCKS = 200;</div>
<div></div>
<div>&nbsp; private int blockSize, numberOfBlocks;</div>
<div>&nbsp; private byte[] storage;</div>
<div></div>
<div>&nbsp; public RAMDisk () {</div>
<div>&nbsp; &nbsp; this (DEFAULTBLOCKSIZE, DEFAULTNUMBEROFBLOCKS);</div>
<div>&nbsp; }</div>
<div></div>
<div>&nbsp; public RAMDisk (int b, int n) {</div>
<div>&nbsp; &nbsp; blockSize = b;</div>
<div>&nbsp; &nbsp; numberOfBlocks = n;</div>
<div>&nbsp; &nbsp; storage = new byte[blockSize * numberOfBlocks];</div>
<div>&nbsp; }</div>
<div></div>
<div>&nbsp; public void readBlock (byte[] buffer, int block) {</div>
<div>&nbsp; &nbsp; int blockindex = block * blockSize;</div>
<div>&nbsp; &nbsp; for (int i = 0; i &lt; blockSize; i++)</div>
<div>&nbsp; &nbsp; &nbsp; buffer[i] = storage[blockindex + i];</div>
<div>&nbsp; }</div>
<div></div>
<div>&nbsp; public void writeBlock (byte[] buffer, int block) {</div>
<div>&nbsp; &nbsp; int blockindex = block * blockSize;</div>
<div>&nbsp; &nbsp; &nbsp; for (int i = 0; i &lt; blockSize; i++)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; storage[blockindex + i] = buffer[i];&nbsp;</div>
<div>&nbsp; }</div>
<div></div>
<div>&nbsp; public int getBlockSize () {</div>
<div>&nbsp; &nbsp; return blockSize;</div>
<div>&nbsp; }</div>
<div></div>
<div>&nbsp; public int getNumberOfBlocks () {</div>
<div>&nbsp; &nbsp; return numberOfBlocks;</div>
<div>&nbsp; }</div>
<div></div>
<div>}</div>
</body>
</html>