Examples of rewind()


Examples of java.nio.ByteBuffer.rewind()

    }
    else {
      // Read bucket count, bucket size and item count from the file
      ByteBuffer buf = ByteBuffer.allocate((int)HEADER_LENGTH);
      fileChannel.read(buf, 0L);
      buf.rewind();

      if (buf.remaining() < HEADER_LENGTH) {
        throw new IOException("File too short to be a compatible hash file");
      }
View Full Code Here

Examples of java.nio.ByteBuffer.rewind()

      if (slotID >= 0) {
        // Empty slot found, store dataOffset in it
        bucket.putInt(ITEM_SIZE * slotID, hash);
        bucket.putInt(ITEM_SIZE * slotID + 4, id);
        bucket.rewind();
        fileChannel.write(bucket, bucketOffset);
        idStored = true;
      }
      else {
        // No empty slot found, check if bucket has an overflow bucket
View Full Code Here

Examples of java.nio.ByteBuffer.rewind()

    buf.putInt(FILE_FORMAT_VERSION);
    buf.putInt(blockSize);
    buf.putInt(valueSize);
    buf.putInt(rootNodeID);

    buf.rewind();

    fileChannel.write(buf, 0L);
  }

  private long nodeID2offset(int id) {
View Full Code Here

Examples of java.nio.ByteBuffer.rewind()

          // No overflow bucket yet, create one
          overflowID = createOverflowBucket();

          // Link overflow bucket to current bucket
          bucket.putInt(ITEM_SIZE * bucketSize, overflowID);
          bucket.rewind();
          fileChannel.write(bucket, bucketOffset);
        }

        // Continue searching for an empty slot in the overflow bucket
        bucketOffset = getOverflowBucketOffset(overflowID);
View Full Code Here

Examples of java.nio.ByteBuffer.rewind()

    int valueCount = 0;

    ByteBuffer buf = ByteBuffer.allocate(nodeSize);
    for (long offset = blockSize; offset < fileChannel.size(); offset += blockSize) {
      fileChannel.read(buf, offset);
      buf.rewind();

      int nodeID = offset2nodeID(offset);
      int count = buf.getInt();
      nodeCount++;
      valueCount += count;
View Full Code Here

Examples of java.nio.ByteBuffer.rewind()

    buf.put(MAGIC_NUMBER);
    buf.put(FILE_FORMAT_VERSION);
    buf.putInt(bucketCount);
    buf.putInt(bucketSize);
    buf.putInt(itemCount);
    buf.rewind();

    fileChannel.write(buf, 0L);
  }

  /**
 
View Full Code Here

Examples of java.nio.ByteBuffer.rewind()

  {
    ByteBuffer emptyBucket = ByteBuffer.allocate(recordSize);

    for (int i = 0; i < bucketCount; i++) {
      fileChannel.write(emptyBucket, fileOffset + i * (long)recordSize);
      emptyBucket.rewind();
    }
  }

  private int findEmptySlotInBucket(ByteBuffer bucket) {
    for (int slotNo = 0; slotNo < bucketSize; slotNo++) {
View Full Code Here

Examples of java.nio.ByteBuffer.rewind()

      // Empty file, write header
      ByteBuffer buf = ByteBuffer.allocate((int)HEADER_LENGTH);
      buf.put(MAGIC_NUMBER);
      buf.put(FILE_FORMAT_VERSION);
      buf.put(new byte[] { 0, 0, 0, 0 });
      buf.rewind();

      fileChannel.write(buf, 0L);

      sync();
    }
View Full Code Here

Examples of java.nio.ByteBuffer.rewind()

    }
    else {
      // Verify file header
      ByteBuffer buf = ByteBuffer.allocate((int)HEADER_LENGTH);
      fileChannel.read(buf, 0L);
      buf.rewind();

      if (buf.remaining() < HEADER_LENGTH) {
        throw new IOException("File too short to be a compatible ID file");
      }
View Full Code Here

Examples of java.nio.ByteBuffer.rewind()

    if (fileChannel.size() == 0L) {
      // Empty file, write header
      ByteBuffer buf = ByteBuffer.allocate((int)HEADER_LENGTH);
      buf.put(MAGIC_NUMBER);
      buf.put(FILE_FORMAT_VERSION);
      buf.rewind();

      fileChannel.write(buf, 0L);

      sync();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.