Example #1
0
 /**
  * Return a byte buffer that represents this Value with the following order:
  *
  * <ol>
  *   <li><strong>type</strong> - position 0
  *   <li><strong>data</strong> - position 1
  * </ol>
  *
  * @return the ByteBuffer representation
  */
 @Override
 public ByteBuffer getBytes() {
   if (bytes == null) {
     bytes = ByteBuffer.allocate(size());
     copyTo(bytes);
     bytes.rewind();
   }
   return ByteBuffers.asReadOnlyBuffer(bytes);
 }
Example #2
0
 /**
  * Deserialize the content of this Transaction from {@code bytes}.
  *
  * @param bytes
  */
 private void deserialize(ByteBuffer bytes) {
   locks = Maps.newHashMap();
   Iterator<ByteBuffer> it =
       ByteableCollections.iterator(ByteBuffers.slice(bytes, bytes.getInt()));
   while (it.hasNext()) {
     LockDescription lock =
         LockDescription.fromByteBuffer(it.next(), lockService, rangeLockService);
     locks.put(lock.getToken(), lock);
   }
   it = ByteableCollections.iterator(bytes);
   while (it.hasNext()) {
     Write write = Write.fromByteBuffer(it.next());
     buffer.insert(write);
   }
 }
 @Override
 public String toString() {
   return Hashing.sha1().hashBytes(ByteBuffers.toByteArray(getBytes())).toString();
 }
 @Override
 public ByteBuffer getBytes() {
   return ByteBuffers.asReadOnlyBuffer(bytes);
 }