io.protostuff.ByteString.copyFromUtf8()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(129)

本文整理了Java中io.protostuff.ByteString.copyFromUtf8()方法的一些代码示例,展示了ByteString.copyFromUtf8()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteString.copyFromUtf8()方法的具体详情如下:
包路径:io.protostuff.ByteString
类名称:ByteString
方法名:copyFromUtf8

ByteString.copyFromUtf8介绍

[英]Encodes text into a sequence of UTF-8 bytes and returns the result as a ByteString.
[中]将文本编码为UTF-8字节序列,并将结果作为ByteString返回。

代码示例

代码示例来源:origin: protostuff/protostuff

static ByteString bs(String text)
{
  return ByteString.copyFromUtf8(text);
}

代码示例来源:origin: protostuff/protostuff

new Double[] { null, 1.1d, null, 2.2d, null },
new String[] { null, "a", null, "b", null },
new ByteString[] { null, ByteString.copyFromUtf8("a"), null, ByteString.copyFromUtf8("b"), null },
new byte[][] { null, new byte[] { 'a' }, null, new byte[] { 'b' }, null },
new BigDecimal[] { null, new BigDecimal(1.1d), null, new BigDecimal(2.2d), null },

代码示例来源:origin: protostuff/protostuff

new Double[] { 1.1d, null, 2.2d },
new String[] { "a", null, "b" },
new ByteString[] { ByteString.copyFromUtf8("a"), null, ByteString.copyFromUtf8("b") },
new byte[][] { new byte[] { 'a' }, null, new byte[] { 'b' } },
new BigDecimal[] { new BigDecimal(1.1d), null, new BigDecimal(2.2d) },

代码示例来源:origin: protostuff/protostuff

new Double[] { null, 1.1d, 2.2d, null },
new String[] { null, "a", "b", null },
new ByteString[] { null, ByteString.copyFromUtf8("a"), ByteString.copyFromUtf8("b"), null },
new byte[][] { null, new byte[] { 'a' }, new byte[] { 'b' }, null },
new BigDecimal[] { null, new BigDecimal(1.1d), new BigDecimal(2.2d), null },

代码示例来源:origin: protostuff/protostuff

new Double[] { 1.1d, 2.2d, null },
new String[] { "a", "b", null },
new ByteString[] { ByteString.copyFromUtf8("a"), ByteString.copyFromUtf8("b"), null },
new byte[][] { new byte[] { 'a' }, new byte[] { 'b' }, null },
new BigDecimal[] { new BigDecimal(1.1d), new BigDecimal(2.2d), null },

代码示例来源:origin: protostuff/protostuff

new Double[] { 1.1d, null, 2.2d },
new String[] { "a", null, "b" },
new ByteString[] { ByteString.copyFromUtf8("a"), null, ByteString.copyFromUtf8("b") },
new byte[][] { new byte[] { 'a' }, null, new byte[] { 'b' } },
new BigDecimal[] { new BigDecimal(1.1d), null, new BigDecimal(2.2d) },

代码示例来源:origin: protostuff/protostuff

new Double[] { null, 1.1d, 2.2d },
new String[] { null, "a", "b" },
new ByteString[] { null, ByteString.copyFromUtf8("a"), ByteString.copyFromUtf8("b") },
new byte[][] { null, new byte[] { 'a' }, new byte[] { 'b' } },
new BigDecimal[] { null, new BigDecimal(1.1d), new BigDecimal(2.2d) },

代码示例来源:origin: protostuff/protostuff

new Double[] { null, 1.1d, null, 2.2d, null },
new String[] { null, "a", null, "b", null },
new ByteString[] { null, ByteString.copyFromUtf8("a"), null, ByteString.copyFromUtf8("b"), null },
new byte[][] { null, new byte[] { 'a' }, null, new byte[] { 'b' }, null },
new BigDecimal[] { null, new BigDecimal(1.1d), null, new BigDecimal(2.2d), null },

代码示例来源:origin: protostuff/protostuff

new Double[] { null, 1.1d, 2.2d },
new String[] { null, "a", "b" },
new ByteString[] { null, ByteString.copyFromUtf8("a"), ByteString.copyFromUtf8("b") },
new byte[][] { null, new byte[] { 'a' }, new byte[] { 'b' } },
new BigDecimal[] { null, new BigDecimal(1.1d), new BigDecimal(2.2d) },

代码示例来源:origin: protostuff/protostuff

new Double[] { 1.1d, 2.2d, null },
new String[] { "a", "b", null },
new ByteString[] { ByteString.copyFromUtf8("a"), ByteString.copyFromUtf8("b"), null },
new byte[][] { new byte[] { 'a' }, new byte[] { 'b' }, null },
new BigDecimal[] { new BigDecimal(1.1d), new BigDecimal(2.2d), null },

代码示例来源:origin: protostuff/protostuff

new Double[] { null, 1.1d, 2.2d, null },
new String[] { null, "a", "b", null },
new ByteString[] { null, ByteString.copyFromUtf8("a"), ByteString.copyFromUtf8("b"), null },
new byte[][] { null, new byte[] { 'a' }, new byte[] { 'b' }, null },
new BigDecimal[] { null, new BigDecimal(1.1d), new BigDecimal(2.2d), null },

代码示例来源:origin: protostuff/protostuff

public void testFooTooLarge() throws Exception
{
  Schema<Foo> schema = Foo.getSchema();
  Foo message = SerializableObjects.newFoo(
      new Integer[] { 90210, -90210, 0, 128 },
      new String[] { "ab", "cd" },
      new Bar[] { SerializableObjects.bar, SerializableObjects.negativeBar },
      new EnumSample[] { EnumSample.TYPE0, EnumSample.TYPE2 },
      new ByteString[] { ByteString.copyFromUtf8("ef"), ByteString.copyFromUtf8("gh") },
      new Boolean[] { true, false },
      new Float[] { 1234.4321f, -1234.4321f, 0f },
      new Double[] { 12345678.87654321d, -12345678.87654321d, 0d },
      new Long[] { 7060504030201l, -7060504030201l, 0l });
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  int size = optWriteDelimitedTo(out, message, schema, buf());
  int delimSize = ProtobufOutput.computeRawVarint32Size(size);
  byte[] data = out.toByteArray();
  int expectedSize = size + delimSize; // 258
  assertEquals(expectedSize, data.length);
  verifyOptData(data, message, schema, buf());
  ByteArrayInputStream in = new ByteArrayInputStream(data);
  Foo parsedMessage = schema.newMessage();
  boolean merged = optMergeDelimitedFrom(in, parsedMessage, schema, buf(256));
  assertFalse(merged);
}

代码示例来源:origin: protostuff/protostuff

SerializableObjects.bar, SerializableObjects.negativeBar },
new EnumSample[] { EnumSample.TYPE0, EnumSample.TYPE2 },
new ByteString[] { ByteString.copyFromUtf8("ef"), ByteString.copyFromUtf8("gh") },
new Boolean[] { true, false },
new Float[] { 1234.4321f, -1234.4321f, 0f },

代码示例来源:origin: protostuff/protostuff

public void testFoo() throws Exception
{
  Bar bar = new Bar();
  bar.setSomeInt(1);
  bar.setSomeBytes(ByteString.copyFromUtf8(ESCAPE_TARGET));
  bar.setSomeString(ESCAPE_TARGET);
  ArrayList<Bar> bars = new ArrayList<Bar>();
  bars.add(bar);
  bars.add(bar);
  ArrayList<String> strings = new ArrayList<String>();
  strings.add(ESCAPE_TARGET);
  strings.add("");
  strings.add(ESCAPE_TARGET);
  Foo foo = new Foo();
  foo.setSomeBar(bars);
  foo.setSomeString(strings);
  byte[] protostuff = ProtostuffIOUtil.toByteArray(foo, foo.cachedSchema(), buf());
  byte[] json = JsonIOUtil.toByteArray(ProtostuffIOUtil.newPipe(protostuff),
      Foo.getPipeSchema(), false);
  byte[] json2 = JsonXIOUtil.toByteArray(ProtostuffIOUtil.newPipe(protostuff),
      Foo.getPipeSchema(), false, buf());
  assertTrue(json.length == json2.length);
  String strJson = STRING.deser(json);
  String strJson2 = STRING.deser(json2);
  assertEquals(strJson, strJson2);
  System.err.println(strJson);
  System.err.println(strJson2);
}

代码示例来源:origin: protostuff/protostuff

expectDouble = Double.valueOf(1234567.7654321d);
expectString = "foo";
expectByteString = ByteString.copyFromUtf8("gg");

代码示例来源:origin: protostuff/protostuff

@Test
public void testBarWithEmptyStringAndByteString() throws Exception
{
  Bar barCompare = new Bar();
  barCompare.setSomeBytes(ByteString.copyFromUtf8(new String("")));
  barCompare.setSomeString(new String(""));
  Bar dbar = new Bar();
  byte[] data = XmlIOUtil.toByteArray(barCompare, barCompare.cachedSchema());
  XmlIOUtil.mergeFrom(data, dbar, dbar.cachedSchema());
  SerializableObjects.assertEquals(barCompare, dbar);
  // test equal serialization on both xml outputs
  byte[] actuals = XmlXIOUtil.toByteArray(barCompare,
      barCompare.cachedSchema(), LinkedBuffer.allocate(256));
  assertArrayEquals(data, actuals);
}

代码示例来源:origin: protostuff/protostuff

public void testBar() throws Exception
{
  Bar bar = new Bar();
  bar.setSomeInt(1);
  bar.setSomeBytes(ByteString.copyFromUtf8(ESCAPE_TARGET));
  bar.setSomeString(ESCAPE_TARGET);
  byte[] protostuff = ProtostuffIOUtil.toByteArray(bar, bar.cachedSchema(), buf());
  byte[] json = JsonIOUtil.toByteArray(ProtostuffIOUtil.newPipe(protostuff),
      Bar.getPipeSchema(), false);
  byte[] json2 = JsonXIOUtil.toByteArray(ProtostuffIOUtil.newPipe(protostuff),
      Bar.getPipeSchema(), false, buf());
  assertTrue(json.length == json2.length);
  String strJson = STRING.deser(json);
  String strJson2 = STRING.deser(json2);
  assertEquals(strJson, strJson2);
  System.err.println(strJson);
  System.err.println(strJson2);
}

相关文章