[go: up one dir, main page]

Menu

[r9]: / cell / CellBuffer.java  Maximize  Restore  History

Download this file

45 lines (44 with data), 1.0 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package cell;
import java.io.*;
abstract class CellBuffer extends CellMap
{
private void fastRead(char[] buf) throws IOException
{
for (int i = 0; i<buf.length; i++)
buf[i] = f.readChar();
}
private void slowWrite(char[] buf) throws IOException
{
int off = 0;
if (f.getFilePointer() == 0)
{
off = 1;
f.writeByte(254);
f.writeByte(255);
}
for (int i = off; i<buf.length; i++)
f.writeChar(buf[i]);
}
void buffer(short row, char[] buf, String op)
{
if (RECORD != buf.length) throw new IllegalArgumentException("The character buffer must have a standard length, namely "+ RECORD);
try
{
goTo(row);
if (op.equalsIgnoreCase("r"))
fastRead(buf);
else if (op.equalsIgnoreCase("W"))
slowWrite(buf);
else throw new IllegalArgumentException("Must be either R or W.");
}
catch (IOException e)
{
e.printStackTrace();
System.exit(1);
}
}
CellBuffer(String fileName)
{
super(fileName);
}
}