void readHeader() throws Exception {
   byte[] header = new byte[this.headersize];
   // this.fromfile.Seek(this.seekStart, System.IO.SeekOrigin.Begin);
   this.fromfile.seek(this.seekStart);
   // this.fromfile.Read(header, 0, this.headersize);
   this.fromfile.read(header, 0, this.headersize);
   int index = 0;
   // check prefix
   // foreach (byte b in HEADERPREFIX)
   for (int i = 0; i < HEADERPREFIX.length; i++) {
     byte b = HEADERPREFIX[i];
     if (header[index] != b) {
       throw new LinkedFileException("invalid header prefix");
     }
     index++;
   }
   // skip version (for now)
   index++;
   // read buffersize
   this.buffersize = BufferFile.Retrieve(header, index);
   index += BufferFile.INTSTORAGE;
   this.FreeListHead = BufferFile.RetrieveLong(header, index);
   this.sanityCheck();
   this.headerDirty = false;
 }
 public byte[] GetChunk(long HeadBufferNumber) throws Exception {
   // get the head, interpret the length
   // byte buffertype;
   // long NextBufferNumber;
   // byte[] buffer = this.ParseBuffer(HeadBufferNumber, out buffertype, out NextBufferNumber);
   ParseBuffer P = new ParseBuffer(HeadBufferNumber);
   byte buffertype = P.type;
   long NextBufferNumber = P.NextBufferNumber;
   byte[] buffer = P.payload;
   int length = BufferFile.Retrieve(buffer, 0);
   if (length < 0) {
     throw new LinkedFileException("negative length block? must be garbage: " + length);
   }
   if (buffertype != HEAD) {
     throw new LinkedFileException("first buffer not marked HEAD");
   }
   byte[] result = new byte[length];
   // read in the data from the first buffer
   int firstLength = this.buffersize - BufferFile.INTSTORAGE;
   if (firstLength > length) {
     firstLength = length;
   }
   // Array.Copy(buffer, BufferFile.INTSTORAGE, result, 0, firstLength);
   for (int i = 0; i < firstLength; i++) {
     result[i] = buffer[BufferFile.INTSTORAGE + i];
   }
   int stored = firstLength;
   while (stored < length) {
     // get the next buffer
     long thisBufferNumber = NextBufferNumber;
     // buffer = this.ParseBuffer(thisBufferNumber, out buffertype, out NextBufferNumber);
     P = new ParseBuffer(thisBufferNumber);
     buffer = P.payload;
     buffertype = P.type;
     NextBufferNumber = P.NextBufferNumber;
     int nextLength = this.buffersize;
     if (length - stored < nextLength) {
       nextLength = length - stored;
     }
     // Array.Copy(buffer, 0, result, stored, nextLength);
     for (int i = 0; i < nextLength; i++) {
       result[stored + i] = buffer[i];
     }
     stored += nextLength;
   }
   return result;
 }