当前位置: 首页>>代码示例>>Java>>正文


Java ByteString.size方法代码示例

本文整理汇总了Java中com.google.protobuf.ByteString.size方法的典型用法代码示例。如果您正苦于以下问题:Java ByteString.size方法的具体用法?Java ByteString.size怎么用?Java ByteString.size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.protobuf.ByteString的用法示例。


在下文中一共展示了ByteString.size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getBlocksBuffers

import com.google.protobuf.ByteString; //导入方法依赖的package包/类
/**
 * List of ByteStrings that encode this block report
 *
 * @return ByteStrings
 */
public List<ByteString> getBlocksBuffers() {
  final ByteString blocksBuf = getBlocksBuffer();
  final List<ByteString> buffers;
  final int size = blocksBuf.size();
  if (size <= CHUNK_SIZE) {
    buffers = Collections.singletonList(blocksBuf);
  } else {
    buffers = new ArrayList<ByteString>();
    for (int pos=0; pos < size; pos += CHUNK_SIZE) {
      // this doesn't actually copy the data
      buffers.add(blocksBuf.substring(pos, Math.min(pos+CHUNK_SIZE, size)));
    }
  }
  return buffers;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:21,代码来源:BlockListAsLongs.java

示例2: hexDump

import com.google.protobuf.ByteString; //导入方法依赖的package包/类
/**
 * Dump a ByteString to a text representation
 * Copied from: http://people.csail.mit.edu/evanj/hg/index.cgi/javatxn/file/tip/src/edu/mit/ExampleServer.java
 * @param bytes
 * @return
 */
public static StringBuilder hexDump(ByteString bytes) {
    StringBuilder out = new StringBuilder();
    for (int i = 0; i < bytes.size(); ++i) {
        if (i != 0 && i % 2 == 0) {
            out.append(' ');
        }
        byte b = bytes.byteAt(i);
        out.append(nibbleToHexChar((b >> 4) & 0xf));
        out.append(nibbleToHexChar(b & 0xf));
    }
    return out;
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:19,代码来源:StringUtil.java

示例3: escapeBytes

import com.google.protobuf.ByteString; //导入方法依赖的package包/类
/**
 * Escapes bytes in the format used in protocol buffer text format, which
 * is the same as the format used for C string literals.  All bytes
 * that are not printable 7-bit ASCII characters are escaped, as well as
 * backslash, single-quote, and double-quote characters.  Characters for
 * which no defined short-hand escape sequence is defined will be escaped
 * using 3-digit octal sequences.
 */
static String escapeBytes(final ByteString input) {
  final StringBuilder builder = new StringBuilder(input.size());
  for (int i = 0; i < input.size(); i++) {
    final byte b = input.byteAt(i);
    switch (b) {
      // Java does not recognize \a or \v, apparently.
      case 0x07: builder.append("\\a" ); break;
      case '\b': builder.append("\\b" ); break;
      case '\f': builder.append("\\f" ); break;
      case '\n': builder.append("\\n" ); break;
      case '\r': builder.append("\\r" ); break;
      case '\t': builder.append("\\t" ); break;
      case 0x0b: builder.append("\\v" ); break;
      case '\\': builder.append("\\\\"); break;
      case '\'': builder.append("\\\'"); break;
      case '"' : builder.append("\\\""); break;
      default:
        if (b >= 0x20) {
          builder.append((char) b);
        } else {
          builder.append('\\');
          builder.append((char) ('0' + ((b >>> 6) & 3)));
          builder.append((char) ('0' + ((b >>> 3) & 7)));
          builder.append((char) ('0' + (b & 7)));
        }
        break;
    }
  }
  return builder.toString();
}
 
开发者ID:jigsaw-projects,项目名称:jigsaw-payment,代码行数:39,代码来源:JavaPropsFormat.java

示例4: hasPrefix

import com.google.protobuf.ByteString; //导入方法依赖的package包/类
public static boolean hasPrefix(ByteString str, ByteString prefix) {
  for (int i = 0; i < prefix.size(); i++) {
    if (str.byteAt(i) != prefix.byteAt(i)) {
      return false;
    }
  }
  return true;
}
 
开发者ID:pingcap,项目名称:tikv-client-lib-java,代码行数:9,代码来源:KeyUtils.java

示例5: compareTo

import com.google.protobuf.ByteString; //导入方法依赖的package包/类
@Override
public int compareTo(@Nonnull ComparableByteString other) {
  requireNonNull(other, "other is null");
  ByteString otherBytes = other.bytes;
  int n = Math.min(bytes.size(), otherBytes.size());
  for (int i = 0, j = 0; i < n; i++, j++) {
    int cmp = UnsignedBytes.compare(bytes.byteAt(i), otherBytes.byteAt(j));
    if (cmp != 0) return cmp;
  }
  // one is the prefix of other then the longer is larger
  return bytes.size() - otherBytes.size();
}
 
开发者ID:pingcap,项目名称:tikv-client-lib-java,代码行数:13,代码来源:Comparables.java

示例6: formatByteString

import com.google.protobuf.ByteString; //导入方法依赖的package包/类
static String formatByteString(ByteString key) {
  StringBuilder sb = new StringBuilder();
  for (int i = 0; i < key.size(); i++) {
    sb.append(key.byteAt(i) & 0xff);
    if (i < key.size() - 1) {
      sb.append(",");
    }
  }
  return sb.toString();
}
 
开发者ID:pingcap,项目名称:tikv-client-lib-java,代码行数:11,代码来源:KeyRangeUtils.java

示例7: PduAttachData

import com.google.protobuf.ByteString; //导入方法依赖的package包/类
public PduAttachData(int attachType, Long handle, Integer serviceType, ByteString pdu) {
    
    this.type = attachType;
    this.handle = handle;
    this.serviceType = serviceType;
    this.pdu = pdu;
    this.pduLength = pdu.size();
    
    buffer.writeInt(attachType);
    buffer.writeLong(handle);
    buffer.writeInt(serviceType);
    buffer.writeInt(pdu.size());
    buffer.writeBytes(pdu.toByteArray());
}
 
开发者ID:ccfish86,项目名称:sctalk,代码行数:15,代码来源:PduAttachData.java

示例8: readBlob

import com.google.protobuf.ByteString; //导入方法依赖的package包/类
private void readBlob(
    ReadRequest request,
    StreamObserver<ReadResponse> responseObserver) {
  String resourceName = request.getResourceName();

  Instance instance;
  try {
    instance = instances.getFromBlob(resourceName);
  } catch (InstanceNotFoundException ex) {
    responseObserver.onError(BuildFarmInstances.toStatusException(ex));
    return;
  }

  Digest digest = UrlPath.parseBlobDigest(resourceName);

  ByteString blob = instance.getBlob(
      digest, request.getReadOffset(), request.getReadLimit());
  if (blob == null) {
    responseObserver.onError(new StatusException(Status.NOT_FOUND));
    return;
  }

  while (!blob.isEmpty()) {
    ByteString chunk;
    if (blob.size() < DEFAULT_CHUNK_SIZE) {
      chunk = blob;
      blob = ByteString.EMPTY;
    } else {
      chunk = blob.substring(0, (int) DEFAULT_CHUNK_SIZE);
      blob = blob.substring((int) DEFAULT_CHUNK_SIZE);
    }
    responseObserver.onNext(ReadResponse.newBuilder()
        .setData(chunk)
        .build());
  }

  responseObserver.onCompleted();
}
 
开发者ID:bazelbuild,项目名称:bazel-buildfarm,代码行数:39,代码来源:ByteStreamService.java

示例9: readSingleChunk

import com.google.protobuf.ByteString; //导入方法依赖的package包/类
@Test
public void readSingleChunk() throws IOException {
  ByteString hello = ByteString.copyFromUtf8("Hello, World");
  InputStream in = new ByteStringIteratorInputStream(
      Iterators.<ByteString>singletonIterator(hello));
  byte[] data = new byte[hello.size()];

  assertThat(in.read(data)).isEqualTo(hello.size());
  assertThat(ByteString.copyFrom(data)).isEqualTo(hello);
  assertThat(in.read()).isEqualTo(-1);
}
 
开发者ID:bazelbuild,项目名称:bazel-buildfarm,代码行数:12,代码来源:ByteStringIteratorInputStreamTest.java

示例10: readSpanningChunks

import com.google.protobuf.ByteString; //导入方法依赖的package包/类
@Test
public void readSpanningChunks() throws IOException {
  ByteString hello = ByteString.copyFromUtf8("Hello, ");
  ByteString world = ByteString.copyFromUtf8("World");
  InputStream in = new ByteStringIteratorInputStream(
      ImmutableList.<ByteString>of(hello, world).iterator());
  ByteString helloWorld = hello.concat(world);
  byte[] data = new byte[helloWorld.size()];

  assertThat(in.read(data)).isEqualTo(helloWorld.size());
  assertThat(ByteString.copyFrom(data)).isEqualTo(helloWorld);
  assertThat(in.read()).isEqualTo(-1);
}
 
开发者ID:bazelbuild,项目名称:bazel-buildfarm,代码行数:14,代码来源:ByteStringIteratorInputStreamTest.java

示例11: readSpanningChunksWithEmptyChunk

import com.google.protobuf.ByteString; //导入方法依赖的package包/类
@Test
public void readSpanningChunksWithEmptyChunk() throws IOException {
  ByteString hello = ByteString.copyFromUtf8("Hello, ");
  ByteString world = ByteString.copyFromUtf8("World");
  InputStream in = new ByteStringIteratorInputStream(
      ImmutableList.<ByteString>of(hello, ByteString.EMPTY, world).iterator());
  ByteString helloWorld = hello.concat(world);
  byte[] data = new byte[helloWorld.size()];

  assertThat(in.read(data)).isEqualTo(helloWorld.size());
  assertThat(ByteString.copyFrom(data)).isEqualTo(helloWorld);
  assertThat(in.read()).isEqualTo(-1);
}
 
开发者ID:bazelbuild,项目名称:bazel-buildfarm,代码行数:14,代码来源:ByteStringIteratorInputStreamTest.java

示例12: getNextChunk

import com.google.protobuf.ByteString; //导入方法依赖的package包/类
private static byte[] getNextChunk(final ByteString bs, final int offset, int size) {
    int snapshotLength = bs.size();
    int start = offset;
    if (size > snapshotLength) {
        size = snapshotLength;
    } else {
        if (start + size > snapshotLength) {
            size = snapshotLength - start;
        }
    }

    byte[] nextChunk = new byte[size];
    bs.copyTo(nextChunk, start, 0, size);
    return nextChunk;
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:16,代码来源:SnapshotTrackerTest.java

示例13: escapeBytes

import com.google.protobuf.ByteString; //导入方法依赖的package包/类
/**
 * Escapes bytes in the format used in protocol buffer text format, which is the same as the
 * format used for C string literals. All bytes that are not printable 7-bit ASCII characters
 * are escaped, as well as backslash, single-quote, and double-quote characters. Characters for
 * which no defined short-hand escape sequence is defined will be escaped using 3-digit octal
 * sequences.
 */
static String escapeBytes(ByteString input) {
    StringBuilder builder = new StringBuilder(input.size());
    for (int i = 0; i < input.size(); i++) {
        byte b = input.byteAt(i);
        switch (b) {
            // Java does not recognize \a or \v, apparently.
            case 0x07:
                builder.append("\\a");
                break;
            case '\b':
                builder.append("\\b");
                break;
            case '\f':
                builder.append("\\f");
                break;
            case '\n':
                builder.append("\\n");
                break;
            case '\r':
                builder.append("\\r");
                break;
            case '\t':
                builder.append("\\t");
                break;
            case 0x0b:
                builder.append("\\v");
                break;
            case '\\':
                builder.append("\\\\");
                break;
            case '\'':
                builder.append("\\\'");
                break;
            case '"':
                builder.append("\\\"");
                break;
            default:
                if (b >= 0x20) {
                    builder.append((char) b);
                } else {
                    builder.append('\\');
                    builder.append((char) ('0' + ((b >>> 6) & 3)));
                    builder.append((char) ('0' + ((b >>> 3) & 7)));
                    builder.append((char) ('0' + (b & 7)));
                }
                break;
        }
    }
    return builder.toString();
}
 
开发者ID:jigsaw-projects,项目名称:jigsaw-payment,代码行数:58,代码来源:XmlFormat.java

示例14: testReceivingAppendEntriesDuringInstallSnapshotFromDifferentLeader

import com.google.protobuf.ByteString; //导入方法依赖的package包/类
@Test
public void testReceivingAppendEntriesDuringInstallSnapshotFromDifferentLeader() {
    logStart("testReceivingAppendEntriesDuringInstallSnapshotFromDifferentLeader");

    MockRaftActorContext context = createActorContext();

    follower = createBehavior(context);

    ByteString bsSnapshot  = createSnapshot();
    int snapshotLength = bsSnapshot.size();
    int chunkSize = 50;
    int totalChunks = snapshotLength / chunkSize + (snapshotLength % chunkSize > 0 ? 1 : 0);
    int lastIncludedIndex = 1;

    // Check that snapshot installation is not in progress
    assertNull(follower.getSnapshotTracker());

    // Make sure that we have more than 1 chunk to send
    assertTrue(totalChunks > 1);

    // Send an install snapshot with the first chunk to start the process of installing a snapshot
    byte[] chunkData = getNextChunk(bsSnapshot, 0, chunkSize);
    follower.handleMessage(leaderActor, new InstallSnapshot(1, "leader", lastIncludedIndex, 1,
            chunkData, 1, totalChunks));

    // Check if snapshot installation is in progress now
    assertNotNull(follower.getSnapshotTracker());

    // Send appendEntries with a new term and leader.
    AppendEntries appendEntries = new AppendEntries(2, "new-leader", 1, 1,
            Arrays.asList(newReplicatedLogEntry(2, 2, "3")), 2, -1, (short)1);

    follower.handleMessage(leaderActor, appendEntries);

    AppendEntriesReply reply = MessageCollectorActor.expectFirstMatching(leaderActor, AppendEntriesReply.class);
    assertEquals("isSuccess", true, reply.isSuccess());
    assertEquals("getLogLastIndex", 2, reply.getLogLastIndex());
    assertEquals("getLogLastTerm", 2, reply.getLogLastTerm());
    assertEquals("getTerm", 2, reply.getTerm());

    assertNull(follower.getSnapshotTracker());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:43,代码来源:FollowerTest.java

示例15: testReceivingAppendEntriesDuringInstallSnapshot

import com.google.protobuf.ByteString; //导入方法依赖的package包/类
/**
 * Verify that when an AppendEntries is sent to a follower during a snapshot install
 * the Follower short-circuits the processing of the AppendEntries message.
 */
@Test
public void testReceivingAppendEntriesDuringInstallSnapshot() {
    logStart("testReceivingAppendEntriesDuringInstallSnapshot");

    MockRaftActorContext context = createActorContext();

    follower = createBehavior(context);

    ByteString bsSnapshot  = createSnapshot();
    int snapshotLength = bsSnapshot.size();
    int chunkSize = 50;
    int totalChunks = snapshotLength / chunkSize + (snapshotLength % chunkSize > 0 ? 1 : 0);
    int lastIncludedIndex = 1;

    // Check that snapshot installation is not in progress
    assertNull(follower.getSnapshotTracker());

    // Make sure that we have more than 1 chunk to send
    assertTrue(totalChunks > 1);

    // Send an install snapshot with the first chunk to start the process of installing a snapshot
    byte[] chunkData = getNextChunk(bsSnapshot, 0, chunkSize);
    follower.handleMessage(leaderActor, new InstallSnapshot(1, "leader", lastIncludedIndex, 1,
            chunkData, 1, totalChunks));

    // Check if snapshot installation is in progress now
    assertNotNull(follower.getSnapshotTracker());

    // Send an append entry
    AppendEntries appendEntries = new AppendEntries(1, "leader", 1, 1,
            Arrays.asList(newReplicatedLogEntry(2, 1, "3")), 2, -1, (short)1);

    follower.handleMessage(leaderActor, appendEntries);

    AppendEntriesReply reply = MessageCollectorActor.expectFirstMatching(leaderActor, AppendEntriesReply.class);
    assertEquals("isSuccess", true, reply.isSuccess());
    assertEquals("getLogLastIndex", context.getReplicatedLog().lastIndex(), reply.getLogLastIndex());
    assertEquals("getLogLastTerm", context.getReplicatedLog().lastTerm(), reply.getLogLastTerm());
    assertEquals("getTerm", context.getTermInformation().getCurrentTerm(), reply.getTerm());

    assertNotNull(follower.getSnapshotTracker());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:47,代码来源:FollowerTest.java


注:本文中的com.google.protobuf.ByteString.size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。