Package java.nio

Examples of java.nio.ByteBuffer.slice()


            if (encoding != DataBlockEncoding.NONE) {
              // We expect a two-byte big-endian encoding id.
              assertEquals(0, actualBuffer.get(0));
              assertEquals(encoding.getId(), actualBuffer.get(1));
              actualBuffer.position(2);
              actualBuffer = actualBuffer.slice();
            }

            ByteBuffer expectedBuffer = encodedBlocks.get(blockId);
            expectedBuffer.rewind();
View Full Code Here


            if (encoding != DataBlockEncoding.NONE) {
              // We expect a two-byte big-endian encoding id.
              assertEquals(0, actualBuffer.get(0));
              assertEquals(encoding.getId(), actualBuffer.get(1));
              actualBuffer.position(2);
              actualBuffer = actualBuffer.slice();
            }

            ByteBuffer expectedBuffer = encodedBlocks.get(blockId);
            expectedBuffer.rewind();
View Full Code Here

    ByteBuffer lowestKey = lowest.getKey();
    addReaderToQueueIfNotEmpty(reader);
    lastKey = SerializableValue.of(getByteBufferMarshaller(), lowestKey);
    if (combineValues) {
      CombiningReader values = new CombiningReader(lowestKey, lowest.getValue());
      return new KeyValue<K, Iterator<V>>(keyMarshaller.fromBytes(lowestKey.slice()), values);
    } else {
      return new KeyValue<>(keyMarshaller.fromBytes(lowestKey.slice()),
          lowest.getValue().iterator());
    }
  }
View Full Code Here

    lastKey = SerializableValue.of(getByteBufferMarshaller(), lowestKey);
    if (combineValues) {
      CombiningReader values = new CombiningReader(lowestKey, lowest.getValue());
      return new KeyValue<K, Iterator<V>>(keyMarshaller.fromBytes(lowestKey.slice()), values);
    } else {
      return new KeyValue<>(keyMarshaller.fromBytes(lowestKey.slice()),
          lowest.getValue().iterator());
    }
  }

  private void addReaderToQueueIfNotEmpty(
View Full Code Here

  }

  private void writeObject(ObjectOutputStream aOutputStream) throws IOException {
    aOutputStream.defaultWriteObject();
    ByteBuffer byteBuffer = marshaller.toBytes(value);
    aOutputStream.writeObject(SerializationUtil.getBytes(byteBuffer.slice()));
    // In case marshalling modified the item
    value = marshaller.fromBytes(byteBuffer);
  }
}
View Full Code Here

          throw new RuntimeException("you need to seekTo() before calling getValue()");
        }
        // TODO: Could this be done with one ByteBuffer rather than create two?
        ByteBuffer valueBuff = this.block.slice();
        valueBuff.position(this.currKeyLen);
        valueBuff = valueBuff.slice();
        valueBuff.limit(currValueLen);
        valueBuff.rewind();
        return valueBuff;
      }
View Full Code Here

    // note: actually searching an array of blooms that have been serialized
    for (int m = 0; m < readMatrixSize; ++m) {
      tmp.position(m* bytesPerBloom);
      tmp.limit(tmp.position() + bytesPerBloom);
      boolean match = this.matrix[0].contains(buf, offset, length, tmp.slice());
      if (match) {
        return true;
      }
    }

View Full Code Here

        if (! Arrays.equals(magic, METABLOCKMAGIC)) {
          throw new IOException("Meta magic is bad in block " + block);
        }

        // Create a new ByteBuffer 'shallow copy' to hide the magic header
        buf = buf.slice();

        readTime += System.currentTimeMillis() - now;
        readOps++;

        // Cache the block
View Full Code Here

        }

        // 'shallow copy' to hide the header
        // NOTE: you WILL GET BIT if you call buf.array() but don't start
        //       reading at buf.arrayOffset()
        buf = buf.slice();

        readTime += System.currentTimeMillis() - now;
        readOps++;

        // Cache the block
View Full Code Here

  public int charAt(int position) {
    if (position > this.length) return -1; // too long
    if (position < 0) return -1; // duh.
     
    ByteBuffer bb = (ByteBuffer)ByteBuffer.wrap(bytes).position(position);
    return bytesToCodePoint(bb.slice());
  }
 
  public int find(String what) {
    return find(what, 0);
  }
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.