Beispiel #1
0
 public static Node loadNode(Storage storage, long offset) {
   storage.seek(offset);
   Node node = new Node(storage);
   byte[] b = new byte[Node.NODE_BYTES_LEN];
   int len = storage.read(b);
   if (len < Node.NODE_BYTES_LEN) {
     storage.seek(storage.getPointer() - len); // if load node fail,reset the offset
     throw new RuntimeException(
         "storage load data starts at : " + offset + ",but couldn't read success");
   }
   node.fill(b);
   return node;
 }
Beispiel #2
0
 public static Node allocateNewNode(Storage storage) {
   Node node = new Node(storage);
   node.clear();
   node.setStoragePointer(storage.length());
   storage.seek(storage.length());
   storage.write(node.toBytes());
   return node;
 }
Beispiel #3
0
  public static void flushToStorage(Node item, Storage storage) {
    if (item == null) return;
    storage.seek(item.getStoragePointer());

    storage.write(item.toBytes());
  }