Java 类com.fasterxml.jackson.core.util.BufferRecycler 实例源码

项目:GitHub    文件:UTF8DataInputJsonParserTest.java   
@Test
public void test_decodeBase64ThrowsEOFException() throws IOException {
    IOContext ioContext = new IOContext(new BufferRecycler(), this, true);
    byte[] byteArray = new byte[5];
    InputStream byteArrayInputStream = new ByteArrayInputStream(byteArray);
    DataInputStream dataInputStream = new DataInputStream(byteArrayInputStream);
    ByteQuadsCanonicalizer byteQuadsCanonicalizer = ByteQuadsCanonicalizer.createRoot();
    UTF8DataInputJsonParser uTF8DataInputJsonParser = new UTF8DataInputJsonParser(ObjectReadContext.empty(),
            ioContext, (byte) 26, dataInputStream, byteQuadsCanonicalizer, 3);

    try {
        uTF8DataInputJsonParser._decodeBase64(null);
        fail("Expecting exception: EOFException");
    } catch (EOFException e) {
        assertEquals(DataInputStream.class.getName(), e.getStackTrace()[0].getClassName());
    }
}
项目:GitHub    文件:UTF8DataInputJsonParserTest.java   
@Test
public void test_skipStringThrowsIOException() {
    IOContext ioContext = new IOContext(new BufferRecycler(), this, false);
    byte[] byteArray = new byte[12];
    byteArray[4] = (byte) (-10);
    InputStream byteArrayInputStream = new ByteArrayInputStream(byteArray);
    DataInputStream dataInputStream = new DataInputStream(byteArrayInputStream);
    UTF8DataInputJsonParser uTF8DataInputJsonParser = new UTF8DataInputJsonParser(ObjectReadContext.empty(),
            ioContext, 100, dataInputStream, null, 11);

    try {
        uTF8DataInputJsonParser._skipString();
        fail("Expecting exception: IOException");
    } catch (IOException e) {
        assertEquals(JsonParser.class.getName(), e.getStackTrace()[0].getClassName());
    }
}
项目:GitHub    文件:UTF8DataInputJsonParserTest.java   
@Test
public void testNextBooleanValueThrowsIOException() {
    IOContext ioContext = new IOContext(new BufferRecycler(), this, false);
    byte[] byteArray = new byte[12];
    byteArray[4] = (byte) (-10);
    InputStream byteArrayInputStream = new ByteArrayInputStream(byteArray);
    DataInputStream dataInputStream = new DataInputStream(byteArrayInputStream);
    UTF8DataInputJsonParser uTF8DataInputJsonParser = new UTF8DataInputJsonParser(ObjectReadContext.empty(),
            ioContext, 100, dataInputStream, null, 11);

    try {
        uTF8DataInputJsonParser.nextBooleanValue();
        fail("Expecting exception: IOException");
    } catch (IOException e) {
        assertEquals(JsonParser.class.getName(), e.getStackTrace()[0].getClassName());
    }
}
项目:GitHub    文件:UTF8DataInputJsonParserTest.java   
@Test
public void testNextTextValueThrowsIOException() {
    IOContext ioContext = new IOContext(new BufferRecycler(), this, false);
    byte[] byteArray = new byte[20];
    byteArray[0] = (byte) 47;
    InputStream byteArrayInputStream = new ByteArrayInputStream(byteArray);
    DataInputStream dataInputStream = new DataInputStream(byteArrayInputStream);
    UTF8DataInputJsonParser uTF8DataInputJsonParser = new UTF8DataInputJsonParser(ObjectReadContext.empty(),
            ioContext, 915, dataInputStream, null, (byte) 47);

    try {
        uTF8DataInputJsonParser.nextTextValue();
        fail("Expecting exception: IOException");
    } catch (IOException e) {
        assertEquals(JsonParser.class.getName(), e.getStackTrace()[0].getClassName());
    }
}
项目:GitHub    文件:UTF8DataInputJsonParserTest.java   
@Test
public void testNextFieldNameThrowsIOException() {
    IOContext ioContext = new IOContext(new BufferRecycler(), this, false);
    byte[] byteArray = new byte[20];
    byteArray[0] = (byte) 47;
    InputStream byteArrayInputStream = new ByteArrayInputStream(byteArray);
    DataInputStream dataInputStream = new DataInputStream(byteArrayInputStream);
    UTF8DataInputJsonParser uTF8DataInputJsonParser = new UTF8DataInputJsonParser(ObjectReadContext.empty(),
            ioContext, 100, dataInputStream, null, -2624);

    try {
        uTF8DataInputJsonParser.nextFieldName();
        fail("Expecting exception: IOException");
    } catch (IOException e) {
        assertEquals(JsonParser.class.getName(), e.getStackTrace()[0].getClassName());
    }
}
项目:GitHub    文件:UTF8DataInputJsonParserTest.java   
@Test
public void test_handleAposThrowsIOException() {
    IOContext ioContext = new IOContext(new BufferRecycler(), this, false);
    byte[] byteArray = new byte[7];
    byteArray[0] = (byte) (-80);
    InputStream byteArrayInputStream = new ByteArrayInputStream(byteArray);
    DataInputStream dataInputStream = new DataInputStream(byteArrayInputStream);
    ByteQuadsCanonicalizer byteQuadsCanonicalizer = ByteQuadsCanonicalizer.createRoot();
    UTF8DataInputJsonParser uTF8DataInputJsonParser = new UTF8DataInputJsonParser(ObjectReadContext.empty(),
            ioContext, 3, dataInputStream, byteQuadsCanonicalizer, 1);

    try {
        uTF8DataInputJsonParser._handleApos();
        fail("Expecting exception: IOException");
    } catch (IOException e) {
        assertEquals(JsonParser.class.getName(), e.getStackTrace()[0].getClassName());
    }
}
项目:GitHub    文件:UTF8DataInputJsonParserTest.java   
@Test
public void test_parseAposNameThrowsEOFException() throws IOException {
    IOContext ioContext = new IOContext(new BufferRecycler(), this, false);
    byte[] byteArray = new byte[17];
    byteArray[4] = (byte) 43;
    InputStream byteArrayInputStream = new ByteArrayInputStream(byteArray);
    DataInputStream dataInputStream = new DataInputStream(byteArrayInputStream);
    ByteQuadsCanonicalizer byteQuadsCanonicalizer = ByteQuadsCanonicalizer.createRoot();
    UTF8DataInputJsonParser uTF8DataInputJsonParser = new UTF8DataInputJsonParser(ObjectReadContext.empty(),
            ioContext, 42, dataInputStream, byteQuadsCanonicalizer, 0);

    try {
        uTF8DataInputJsonParser._parseAposName();
        fail("Expecting exception: EOFException");
    } catch (EOFException e) {
        assertEquals(DataInputStream.class.getName(), e.getStackTrace()[0].getClassName());
    }
}
项目:GitHub    文件:UTF8DataInputJsonParserTest.java   
@Test
public void testParseEscapedNameThrowsArrayIndexOutOfBoundsException() throws IOException {
    IOContext ioContext = new IOContext((BufferRecycler) null, null, false);
    PipedOutputStream pipedOutputStream = new PipedOutputStream();
    PipedInputStream pipedInputStream = new PipedInputStream(pipedOutputStream, 131);
    DataInputStream dataInputStream = new DataInputStream(pipedInputStream);
    ByteQuadsCanonicalizer byteQuadsCanonicalizer = ByteQuadsCanonicalizer.createRoot();
    UTF8DataInputJsonParser uTF8DataInputJsonParser = new UTF8DataInputJsonParser(ObjectReadContext.empty(),
            ioContext, 131, dataInputStream, byteQuadsCanonicalizer, (byte) 57);
    int[] intArray = new int[3];

    try {
        uTF8DataInputJsonParser.parseEscapedName(intArray, 56, (byte) 72, (byte) 127, (byte) 57);
        fail("Expecting exception: ArrayIndexOutOfBoundsException");
    } catch (ArrayIndexOutOfBoundsException e) {
        assertEquals(UTF8DataInputJsonParser.class.getName(), e.getStackTrace()[0].getClassName());
    }
}
项目:GitHub    文件:UTF8DataInputJsonParserTest.java   
@Test
public void test_parseNegNumberThrowsIOException() throws IOException {
    IOContext ioContext = new IOContext(new BufferRecycler(), this, false);
    byte[] byteArray = new byte[20];
    byteArray[2] = (byte) 73;
    InputStream byteArrayInputStream = new ByteArrayInputStream(byteArray);
    DataInputStream dataInputStream = new DataInputStream(byteArrayInputStream);
    UTF8DataInputJsonParser uTF8DataInputJsonParser = new UTF8DataInputJsonParser(ObjectReadContext.empty(),
            ioContext, 100, dataInputStream, null, 3);
    dataInputStream.readUnsignedShort();

    try {
        uTF8DataInputJsonParser._parseNegNumber();
        fail("Expecting exception: IOException");
    } catch (IOException e) {
        assertEquals(JsonParser.class.getName(), e.getStackTrace()[0].getClassName());
    }
}
项目:GitHub    文件:UTF8DataInputJsonParserTest.java   
@Test
public void test_parsePosNumber() throws IOException {
    byte[] byteArray = new byte[2];
    byteArray[0] = (byte) 51;
    byteArray[1] = (byte) 22;
    IOContext ioContext = new IOContext(new BufferRecycler(), byteArray, false);
    InputStream byteArrayInputStream = new ByteArrayInputStream(byteArray);
    ByteQuadsCanonicalizer byteQuadsCanonicalizer = ByteQuadsCanonicalizer.createRoot();
    DataInputStream dataInputStream = new DataInputStream(byteArrayInputStream);
    UTF8DataInputJsonParser uTF8DataInputJsonParser = new UTF8DataInputJsonParser(ObjectReadContext.empty(),
            ioContext, 1568, dataInputStream, byteQuadsCanonicalizer, 13);
    JsonToken jsonToken = uTF8DataInputJsonParser._parsePosNumber(7);

    assertEquals(7, jsonToken.id());
    assertNull(jsonToken.asString());
}
项目:GitHub    文件:UTF8DataInputJsonParserTest.java   
@Test
public void test_readBinaryThrowsNullPointerException() throws IOException {
    byte[] byteArray = new byte[5];
    byteArray[4] = (byte) 43;
    IOContext ioContext = new IOContext(new BufferRecycler(), byteArray, false);
    InputStream byteArrayInputStream = new ByteArrayInputStream(byteArray);
    DataInputStream dataInputStream = new DataInputStream(byteArrayInputStream);
    ByteQuadsCanonicalizer byteQuadsCanonicalizer = ByteQuadsCanonicalizer.createRoot();
    UTF8DataInputJsonParser uTF8DataInputJsonParser = new UTF8DataInputJsonParser(ObjectReadContext.empty(),
            ioContext, 500, dataInputStream, byteQuadsCanonicalizer, 1);

    try {
        uTF8DataInputJsonParser._readBinary(null, null, byteArray);
        fail("Expecting exception: NullPointerException");
    } catch (NullPointerException e) {
        assertEquals(UTF8DataInputJsonParser.class.getName(), e.getStackTrace()[0].getClassName());
    }
}
项目:GitHub    文件:UTF8DataInputJsonParserTest.java   
@Test
public void testReadBinaryValueThrowsIOException() {
    BufferRecycler bufferRecycler = new BufferRecycler();
    IOContext ioContext = new IOContext(bufferRecycler, this, false);
    ByteQuadsCanonicalizer byteQuadsCanonicalizer = ByteQuadsCanonicalizer.createRoot();
    UTF8DataInputJsonParser uTF8DataInputJsonParser = new UTF8DataInputJsonParser(ObjectReadContext.empty(),
            ioContext, (-53), null, byteQuadsCanonicalizer, 48);
    ByteArrayBuilder byteArrayBuilder = new ByteArrayBuilder(bufferRecycler, 1);

    try {
        uTF8DataInputJsonParser.readBinaryValue(null, byteArrayBuilder);
        fail("Expecting exception: IOException");
    } catch (IOException e) {
        assertEquals(JsonParser.class.getName(), e.getStackTrace()[0].getClassName());
    }
}
项目:GitHub    文件:Base64VariantTest.java   
@Test
public void testDecodeTaking2ArgumentsOne() {
    Base64Variant base64Variant = new Base64Variant("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
            "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
            false,
            'R',
            4);
    BufferRecycler bufferRecycler = new BufferRecycler();
    ByteArrayBuilder byteArrayBuilder = new ByteArrayBuilder(bufferRecycler);

    base64Variant.decode("PEM", byteArrayBuilder);

    assertFalse(base64Variant.usesPadding());
    assertEquals('R', base64Variant.getPaddingChar());
    assertEquals(4, base64Variant.getMaxLineLength());
    assertEquals("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", base64Variant.toString());
    assertEquals("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", base64Variant.getName());
    assertEquals((byte) 82, base64Variant.getPaddingByte());
}
项目:GitHub    文件:UTF8WriterTest.java   
public void testSimpleAscii() throws Exception
{
    BufferRecycler rec = new BufferRecycler();
    IOContext ctxt = new IOContext(rec, null, false);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    UTF8Writer w = new UTF8Writer(ctxt, out);

    String str = "abcdefghijklmnopqrst\u00A0";
    char[] ch = str.toCharArray();

    w.write(ch, 0, ch.length);
    w.flush(); // trigger different code path for close
    w.close();

    byte[] data = out.toByteArray();
    // one 2-byte encoded char
    assertEquals(ch.length+1, data.length);
    String act = out.toString("UTF-8");
    assertEquals(str, act);
}
项目:GitHub    文件:UTF8WriterTest.java   
public void testFlushAfterClose() throws Exception
{
    BufferRecycler rec = new BufferRecycler();
    IOContext ctxt = new IOContext(rec, null, false);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    UTF8Writer w = new UTF8Writer(ctxt, out);

    w.write('X');
    char[] ch = { 'Y' };
    w.write(ch);

    w.close();
    assertEquals(2, out.size());

    // and this ought to be fine...
    w.flush();
    // as well as some more...
    w.close();
    w.flush();
}
项目:athena    文件:JsonRpcReaderUtil.java   
/**
 * Check whether the encoding is valid.
 * @param in input of bytes
 * @throws IOException this is an IO exception
 * @throws UnsupportedException this is an unsupported exception
 */
private static void checkEncoding(ByteBuf in) throws IOException {
    int inputStart = 0;
    int inputLength = 4;
    fliterCharaters(in);
    byte[] buff = new byte[4];
    in.getBytes(in.readerIndex(), buff);
    ByteSourceJsonBootstrapper strapper = new ByteSourceJsonBootstrapper(new IOContext(new BufferRecycler(),
                                                                                       null,
                                                                                       false),
                                                                         buff, inputStart,
                                                                         inputLength);
    JsonEncoding jsonEncoding = strapper.detectEncoding();
    if (!JsonEncoding.UTF8.equals(jsonEncoding)) {
        throw new UnsupportedException("Only UTF-8 encoding is supported.");
    }
}
项目:onos    文件:JsonRpcReaderUtil.java   
/**
 * Check whether the encoding is valid.
 * @param in input of bytes
 * @throws IOException this is an IO exception
 * @throws UnsupportedException this is an unsupported exception
 */
private static void checkEncoding(ByteBuf in) throws IOException {
    int inputStart = 0;
    int inputLength = 4;
    fliterCharaters(in);
    byte[] buff = new byte[4];
    in.getBytes(in.readerIndex(), buff);
    ByteSourceJsonBootstrapper strapper = new ByteSourceJsonBootstrapper(new IOContext(new BufferRecycler(),
                                                                                       null,
                                                                                       false),
                                                                         buff, inputStart,
                                                                         inputLength);
    JsonEncoding jsonEncoding = strapper.detectEncoding();
    if (!JsonEncoding.UTF8.equals(jsonEncoding)) {
        throw new UnsupportedException("Only UTF-8 encoding is supported.");
    }
}
项目:GitHub    文件:TokenStreamFactory.java   
/**
 * Method used by factory to create buffer recycler instances
 * for parsers and generators.
 *<p>
 * Note: only public to give access for <code>ObjectMapper</code>
 */
public BufferRecycler _getBufferRecycler()
{
    /* 23-Apr-2015, tatu: Let's allow disabling of buffer recycling
     *   scheme, for cases where it is considered harmful (possibly
     *   on Android, for example)
     */
    if (Feature.USE_THREAD_LOCAL_FOR_BUFFER_RECYCLING.enabledIn(_factoryFeatures)) {
        return BufferRecyclers.getBufferRecycler();
    }
    return new BufferRecycler();
}
项目:GitHub    文件:IOContext.java   
/**
 * @since 3.0
 */
public IOContext(BufferRecycler br, Object sourceRef, boolean managedResource,
        JsonEncoding enc)
{
    _bufferRecycler = br;
    _sourceRef = sourceRef;
    _managedResource = managedResource;
    _encoding = enc;
}
项目:GitHub    文件:IOContext.java   
/**
 * Method to call when all the processing buffers can be safely
 * recycled.
 */
public void releaseReadIOBuffer(byte[] buf) {
    if (buf != null) {
        /* Let's do sanity checks to ensure once-and-only-once release,
         * as well as avoiding trying to release buffers not owned
         */
        _verifyRelease(buf, _readIOBuffer);
        _readIOBuffer = null;
        _bufferRecycler.releaseByteBuffer(BufferRecycler.BYTE_READ_IO_BUFFER, buf);
    }
}
项目:GitHub    文件:IOContext.java   
public void releaseWriteEncodingBuffer(byte[] buf) {
    if (buf != null) {
        /* Let's do sanity checks to ensure once-and-only-once release,
         * as well as avoiding trying to release buffers not owned
         */
        _verifyRelease(buf, _writeEncodingBuffer);
        _writeEncodingBuffer = null;
        _bufferRecycler.releaseByteBuffer(BufferRecycler.BYTE_WRITE_ENCODING_BUFFER, buf);
    }
}
项目:GitHub    文件:IOContext.java   
public void releaseBase64Buffer(byte[] buf) {
    if (buf != null) { // sanity checks, release once-and-only-once, must be one owned
        _verifyRelease(buf, _base64Buffer);
        _base64Buffer = null;
        _bufferRecycler.releaseByteBuffer(BufferRecycler.BYTE_BASE64_CODEC_BUFFER, buf);
    }
}
项目:GitHub    文件:IOContext.java   
public void releaseTokenBuffer(char[] buf) {
    if (buf != null) {
        _verifyRelease(buf, _tokenCBuffer);
        _tokenCBuffer = null;
        _bufferRecycler.releaseCharBuffer(BufferRecycler.CHAR_TOKEN_BUFFER, buf);
    }
}
项目:GitHub    文件:IOContext.java   
public void releaseConcatBuffer(char[] buf) {
    if (buf != null) {
        // 14-Jan-2014, tatu: Let's actually allow upgrade of the original buffer.
        _verifyRelease(buf, _concatCBuffer);
        _concatCBuffer = null;
        _bufferRecycler.releaseCharBuffer(BufferRecycler.CHAR_CONCAT_BUFFER, buf);
    }
}
项目:GitHub    文件:IOContext.java   
public void releaseNameCopyBuffer(char[] buf) {
    if (buf != null) {
        // 14-Jan-2014, tatu: Let's actually allow upgrade of the original buffer.
        _verifyRelease(buf, _nameCopyBuffer);
        _nameCopyBuffer = null;
        _bufferRecycler.releaseCharBuffer(BufferRecycler.CHAR_NAME_COPY_BUFFER, buf);
    }
}
项目:GitHub    文件:UTF8DataInputJsonParserTest.java   
@Test
public void testGetTextOffsetAndNextFieldName() throws IOException {
    byte[] byteArray = new byte[2];
    byteArray[1] = (byte) 91;
    IOContext ioContext = new IOContext(new BufferRecycler(), byteArray, false);
    InputStream byteArrayInputStream = new ByteArrayInputStream(byteArray);
    DataInputStream dataInputStream = new DataInputStream(byteArrayInputStream);
    ByteQuadsCanonicalizer byteQuadsCanonicalizer = ByteQuadsCanonicalizer.createRoot();
    UTF8DataInputJsonParser uTF8DataInputJsonParser = new UTF8DataInputJsonParser(ObjectReadContext.empty(),
            ioContext, 42, dataInputStream, byteQuadsCanonicalizer, 0);
    assertEquals(0, uTF8DataInputJsonParser.getTextOffset());
    assertNull(uTF8DataInputJsonParser.nextFieldName());
}
项目:GitHub    文件:UTF8DataInputJsonParserTest.java   
@Test
public void testGetNextFieldNameAndGetTextLength() throws IOException {
    byte[] byteArray = new byte[2];
    byteArray[1] = (byte) 91;
    IOContext ioContext = new IOContext(new BufferRecycler(), byteArray, false);
    InputStream byteArrayInputStream = new ByteArrayInputStream(byteArray);
    DataInputStream dataInputStream = new DataInputStream(byteArrayInputStream);
    UTF8DataInputJsonParser uTF8DataInputJsonParser = new UTF8DataInputJsonParser(ObjectReadContext.empty(),
            ioContext, 42, dataInputStream, ByteQuadsCanonicalizer.createRoot(), 0);
    uTF8DataInputJsonParser.nextFieldName();

    assertNull(uTF8DataInputJsonParser.getObjectId());
    assertEquals(1, uTF8DataInputJsonParser.getTextLength());
}
项目:GitHub    文件:UTF8DataInputJsonParserTest.java   
@Test
public void testGetValueAsIntTakingInt() throws IOException {
    byte[] byteArray = new byte[5];
    IOContext ioContext = new IOContext(new BufferRecycler(), byteArray, false);
    InputStream byteArrayInputStream = new ByteArrayInputStream(byteArray);
    DataInputStream dataInputStream = new DataInputStream(byteArrayInputStream);
    UTF8DataInputJsonParser uTF8DataInputJsonParser = new UTF8DataInputJsonParser(ObjectReadContext.empty(),
            ioContext, 500, dataInputStream, ByteQuadsCanonicalizer.createRoot(), 1);

    assertEquals(466, uTF8DataInputJsonParser.getValueAsInt(466));
}
项目:GitHub    文件:UTF8DataInputJsonParserTest.java   
@Test
public void testGetValueAsIntTakingNoArguments() throws IOException {
    byte[] byteArray = new byte[2];
    IOContext ioContext = new IOContext(new BufferRecycler(), byteArray, false);
    InputStream byteArrayInputStream = new ByteArrayInputStream(byteArray);
    DataInputStream dataInputStream = new DataInputStream(byteArrayInputStream);
    UTF8DataInputJsonParser uTF8DataInputJsonParser = new UTF8DataInputJsonParser(ObjectReadContext.empty(),
            ioContext, 42, dataInputStream, ByteQuadsCanonicalizer.createRoot(), 0);

    assertEquals(0, uTF8DataInputJsonParser.getValueAsInt());
}
项目:GitHub    文件:TestUtf8Generator.java   
public void testUtf8Issue462() throws Exception
{
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    IOContext ioc = new IOContext(new BufferRecycler(), bytes, true);
    JsonGenerator gen = new UTF8JsonGenerator(ObjectWriteContext.empty(), ioc, 0, bytes,
            JsonFactory.DEFAULT_ROOT_VALUE_SEPARATOR, null, null);

    String str = "Natuurlijk is alles gelukt en weer een tevreden klant\uD83D\uDE04";
    int length = 4000 - 38;

    for (int i = 1; i <= length; ++i) {
        gen.writeNumber(1);
    }
    gen.writeString(str);
    gen.flush();
    gen.close();

    // Also verify it's parsable?
    JsonParser p = JSON_F.createParser(ObjectReadContext.empty(), bytes.toByteArray());
    for (int i = 1; i <= length; ++i) {
        assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
        assertEquals(1, p.getIntValue());
    }
    assertToken(JsonToken.VALUE_STRING, p.nextToken());
    assertEquals(str, p.getText());
    assertNull(p.nextToken());
    p.close();
}
项目:GitHub    文件:Base64VariantTest.java   
@Test
public void testEquals() {
    Base64Variant base64Variant = new Base64Variant("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
            "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
            true,
            ':',
            ':');

    assertFalse(base64Variant.equals(new BufferRecycler()));
    assertTrue(base64Variant.equals(base64Variant));

}
项目:GitHub    文件:UTF8WriterTest.java   
public void testSimple() throws Exception
{
    BufferRecycler rec = new BufferRecycler();
    IOContext ctxt = new IOContext(rec, null, false);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    UTF8Writer w = new UTF8Writer(ctxt, out);

    String str = "AB\u00A0\u1AE9\uFFFC";
    char[] ch = str.toCharArray();

    // Let's write 3 times, using different methods
    w.write(str);

    w.append(ch[0]);
    w.write(ch[1]);
    w.write(ch, 2, 3);
    w.flush();

    w.write(str, 0, str.length());
    w.close();

    // and thus should have 3 times contents
    byte[] data = out.toByteArray();
    assertEquals(3*10, data.length);
    String act = out.toString("UTF-8");
    assertEquals(15, act.length());

    assertEquals(3 * str.length(), act.length());
    assertEquals(str+str+str, act);
}
项目:GitHub    文件:TestMergedStream.java   
public void testSimple() throws Exception
{
    BufferRecycler rec = new BufferRecycler();
    IOContext ctxt = new IOContext(rec, null, false);
    // bit complicated; must use recyclable buffer...
    byte[] first = ctxt.allocReadIOBuffer();
    System.arraycopy("ABCDE".getBytes("UTF-8"), 0, first, 99, 5);
    byte[] second = "FGHIJ".getBytes("UTF-8");

    assertNull(ctxt.getSourceReference());
    assertFalse(ctxt.isResourceManaged());
    ctxt.setEncoding(JsonEncoding.UTF8);
    MergedStream ms = new MergedStream(ctxt, new ByteArrayInputStream(second),
                                       first, 99, 99+5);
    // Ok, first, should have 5 bytes from first buffer:
    assertEquals(5, ms.available());
    // not supported when there's buffered stuff...
    assertFalse(ms.markSupported());
    // so this won't work, but shouldn't throw exception
    ms.mark(1);
    assertEquals((byte) 'A', ms.read());
    assertEquals(3, ms.skip(3));
    byte[] buffer = new byte[5];
    /* Ok, now, code is allowed to return anywhere between 1 and 3,
     * but we now it will return 1...
     */
    assertEquals(1, ms.read(buffer, 1, 3));
    assertEquals((byte) 'E', buffer[1]);
    // So let's read bit more
    assertEquals(3, ms.read(buffer, 0, 3));
    assertEquals((byte) 'F', buffer[0]);
    assertEquals((byte) 'G', buffer[1]);
    assertEquals((byte) 'H', buffer[2]);
    assertEquals(2, ms.available());
    // And then skip the reset
    assertEquals(2, ms.skip(200));

    ms.close();
}
项目:GitHub    文件:SegmentedStringWriterTest.java   
public void testSimple() throws Exception
{
    BufferRecycler br = new BufferRecycler();
    SegmentedStringWriter w = new SegmentedStringWriter(br);

    StringBuilder exp = new StringBuilder();

    for (int i = 0; exp.length() < 100; ++i) {
        String nr = String.valueOf(i);
        exp.append(' ').append(nr);
        w.append(' ');
        switch (i % 4) {
        case 0:
            w.append(nr);
            break;
        case 1:
            {
                String str = "  "+nr;
                w.append(str, 2, str.length());
            }
            break;
        case 2:
            w.write(nr.toCharArray());
            break;
        default:
            {
                char[] ch = (" "+nr+" ").toCharArray();
                w.write(ch, 1, nr.length());
            }
            break;
        }
    }
    // flush, close are nops but trigger just for fun
    w.flush();
    w.close();

    String act = w.getAndClear();
    assertEquals(exp.toString(), act);
}
项目:QuizUpWinner    文件:IOContext.java   
public final byte[] allocBase64Buffer()
{
  _verifyAlloc(this._base64Buffer);
  byte[] arrayOfByte = this._bufferRecycler.allocByteBuffer(BufferRecycler.ByteBufferType.BASE64_CODEC_BUFFER);
  this._base64Buffer = arrayOfByte;
  return arrayOfByte;
}
项目:QuizUpWinner    文件:IOContext.java   
public final char[] allocConcatBuffer()
{
  _verifyAlloc(this._concatCBuffer);
  char[] arrayOfChar = this._bufferRecycler.allocCharBuffer(BufferRecycler.CharBufferType.CONCAT_BUFFER);
  this._concatCBuffer = arrayOfChar;
  return arrayOfChar;
}
项目:QuizUpWinner    文件:IOContext.java   
public final char[] allocNameCopyBuffer(int paramInt)
{
  _verifyAlloc(this._nameCopyBuffer);
  char[] arrayOfChar = this._bufferRecycler.allocCharBuffer(BufferRecycler.CharBufferType.NAME_COPY_BUFFER, paramInt);
  this._nameCopyBuffer = arrayOfChar;
  return arrayOfChar;
}
项目:QuizUpWinner    文件:IOContext.java   
public final byte[] allocReadIOBuffer()
{
  _verifyAlloc(this._readIOBuffer);
  byte[] arrayOfByte = this._bufferRecycler.allocByteBuffer(BufferRecycler.ByteBufferType.READ_IO_BUFFER);
  this._readIOBuffer = arrayOfByte;
  return arrayOfByte;
}
项目:QuizUpWinner    文件:IOContext.java   
public final char[] allocTokenBuffer()
{
  _verifyAlloc(this._tokenCBuffer);
  char[] arrayOfChar = this._bufferRecycler.allocCharBuffer(BufferRecycler.CharBufferType.TOKEN_BUFFER);
  this._tokenCBuffer = arrayOfChar;
  return arrayOfChar;
}
项目:QuizUpWinner    文件:IOContext.java   
public final byte[] allocWriteEncodingBuffer()
{
  _verifyAlloc(this._writeEncodingBuffer);
  byte[] arrayOfByte = this._bufferRecycler.allocByteBuffer(BufferRecycler.ByteBufferType.WRITE_ENCODING_BUFFER);
  this._writeEncodingBuffer = arrayOfByte;
  return arrayOfByte;
}