Package com.google.protobuf

Examples of com.google.protobuf.ByteString$CodedBuilder


      throw new NullPointerException("buffer is null");
    }
    if (null == file) {
      throw new NullPointerException("file is null");
    }
    ByteString data = ByteString.copyFrom(buffer);
    append(file.getFullPath(), data, sequenceKey);
    return data.size();
  }
View Full Code Here


    }
    long remaining = buffer.remaining();
    if (buffer.remaining() < 1) {
      return 0;
    }
    ByteString byteString = read(file.getFullPath(), startingPos, remaining);
    byteString.copyTo(buffer);
    int numBytesRead = byteString.size();
    if (numBytesRead <= 0) {
      numBytesRead = -1;
    }
    return numBytesRead;
  }
View Full Code Here

  /**
   * Saves the original value of an entity (as returned by the datastore)
   * to the local cache.
   */
  public void addEntityToCache(OnestoreEntity.EntityProto entityPb) {
    ByteString key = entityPb.getKey().toByteString();
    if (getCache.containsKey(key)) {
      throw new IllegalStateException("shouldn't load the same entity twice within a transaction");
    }
    getCache.put(key, entityPb);
  }
View Full Code Here

  /**
   * Caches the absence of an entity (according to the datastore).
   */
  public void addEntityAbsenceToCache(OnestoreEntity.Reference key) {
    ByteString keyBytes = key.toByteString();
    if (getCache.containsKey(keyBytes)) {
      throw new IllegalStateException("shouldn't load the same entity twice within a transaction");
    }
    getCache.put(keyBytes, (OnestoreEntity.EntityProto) null);
  }
View Full Code Here

  /**
   * Returns a cached entity, or null if the entity's absence was cached.
   */
  @Nullable
  public OnestoreEntity.EntityProto getCachedEntity(OnestoreEntity.Reference key) {
    ByteString keyBytes = key.toByteString();
    if (!getCache.containsKey(keyBytes)) {
      throw new IllegalStateException("entity's status unexpectedly not in cache");
    }
    return getCache.get(keyBytes);
  }
View Full Code Here

      Provider<Map<K, V>> defaultValue) {
    MemcacheGetRequest.Builder requestBuilder = MemcacheGetRequest.newBuilder();
    requestBuilder.setNameSpace(getEffectiveNamespace());
    final Map<ByteString, K> byteStringToKey = new HashMap<ByteString, K>(keys.size(), 1);
    for (K key : keys) {
      ByteString pbKey = makePbKey(key);
      byteStringToKey.put(pbKey, key);
      requestBuilder.addKey(pbKey);
    }
    if (forCas) {
      requestBuilder.setForCas(forCas);
View Full Code Here

      super.handleApiProxyException(cause);
    }

    private void handleApiProxyException(String msg) throws MemcacheServiceException {
      for (MemcacheSetRequest.Item.Builder itemBuilder : itemsSentToBackend) {
        ByteString pbKey = itemBuilder.getKey();
        ByteString value = itemBuilder.getValue();
        if (value.size() + pbKey.size() > ITEM_SIZE_LIMIT) {
          maybeThrow("Key+value is bigger than maximum allowed. " + msg);
        }
        if (Bytes.contains(pbKey.toByteArray(), (byte) 0)) {
          maybeThrow("Key contains embedded null byte. " + msg);
        }
View Full Code Here

     */
    public static BinaryPacket trimForLogging(BinaryPacket binaryPacket) {
        int offset = 0;
        int size = Math.min(30, binaryPacket.getData().size());
        byte[] bytes = binaryPacket.getData().toByteArray();
        ByteString data = ByteString.copyFrom(bytes, offset, size);
        return BinaryPacket.newBuilder(binaryPacket).setData(data).build();
    }
View Full Code Here

* Calculates hashes of file contents and records metrics about the run time.
*/
public class FileHasher {
  public static ByteString getSha1(String contents) {
    Stopwatch stopWatch = new Stopwatch().start();
    ByteString sha1 = ByteString.copyFrom(Hashing.sha1().hashString(contents).asBytes());
    return sha1;
  }
View Full Code Here

    }

    @Override
    public ByteString compress(byte[] data, Dictionary dict) throws IOException {
      writeCompressed(data, dict);
      ByteString result = ByteString.copyFrom(this.buf, 0, this.count);
      reset(); // Only resets the count - we reuse the byte array.
      return result;
    }
View Full Code Here

TOP

Related Classes of com.google.protobuf.ByteString$CodedBuilder

Copyright © 2018 www.massapicom. 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.