Package java.nio

Examples of java.nio.ByteBuffer.rewind()


                ZipEncodingHelper.appendSurrogate(out,c);
            }
        }

        out.limit(out.position());
        out.rewind();
        return out;
    }

    /**
     * @see
 
View Full Code Here


        // this may write excess the size, the setLength() would fix it
        while (oldMetaLen < newMetaLen) {
          // never write random byte to meta data!
          // this would screw up the isFree() function
          bf.rewind();
          metaFC.write(bf, oldMetaLen);
          oldMetaLen += 4096;
        }
        byte[] seed = new byte[64];
        random.nextBytes(seed);
View Full Code Here

        random.nextBytes(seed);
        Random mt = new MersenneTwister(seed);
        int x = 0;
        while (currentHdLen < newHdLen) {
          mt.nextBytes(b);
          bf.rewind();
          hdFC.write(bf, currentHdLen);
          currentHdLen += 4096;
          if(currentHdLen % (1024*1024*1024L) == 0) {
            random.nextBytes(seed);
            mt = new MersenneTwister(seed);
View Full Code Here

        final StringBuilder sb = new StringBuilder((int) fc.size());
        // TODO: Make sure that the entire world settles on one encoding and
        // that every file in existance is re-encoded.
        final Charset cs = Charset.forName("UTF-8");
        while (fc.read(buf) != -1) {
            buf.rewind();
            final CharBuffer chbuf = cs.decode(buf);
            sb.append(chbuf.array());
            buf.clear();
        }
View Full Code Here

    // TODO: two writes could be more efficient since it prevent array copies
    ByteBuffer buf = ByteBuffer.allocate(data.length + 4);
    buf.putInt(data.length);
    buf.put(data);
    buf.rewind();

    nioFile.write(buf, offset);

    return offset;
  }
View Full Code Here

    else {
      // Read parameters from file
      ByteBuffer buf = ByteBuffer.allocate(HEADER_LENGTH);
      nioFile.read(buf, 0L);

      buf.rewind();

      byte[] magicNumber = new byte[MAGIC_NUMBER.length];
      buf.get(magicNumber);
      byte version = buf.get();
      this.blockSize = buf.getInt();
View Full Code Here

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

    buf.rewind();

    nioFile.write(buf, 0L);
  }

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

    int valueCount = 0;

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

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

    }
    else {
      // Read bucket count, bucket size and item count from the file
      ByteBuffer buf = ByteBuffer.allocate((int)HEADER_LENGTH);
      nioFile.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

      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();
        nioFile.write(bucket, bucketOffset);
        idStored = true;
      }
      else {
        // No empty slot found, check if bucket has an overflow bucket
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.