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


Java STRING类代码示例

本文整理汇总了Java中io.protostuff.StringSerializer.STRING的典型用法代码示例。如果您正苦于以下问题:Java STRING类的具体用法?Java STRING怎么用?Java STRING使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: readString

import io.protostuff.StringSerializer.STRING; //导入依赖的package包/类
/**
 * Read a {@code string} field value from the stream.
 */
@Override
public String readString() throws IOException
{
    final int size = readRawVarint32();
    if (size <= (bufferSize - bufferPos) && size > 0)
    {
        // Fast path: We already have the bytes in a contiguous buffer, so
        // just copy directly from it.
        final String result = STRING.deser(buffer, bufferPos, size);
        bufferPos += size;
        return result;
    }
    else
    {
        // Slow path: Build a byte array first then copy it.
        return STRING.deser(readRawBytes(size));
    }
}
 
开发者ID:BFergerson,项目名称:Beam,代码行数:22,代码来源:CodedInput.java

示例2: parseInt

import io.protostuff.StringSerializer.STRING; //导入依赖的package包/类
/**
 * Parse an ascii int from a raw buffer.
 */
public static int parseInt(final byte[] buffer, final int start, final int length,
        final int radix) throws NumberFormatException
{
    if (length == 0)
        throw new NumberFormatException(STRING.deser(buffer, start, length));

    if (buffer[start] == '-')
    {
        if (length == 1)
            throw new NumberFormatException(STRING.deser(buffer, start, length));

        return parseInt(buffer, start + 1, length - 1, radix, false);
    }

    return parseInt(buffer, start, length, radix, true);
}
 
开发者ID:BFergerson,项目名称:Beam,代码行数:20,代码来源:NumberParser.java

示例3: parseLong

import io.protostuff.StringSerializer.STRING; //导入依赖的package包/类
/**
 * Parse an ascii long from a raw buffer.
 */
public static long parseLong(final byte[] buffer, final int start, final int length,
        final int radix) throws NumberFormatException
{
    if (length == 0)
        throw new NumberFormatException(STRING.deser(buffer, start, length));

    if (buffer[start] == '-')
    {
        if (length == 1)
            throw new NumberFormatException(STRING.deser(buffer, start, length));

        return parseLong(buffer, start + 1, length - 1, radix, false);
    }

    return parseLong(buffer, start, length, radix, true);
}
 
开发者ID:BFergerson,项目名称:Beam,代码行数:20,代码来源:NumberParser.java

示例4: readString

import io.protostuff.StringSerializer.STRING; //导入依赖的package包/类
public String readString() throws IOException {
  final int length = readRawVarint32();
  if (length < 0) {
    throw negativeSize();
  }

  if (buffer.readableBytes() < length) {
    throw misreportedSize();
  }

  if (buffer.hasArray()) {
    final int currPosition = buffer.readerIndex();

    buffer.skipBytes(length);

    return STRING.deser(buffer.array(),
        buffer.arrayOffset() + currPosition,
        length);
  } else {
    byte[] tmp = new byte[length];
    buffer.readBytes(tmp);
    return STRING.deser(tmp);
  }
}
 
开发者ID:cloud-software-foundation,项目名称:c5,代码行数:25,代码来源:ByteBufInput.java

示例5: testUnknownScalarFields

import io.protostuff.StringSerializer.STRING; //导入依赖的package包/类
@Test
public void testUnknownScalarFields() throws Exception
{
    String[] regularMessages = new String[] {
            "<?xml version='1.0' encoding='UTF-8'?>" +
                    "<Baz><int>1</int><string>string</string>" +
                    "<double>555.444</double><id>1</id></Baz>",

            "<?xml version='1.0' encoding='UTF-8'?>" +
                    "<Baz><int>1</int><string>string</string>" +
                    "<id>2</id><double>555.444</double></Baz>",

            "<?xml version='1.0' encoding='UTF-8'?>" +
                    "<Baz><id>3</id><int>1</int>" +
                    "<string>string</string><double>555.444</double>" +
                    "<bytes><![CDATA[b2]]></bytes></Baz>"
    };

    for (int i = 0; i < regularMessages.length; i++)
    {
        Baz b = new Baz();
        XmlIOUtil.mergeFrom(STRING.ser(regularMessages[i]),
                b, b.cachedSchema());
        assertTrue(i + 1 == b.getId());
    }
}
 
开发者ID:protostuff,项目名称:protostuff,代码行数:27,代码来源:XmlCoreSerDeserTest.java

示例6: testFoo

import io.protostuff.StringSerializer.STRING; //导入依赖的package包/类
public void testFoo() throws Exception
{
    Foo fooCompare = foo;

    byte[] jo = JSON_OUTPUT.serialize(fooCompare);
    byte[] jbo = JSON_BUFFERED_OUTPUT.serialize(fooCompare);
    byte[] jso = JSON_STREAMED_OUTPUT.serialize(fooCompare);

    assertTrue(jo.length == jbo.length);
    assertTrue(jso.length == jo.length);

    String joString = STRING.deser(jo);
    String jboString = STRING.deser(jbo);

    assertEquals(joString, jboString);
    assertEquals(joString, STRING.deser(jso));
}
 
开发者ID:protostuff,项目名称:protostuff,代码行数:18,代码来源:JsonCompareOutputsTest.java

示例7: testFooNumeric

import io.protostuff.StringSerializer.STRING; //导入依赖的package包/类
public void testFooNumeric() throws Exception
{
    Foo fooCompare = foo;

    byte[] jo = JSON_OUTPUT_NUMERIC.serialize(fooCompare);
    byte[] jbo = JSON_BUFFERED_OUTPUT_NUMERIC.serialize(fooCompare);
    byte[] jso = JSON_STREAMED_OUTPUT_NUMERIC.serialize(fooCompare);

    assertTrue(jo.length == jbo.length);
    assertTrue(jso.length == jo.length);

    String joString = STRING.deser(jo);
    String jboString = STRING.deser(jbo);

    assertEquals(joString, jboString);
    assertEquals(joString, STRING.deser(jso));
}
 
开发者ID:protostuff,项目名称:protostuff,代码行数:18,代码来源:JsonCompareOutputsTest.java

示例8: testBar

import io.protostuff.StringSerializer.STRING; //导入依赖的package包/类
public void testBar() throws Exception
{
    for (Bar barCompare : new Bar[] { bar, negativeBar })
    {
        byte[] jo = JSON_OUTPUT.serialize(barCompare);
        byte[] jbo = JSON_BUFFERED_OUTPUT.serialize(barCompare);
        byte[] jso = JSON_STREAMED_OUTPUT.serialize(barCompare);

        assertTrue(jo.length == jbo.length);
        assertTrue(jso.length == jo.length);

        String joString = STRING.deser(jo);
        String jboString = STRING.deser(jbo);

        assertEquals(joString, jboString);
        assertEquals(joString, STRING.deser(jso));
    }
}
 
开发者ID:protostuff,项目名称:protostuff,代码行数:19,代码来源:JsonCompareOutputsTest.java

示例9: testBarNumeric

import io.protostuff.StringSerializer.STRING; //导入依赖的package包/类
public void testBarNumeric() throws Exception
{
    for (Bar barCompare : new Bar[] { bar, negativeBar })
    {
        byte[] jo = JSON_OUTPUT_NUMERIC.serialize(barCompare);
        byte[] jbo = JSON_BUFFERED_OUTPUT_NUMERIC.serialize(barCompare);
        byte[] jso = JSON_STREAMED_OUTPUT_NUMERIC.serialize(barCompare);

        assertTrue(jo.length == jbo.length);
        assertTrue(jso.length == jo.length);

        String joString = STRING.deser(jo);
        String jboString = STRING.deser(jbo);

        assertEquals(joString, jboString);
        assertEquals(joString, STRING.deser(jso));
    }
}
 
开发者ID:protostuff,项目名称:protostuff,代码行数:19,代码来源:JsonCompareOutputsTest.java

示例10: testBaz

import io.protostuff.StringSerializer.STRING; //导入依赖的package包/类
public void testBaz() throws Exception
{
    for (Baz bazCompare : new Baz[] { baz, negativeBaz })
    {
        byte[] jo = JSON_OUTPUT.serialize(bazCompare);
        byte[] jbo = JSON_BUFFERED_OUTPUT.serialize(bazCompare);
        byte[] jso = JSON_STREAMED_OUTPUT.serialize(bazCompare);

        assertTrue(jo.length == jbo.length);
        assertTrue(jso.length == jo.length);

        String joString = STRING.deser(jo);
        String jboString = STRING.deser(jbo);

        assertEquals(joString, jboString);
        assertEquals(joString, STRING.deser(jso));
    }
}
 
开发者ID:protostuff,项目名称:protostuff,代码行数:19,代码来源:JsonCompareOutputsTest.java

示例11: testBazNumeric

import io.protostuff.StringSerializer.STRING; //导入依赖的package包/类
public void testBazNumeric() throws Exception
{
    for (Baz bazCompare : new Baz[] { baz, negativeBaz })
    {
        byte[] jo = JSON_OUTPUT_NUMERIC.serialize(bazCompare);
        byte[] jbo = JSON_BUFFERED_OUTPUT_NUMERIC.serialize(bazCompare);
        byte[] jso = JSON_STREAMED_OUTPUT_NUMERIC.serialize(bazCompare);

        assertTrue(jo.length == jbo.length);
        assertTrue(jso.length == jo.length);

        String joString = STRING.deser(jo);
        String jboString = STRING.deser(jbo);

        assertEquals(joString, jboString);
        assertEquals(joString, STRING.deser(jso));
    }
}
 
开发者ID:protostuff,项目名称:protostuff,代码行数:19,代码来源:JsonCompareOutputsTest.java

示例12: testBar

import io.protostuff.StringSerializer.STRING; //导入依赖的package包/类
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);
}
 
开发者ID:protostuff,项目名称:protostuff,代码行数:26,代码来源:JsonEscapeTest.java

示例13: testInt

import io.protostuff.StringSerializer.STRING; //导入依赖的package包/类
public void testInt() throws Exception
{
    for (int i : int_targets)
    {
        LinkedBuffer lb = new LinkedBuffer(256);
        WriteSession session = new WriteSession(lb);
        StringSerializer.writeInt(i, session, lb);

        LinkedBuffer lb2 = new LinkedBuffer(1);
        WriteSession session2 = new WriteSession(lb2);
        StringSerializer.writeInt(i, session2, lb2);

        byte[] buffered = session.toByteArray();
        byte[] buffered_needed_to_grow = session2.toByteArray();
        byte[] builtin = STRING.ser(Integer.toString(i));

        assertEquals(builtin, buffered);
        assertEquals(builtin, buffered_needed_to_grow);
    }
}
 
开发者ID:protostuff,项目名称:protostuff,代码行数:21,代码来源:StringSerializerTest.java

示例14: testLong

import io.protostuff.StringSerializer.STRING; //导入依赖的package包/类
public void testLong() throws Exception
{
    for (long i : long_targets)
    {
        LinkedBuffer lb = new LinkedBuffer(256);
        WriteSession session = new WriteSession(lb);
        StringSerializer.writeLong(i, session, lb);

        LinkedBuffer lb2 = new LinkedBuffer(1);
        WriteSession session2 = new WriteSession(lb2);
        StringSerializer.writeLong(i, session2, lb2);

        byte[] buffered = session.toByteArray();
        byte[] buffered_needed_to_grow = session2.toByteArray();
        byte[] builtin = STRING.ser(Long.toString(i));

        assertEquals(builtin, buffered);
        assertEquals(builtin, buffered_needed_to_grow);
    }
}
 
开发者ID:protostuff,项目名称:protostuff,代码行数:21,代码来源:StringSerializerTest.java

示例15: testFloat

import io.protostuff.StringSerializer.STRING; //导入依赖的package包/类
public void testFloat() throws Exception
{
    for (float i : float_targets)
    {
        LinkedBuffer lb = new LinkedBuffer(256);
        WriteSession session = new WriteSession(lb);
        StringSerializer.writeFloat(i, session, lb);

        LinkedBuffer lb2 = new LinkedBuffer(1);
        WriteSession session2 = new WriteSession(lb2);
        StringSerializer.writeFloat(i, session2, lb2);

        byte[] buffered = session.toByteArray();
        byte[] buffered_needed_to_grow = session2.toByteArray();
        byte[] builtin = STRING.ser(Float.toString(i));

        assertEquals(builtin, buffered);
        assertEquals(builtin, buffered_needed_to_grow);
    }
}
 
开发者ID:protostuff,项目名称:protostuff,代码行数:21,代码来源:StringSerializerTest.java


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