예제 #1
1
파일: HeapFile.java 프로젝트: ntgsx92/cs143
 // see DbFile.java for javadocs
 public Page readPage(PageId pid) {
   int offset = BufferPool.PAGE_SIZE * pid.pageNumber();
   byte[] b = new byte[BufferPool.PAGE_SIZE];
   try {
     InputStream is = new FileInputStream(m_file);
     is.skip(offset);
     is.read(b, 0, BufferPool.PAGE_SIZE);
     is.close();
     return new HeapPage((HeapPageId) pid, b);
   } catch (IOException ioe) {
     ioe.printStackTrace();
     return null;
   }
 }
예제 #2
0
  /**
   * Compares one PageId to another.
   *
   * @param o The object to compare against (must be a PageId)
   * @return true if the objects are equal (e.g., page numbers and table ids are the same)
   */
  public boolean equals(Object o) {
    if (!(o instanceof PageId)) return false;

    PageId other = (PageId) o;

    if (this.getTableId() != other.getTableId() || this.pageNumber() != other.pageNumber())
      return false;

    return true;
  }
예제 #3
0
  // see DbFile.java for javadocs
  public Page readPage(PageId pid) {
    // some code goes here
    if (pid.pageNumber() >= numPages()) {
      throw new IllegalArgumentException("page not in file");
    }
    Page returnme = null;

    byte[] data = HeapPage.createEmptyPageData();
    long offset = (long) BufferPool.PAGE_SIZE * pid.pageNumber();
    try {
      raf.seek(offset);
      for (int i = 0; i < data.length; i++) {
        data[i] = raf.readByte();
      }
      returnme = new HeapPage((HeapPageId) pid, data);
    } catch (EOFException eofe) {
      eofe.printStackTrace();
    } catch (IOException ioe) {
      ioe.printStackTrace();
    }
    return returnme;
  }
예제 #4
0
 // see DbFile.java for javadocs
 public Page readPage(PageId pid) {
   // some code goes here
   try {
     RandomAccessFile rAf = new RandomAccessFile(f, "r");
     int offset = pid.pageNumber() * BufferPool.PAGE_SIZE;
     byte[] b = new byte[BufferPool.PAGE_SIZE];
     rAf.seek(offset);
     rAf.read(b, 0, BufferPool.PAGE_SIZE);
     HeapPageId hpid = (HeapPageId) pid;
     rAf.close();
     return new HeapPage(hpid, b);
   } catch (IOException e) {
     e.printStackTrace();
   }
   return null;
 }