Пример #1
0
  private long readHeader(int id) throws IOException {
    long header = p_alloc(MINIMUM_PAGE_SIZE);

    try {
      try {
        mPageArray.readPage(id, header, 0, MINIMUM_PAGE_SIZE);
      } catch (EOFException e) {
        throw new CorruptDatabaseException("File is smaller than expected");
      }

      long magic = p_longGetLE(header, I_MAGIC_NUMBER);
      if (magic != MAGIC_NUMBER) {
        throw new CorruptDatabaseException("Wrong magic number: " + magic);
      }

      int checksum = p_intGetLE(header, I_CHECKSUM);

      int newChecksum = setHeaderChecksum(header);
      if (newChecksum != checksum) {
        throw new CorruptDatabaseException(
            "Header checksum mismatch: " + newChecksum + " != " + checksum);
      }

      return header;
    } catch (Throwable e) {
      p_delete(header);
      throw e;
    }
  }
Пример #2
0
 @Override
 public void readPage(long id, long page) throws IOException {
   try {
     mPageArray.readPage(id, page, 0, pageSize());
   } catch (Throwable e) {
     throw closeOnFailure(e);
   }
 }
Пример #3
0
 private void readPartial(long index, int start, byte[] buf, int offset, int length)
     throws IOException {
   long page = p_alloc(start + length);
   try {
     mPageArray.readPage(index, page, 0, start + length);
     p_copyToArray(page, start, buf, offset, length);
   } finally {
     p_delete(page);
   }
 }
Пример #4
0
 /** @see _SnapshotPageArray#beginSnapshot */
 Snapshot beginSnapshot(_LocalDatabase db) throws IOException {
   mHeaderLatch.acquireShared();
   try {
     long pageCount, redoPos;
     long header = p_alloc(MINIMUM_PAGE_SIZE);
     try {
       mPageArray.readPage(mCommitNumber & 1, header, 0, MINIMUM_PAGE_SIZE);
       pageCount = _PageManager.readTotalPageCount(header, I_MANAGER_HEADER);
       redoPos = _LocalDatabase.readRedoPosition(header, I_EXTRA_DATA);
     } finally {
       p_delete(header);
     }
     return mPageArray.beginSnapshot(db, pageCount, redoPos);
   } finally {
     mHeaderLatch.releaseShared();
   }
 }