當前位置: 首頁>>代碼示例>>Java>>正文


Java ByteString.byteAt方法代碼示例

本文整理匯總了Java中com.google.protobuf.ByteString.byteAt方法的典型用法代碼示例。如果您正苦於以下問題:Java ByteString.byteAt方法的具體用法?Java ByteString.byteAt怎麽用?Java ByteString.byteAt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.protobuf.ByteString的用法示例。


在下文中一共展示了ByteString.byteAt方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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

示例2: 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

示例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.
 */
public 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:
          // Note:  Bytes with the high-order bit set should be escaped.  Since
          //   bytes are signed, such bytes will compare less than 0x20, hence
          //   the following line is correct.
          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,代碼行數:41,代碼來源:TextUtils.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: 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

示例6: 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 {
		final String unicodeString = unicodeEscaped((char) b);
		builder.append(unicodeString);
                }
                break;
        }
    }
    return builder.toString();
}
 
開發者ID:jigsaw-projects,項目名稱:jigsaw-payment,代碼行數:56,代碼來源:JsonFormat.java

示例7: split

import com.google.protobuf.ByteString; //導入方法依賴的package包/類
public static List<Coprocessor.KeyRange> split(Coprocessor.KeyRange range, int splitFactor) {
  if (splitFactor > 32 || splitFactor <= 0 || (splitFactor & (splitFactor - 1)) != 0) {
    throw new TiClientInternalException(
        "splitFactor must be positive integer power of 2 and no greater than 16");
  }

  ByteString startKey = range.getStart();
  ByteString endKey = range.getEnd();
  // we don't cut infinite
  if (startKey.isEmpty() || endKey.isEmpty()) {
    return ImmutableList.of(range);
  }

  ImmutableList.Builder<Coprocessor.KeyRange> resultList = ImmutableList.builder();
  int maxSize = Math.max(startKey.size(), endKey.size());
  int i;

  for (i = 0; i < maxSize; i++) {
    byte sb = i < startKey.size() ? startKey.byteAt(i) : 0;
    byte eb = i < endKey.size() ? endKey.byteAt(i) : 0;
    if (sb != eb) {
      break;
    }
  }

  ByteString sRemaining = i < startKey.size() ? startKey.substring(i) : ByteString.EMPTY;
  ByteString eRemaining = i < endKey.size() ? endKey.substring(i) : ByteString.EMPTY;

  CodecDataInput cdi = new CodecDataInput(sRemaining);
  int uss = cdi.readPartialUnsignedShort();

  cdi = new CodecDataInput(eRemaining);
  int ues = cdi.readPartialUnsignedShort();

  int delta = (ues - uss) / splitFactor;
  if (delta <= 0) {
    return ImmutableList.of(range);
  }

  ByteString prefix = startKey.size() > endKey.size() ?
                      startKey.substring(0, i) : endKey.substring(0, i);
  ByteString newStartKey = startKey;
  ByteString newEndKey;
  for (int j = 0; j < splitFactor; j++) {
    uss += delta;
    if (j == splitFactor - 1) {
      newEndKey = endKey;
    } else {
      CodecDataOutput cdo = new CodecDataOutput();
      cdo.writeShort(uss);
      newEndKey = prefix.concat(cdo.toByteString());
    }
    resultList.add(makeCoprocRange(newStartKey, newEndKey));
    newStartKey = newEndKey;
  }

  return resultList.build();
}
 
開發者ID:pingcap,項目名稱:tikv-client-lib-java,代碼行數:59,代碼來源:KeyRangeUtils.java


注:本文中的com.google.protobuf.ByteString.byteAt方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。