Note: the method can only be called once during its life cycle. This is to protect against accidental sharing.
1314151617181920212223
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());
1112131415161718192021
IOContext ctxt = new IOContext(new BufferRecycler(), "N/A", true); /* I/O Read buffer */ // First succeeds: assertNotNull(ctxt.allocReadIOBuffer()); // second fails try { ctxt.allocReadIOBuffer(); } catch (IllegalStateException e) { verifyException(e, "second time");
1415161718192021222324
// First succeeds: assertNotNull(ctxt.allocReadIOBuffer()); // second fails try { ctxt.allocReadIOBuffer(); } catch (IllegalStateException e) { verifyException(e, "second time"); } // Also: can't succeed with different buffer try {
127128129130131132133134135136137
*/ public static Pipe newPipe(InputStream in, boolean numeric) throws IOException { final IOContext context = new IOContext(DEFAULT_SMILE_FACTORY._getBufferRecycler(), in, false); final SmileParser parser = newSmileParser(in, context.allocReadIOBuffer(), 0, 0, true, context); return JsonIOUtil.newPipe(parser, numeric); //return JsonIOUtil.newPipe(DEFAULT_SMILE_FACTORY.createJsonParser(in), numeric); }
230231232233234235236237238239240
public static <T> void mergeFrom(InputStream in, T message, Schema<T> schema, boolean numeric) throws IOException { final IOContext context = new IOContext(DEFAULT_SMILE_FACTORY._getBufferRecycler(), in, false); final SmileParser parser = newSmileParser(in, context.allocReadIOBuffer(), 0, 0, true, context); //final SmileParser parser = DEFAULT_SMILE_FACTORY.createJsonParser(in); try {
421422423424425426427428429430431
public static <T> List<T> parseListFrom(InputStream in, Schema<T> schema, boolean numeric) throws IOException { final IOContext context = new IOContext(DEFAULT_SMILE_FACTORY._getBufferRecycler(), in, false); final SmileParser parser = newSmileParser(in, context.allocReadIOBuffer(), 0, 0, true, context); //final SmileParser parser = DEFAULT_SMILE_FACTORY.createJsonParser(in); try {
116117118119120121122123124125126
*/ public static Pipe newPipe(InputStream in, boolean numeric) throws IOException { final IOContext context = new IOContext(DEFAULT_JSON_FACTORY._getBufferRecycler(), in, false); final JsonParser parser = newJsonParser(in, context.allocReadIOBuffer(), 0, 0, true, context); return newPipe(parser, numeric); }
269270271272273274275276277278279
public static <T> void mergeFrom(InputStream in, T message, Schema<T> schema, boolean numeric) throws IOException { final IOContext context = new IOContext(DEFAULT_JSON_FACTORY._getBufferRecycler(), in, false); final JsonParser parser = newJsonParser(in, context.allocReadIOBuffer(), 0, 0, true, context); //final JsonParser parser = DEFAULT_JSON_FACTORY.createJsonParser(in); try { mergeFrom(parser, message, schema, numeric);
574575576577578579580581582583584
public static <T> List<T> parseListFrom(InputStream in, Schema<T> schema, boolean numeric) throws IOException { final IOContext context = new IOContext(DEFAULT_JSON_FACTORY._getBufferRecycler(), in, false); final JsonParser parser = newJsonParser(in, context.allocReadIOBuffer(), 0, 0, true, context); //final JsonParser parser = DEFAULT_JSON_FACTORY.createJsonParser(in); try { return parseListFrom(parser, schema, numeric);
199200201202203204205206207208209
/* This may be unfair advantage (allocating buffer of exact * size)? But let's do that for now */ //char[] cbuf = new char[mData.length]; //InputStreamReader r = new InputStreamReader(bin, "UTF-8"); byte[] bbuf = ctxt.allocReadIOBuffer(); /* 13-Jan-2009, tatu: Note: Noggit doesn't use our turbo-charged * UTF8 codec by default. But let's make it as fast as we * possibly can... */ UTF8Reader r = new UTF8Reader(ctxt, bin, bbuf, 0, 0);