6
internal class RandomAccessFile
8
private FileStream stream;
10
public RandomAccessFile (FilePath file, string mode) : this(file.GetPath (), mode)
14
public RandomAccessFile (string file, string mode)
16
if (mode.IndexOf ('w') != -1)
17
stream = new FileStream (file, System.IO.FileMode.OpenOrCreate, FileAccess.ReadWrite);
19
stream = new FileStream (file, System.IO.FileMode.Open, FileAccess.Read);
27
public FileChannel GetChannel ()
29
return new FileChannel (this.stream);
32
public long GetFilePointer ()
34
return stream.Position;
42
public int Read (byte[] buffer)
44
int r = stream.Read (buffer, 0, buffer.Length);
45
return r > 0 ? r : -1;
48
public int Read (byte[] buffer, int start, int size)
50
return stream.Read (buffer, start, size);
53
public void ReadFully (byte[] buffer, int start, int size)
56
int num = stream.Read (buffer, start, size);
58
throw new EOFException ();
65
public void Seek (long pos)
67
stream.Position = pos;
70
public void SetLength (long len)
72
stream.SetLength (len);
75
public void Write (byte[] buffer)
77
stream.Write (buffer, 0, buffer.Length);
80
public void Write (byte[] buffer, int start, int size)
82
stream.Write (buffer, start, size);