@Override public JsonParser createParser(ObjectReadContext readCtxt, String content) throws IOException { final int strLen = content.length(); // Actually, let's use this for medium-sized content, up to 64kB chunk (32kb char) if ((_inputDecorator != null) || (strLen > 0x8000) || !canUseCharArrays()) { // easier to just wrap in a Reader than extend InputDecorator; or, if content // is too long for us to copy it over return createParser(readCtxt, new StringReader(content)); } IOContext ioCtxt = _createContext(content, true); char[] buf = ioCtxt.allocTokenBuffer(strLen); content.getChars(0, strLen, buf, 0); return _createParser(readCtxt, ioCtxt, buf, 0, strLen, true); }
public UTF8StreamJsonParser(ObjectReadContext readCtxt, IOContext ctxt, int features, InputStream in, ByteQuadsCanonicalizer sym, byte[] inputBuffer, int start, int end, boolean bufferRecyclable) { super(readCtxt, ctxt, features); _inputStream = in; _symbols = sym; _inputBuffer = inputBuffer; _inputPtr = start; _inputEnd = end; _currInputRowStart = start; // If we have offset, need to omit that from byte offset, so: _currInputProcessed = -start; _bufferRecyclable = bufferRecyclable; }
public JsonGeneratorImpl(ObjectWriteContext writeCtxt, IOContext ctxt, int features, SerializableString rvs, CharacterEscapes charEsc, PrettyPrinter pp) { super(writeCtxt, features); _ioContext = ctxt; if (Feature.ESCAPE_NON_ASCII.enabledIn(features)) { // inlined `setHighestNonEscapedChar()` _maximumNonEscapedChar = 127; } _cfgUnqNames = !Feature.QUOTE_FIELD_NAMES.enabledIn(features); _rootValueSeparator = rvs; _cfgPrettyPrinter = pp; // 03-Oct-2017, tatu: Not clean (shouldn't call non-static methods from ctor), // but for now best way to avoid code duplication setCharacterEscapes(charEsc); }
public UTF8JsonGenerator(ObjectWriteContext writeCtxt, IOContext ioCtxt, int features, OutputStream out, SerializableString rootValueSep, CharacterEscapes charEsc, PrettyPrinter pp) { super(writeCtxt, ioCtxt, features, rootValueSep, charEsc, pp); _outputStream = out; _bufferRecyclable = true; _outputBuffer = ioCtxt.allocWriteEncodingBuffer(); _outputEnd = _outputBuffer.length; // To be exact, each char can take up to 6 bytes when escaped (Unicode // escape with backslash, 'u' and 4 hex digits); but to avoid fluctuation, // we will actually round down to only do up to 1/8 number of chars _outputMaxContiguous = _outputEnd >> 3; _charBuffer = ioCtxt.allocConcatBuffer(); _charBufferLength = _charBuffer.length; // By default we use this feature to determine additional quoting if (isEnabled(Feature.ESCAPE_NON_ASCII)) { setHighestNonEscapedChar(127); } }
public UTF8JsonGenerator(ObjectWriteContext writeCtxt, IOContext ioCtxt, int features, OutputStream out, SerializableString rootValueSep, CharacterEscapes charEsc, PrettyPrinter pp, byte[] outputBuffer, int outputOffset, boolean bufferRecyclable) { super(writeCtxt, ioCtxt, features, rootValueSep, charEsc, pp); _outputStream = out; _bufferRecyclable = bufferRecyclable; _outputTail = outputOffset; _outputBuffer = outputBuffer; _outputEnd = _outputBuffer.length; // up to 6 bytes per char (see above), rounded up to 1/8 _outputMaxContiguous = (_outputEnd >> 3); _charBuffer = ioCtxt.allocConcatBuffer(); _charBufferLength = _charBuffer.length; }
/** * Method called when caller wants to provide input buffer directly, * and it may or may not be recyclable use standard recycle context. */ public ReaderBasedJsonParser(ObjectReadContext readCtxt, IOContext ctxt, int features, Reader r, CharsToNameCanonicalizer st, char[] inputBuffer, int start, int end, boolean bufferRecyclable) { super(readCtxt, ctxt, features); _reader = r; _inputBuffer = inputBuffer; _inputPtr = start; _inputEnd = end; _symbols = st; _hashSeed = st.hashSeed(); _bufferRecyclable = bufferRecyclable; }
@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()); } }
@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()); } }
@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()); } }
@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()); } }
@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()); } }
@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()); } }
@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()); } }
@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()); } }
@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()); } }
@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()); }
@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()); } }
@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()); } }
@Test public void testClose() throws IOException { IOContext ioContext = new IOContext(new BufferRecycler(), this, true); ReaderBasedJsonParser readerBasedJsonParser = new ReaderBasedJsonParser( ObjectReadContext.empty(), ioContext, 2, null, CharsToNameCanonicalizer.createRoot()); JsonParserSequence jsonParserSequence = JsonParserSequence.createFlattened(true, readerBasedJsonParser, readerBasedJsonParser); assertFalse(jsonParserSequence.isClosed()); jsonParserSequence.close(); assertTrue(jsonParserSequence.isClosed()); assertNull(jsonParserSequence.nextToken()); }
@Test public void testSkipChildren() throws IOException { JsonParser[] jsonParserArray = new JsonParser[3]; IOContext ioContext = new IOContext(new BufferRecycler(), jsonParserArray, true); byte[] byteArray = new byte[8]; InputStream byteArrayInputStream = new ByteArrayInputStream(byteArray, 0, (byte) 58); UTF8StreamJsonParser uTF8StreamJsonParser = new UTF8StreamJsonParser(ObjectReadContext.empty(), ioContext, 0, byteArrayInputStream, ByteQuadsCanonicalizer.createRoot(), byteArray, -1, (byte) 9, true); JsonParserDelegate jsonParserDelegate = new JsonParserDelegate(jsonParserArray[0]); JsonParserSequence jsonParserSequence = JsonParserSequence.createFlattened(true, uTF8StreamJsonParser, jsonParserDelegate); JsonParserSequence jsonParserSequenceTwo = (JsonParserSequence) jsonParserSequence.skipChildren(); assertEquals(2, jsonParserSequenceTwo.containedParsersCount()); }
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); }
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(); }
/** * 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."); } }
@Override protected HoconTreeTraversingParser _createParser( Reader r, IOContext ctxt ) throws IOException { ConfigParseOptions options = ConfigParseOptions.defaults(); Config config = ConfigFactory.parseReader( r, options ); final Config unresolvedConfig = additinal .withFallback( config ) .withFallback( ConfigFactory.systemProperties() ); // log.trace( unresolvedConfig.root().render() ); try { Config resolvedConfig = unresolvedConfig.resolve(); return new HoconTreeTraversingParser( resolvedConfig.root(), _objectCodec ); } catch( ConfigException e ) { log.error( unresolvedConfig.root().render() ); throw e; } }
/** * Merges the {@code message} from the {@link InputStream} using the given {@code schema}. */ 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 { JsonIOUtil.mergeFrom(parser, message, schema, numeric); } finally { parser.close(); } }
/** * Parses the {@code messages} from the stream using the given {@code schema}. */ 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); } finally { parser.close(); } }
/** * Serializes the {@code messages} into the stream using the given schema. */ public static <T> void writeListTo(OutputStream out, List<T> messages, Schema<T> schema, boolean numeric) throws IOException { final IOContext context = new IOContext(DEFAULT_JSON_FACTORY._getBufferRecycler(), out, false); final JsonGenerator generator = newJsonGenerator(out, context.allocWriteEncodingBuffer(), 0, true, context); /* * final JsonGenerator generator = DEFAULT_JSON_FACTORY.createJsonGenerator(out, JsonEncoding.UTF8); */ try { writeListTo(generator, messages, schema, numeric); } finally { generator.close(); } }
/** * Parses the {@code messages} from the stream using the given {@code schema}. * <p> * The {@link LinkedBuffer}'s internal byte array will be used when reading the message. */ public static <T> List<T> parseListFrom(InputStream in, Schema<T> schema, boolean numeric, LinkedBuffer buffer) throws IOException { final IOContext context = new IOContext(DEFAULT_JSON_FACTORY._getBufferRecycler(), in, false); final JsonParser parser = newJsonParser(in, buffer.buffer, 0, 0, false, context); try { return parseListFrom(parser, schema, numeric); } finally { parser.close(); } }
public JsonGenerator createGenerator(File paramFile, JsonEncoding paramJsonEncoding) { Object localObject = new FileOutputStream(paramFile); IOContext localIOContext = _createContext(localObject, true); localIOContext.setEncoding(paramJsonEncoding); if (paramJsonEncoding == JsonEncoding.UTF8) { if (this._outputDecorator != null) localObject = this._outputDecorator.decorate(localIOContext, (OutputStream)localObject); return _createUTF8Generator((OutputStream)localObject, localIOContext); } Writer localWriter = _createWriter((OutputStream)localObject, paramJsonEncoding, localIOContext); if (this._outputDecorator != null) localWriter = this._outputDecorator.decorate(localIOContext, localWriter); return _createGenerator(localWriter, localIOContext); }
/** * Parses the {@code messages} from the stream using the given {@code schema}. */ 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 { return JsonIOUtil.parseListFrom(parser, schema, numeric); } finally { parser.close(); } }
/** * Serializes the {@code messages} into the stream using the given schema. */ public static <T> void writeListTo(OutputStream out, List<T> messages, Schema<T> schema, boolean numeric) throws IOException { final IOContext context = new IOContext(DEFAULT_SMILE_FACTORY._getBufferRecycler(), out, false); final SmileGenerator generator = newSmileGenerator(out, context.allocWriteEncodingBuffer(), 0, true, context); // final SmileGenerator generator = DEFAULT_SMILE_FACTORY.createJsonGenerator(out); try { JsonIOUtil.writeListTo(generator, messages, schema, numeric); } finally { generator.close(); } }
/** * Merges the {@code message} from the {@link InputStream} using the given {@code schema}. * <p> * The {@link LinkedBuffer}'s internal byte array will be used when reading the message. */ public static <T> void mergeFrom(InputStream in, T message, Schema<T> schema, boolean numeric, LinkedBuffer buffer) throws IOException { final IOContext context = new IOContext(DEFAULT_SMILE_FACTORY._getBufferRecycler(), in, false); final SmileParser parser = newSmileParser(in, buffer.buffer, 0, 0, false, context); // final SmileParser parser = DEFAULT_SMILE_FACTORY.createJsonParser(in); try { JsonIOUtil.mergeFrom(parser, message, schema, numeric); } finally { parser.close(); } }
/** * Merges the {@code message} from the {@link InputStream} using the given {@code schema}. */ 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); } finally { parser.close(); } }
/** * Parses the {@code messages} from the stream using the given {@code schema}. * <p> * The {@link LinkedBuffer}'s internal byte array will be used when reading the message. */ public static <T> List<T> parseListFrom(InputStream in, Schema<T> schema, boolean numeric, LinkedBuffer buffer) throws IOException { final IOContext context = new IOContext(DEFAULT_SMILE_FACTORY._getBufferRecycler(), in, false); final SmileParser parser = newSmileParser(in, buffer.buffer, 0, 0, false, context); // final SmileParser parser = DEFAULT_SMILE_FACTORY.createJsonParser(in); try { return JsonIOUtil.parseListFrom(parser, schema, numeric); } finally { parser.close(); } }
/** * Merges the {@code message} with the byte array using the given {@code schema}. */ public static <T> void mergeFrom(byte[] data, int offset, int length, T message, Schema<T> schema, boolean numeric) throws IOException { final IOContext context = new IOContext(DEFAULT_JSON_FACTORY._getBufferRecycler(), data, false); final JsonParser parser = newJsonParser(null, data, offset, offset + length, false, context); /* * final JsonParser parser = DEFAULT_JSON_FACTORY.createJsonParser(data, offset, length); */ try { mergeFrom(parser, message, schema, numeric); } finally { parser.close(); } }
protected SmileGenerator _createGenerator(OutputStream out, IOContext ctxt) throws IOException { int feats = _smileGeneratorFeatures; /* One sanity check: MUST write header if shared string values setting is enabled, * or quoting of binary data disabled. * But should we force writing, or throw exception, if settings are in conflict? * For now, let's error out... */ SmileGenerator gen = new SmileGenerator(ctxt, _generatorFeatures, feats, _objectCodec, out); if ((feats & SmileGenerator.Feature.WRITE_HEADER.getMask()) != 0) { gen.writeHeader(); } else { if ((feats & SmileGenerator.Feature.CHECK_SHARED_STRING_VALUES.getMask()) != 0) { throw new JsonGenerationException( "Inconsistent settings: WRITE_HEADER disabled, but CHECK_SHARED_STRING_VALUES enabled; can not construct generator" +" due to possible data loss (either enable WRITE_HEADER, or disable CHECK_SHARED_STRING_VALUES to resolve)"); } if ((feats & SmileGenerator.Feature.ENCODE_BINARY_AS_7BIT.getMask()) == 0) { throw new JsonGenerationException( "Inconsistent settings: WRITE_HEADER disabled, but ENCODE_BINARY_AS_7BIT disabled; can not construct generator" +" due to possible data loss (either enable WRITE_HEADER, or ENCODE_BINARY_AS_7BIT to resolve)"); } } return gen; }
public NonBlockingParserImpl(IOContext ctxt, int parserFeatures, int smileFeatures, ObjectCodec codec, BytesToNameCanonicalizer sym) { super(ctxt, parserFeatures); _objectCodec = codec; _symbols = sym; _tokenInputRow = -1; _tokenInputCol = -1; _smileBufferRecycler = _smileBufferRecycler(); _currToken = JsonToken.NOT_AVAILABLE; _state = STATE_INITIAL; _tokenIncomplete = true; _cfgRequireHeader = (smileFeatures & SmileParser.Feature.REQUIRE_HEADER.getMask()) != 0; }
/** * Serializes the {@code message} into an {@link OutputStream} using the given {@code schema}. */ public static <T> void writeTo(OutputStream out, T message, Schema<T> schema, boolean numeric) throws IOException { final IOContext context = new IOContext(DEFAULT_JSON_FACTORY._getBufferRecycler(), out, false); final JsonGenerator generator = newJsonGenerator(out, context.allocWriteEncodingBuffer(), 0, true, context); /* * final JsonGenerator generator = DEFAULT_JSON_FACTORY.createJsonGenerator(out, JsonEncoding.UTF8); */ try { writeTo(generator, message, schema, numeric); } finally { generator.close(); } }
public UTF8StreamJsonParser(IOContext ctxt, int features, InputStream in, ObjectCodec codec, BytesToNameCanonicalizer sym, byte[] inputBuffer, int start, int end, boolean bufferRecyclable) { super(ctxt, features); _inputStream = in; _objectCodec = codec; _symbols = sym; _inputBuffer = inputBuffer; _inputPtr = start; _inputEnd = end; _currInputRowStart = start; // If we have offset, need to omit that from byte offset, so: _currInputProcessed = -start; _bufferRecyclable = bufferRecyclable; }
/** * Merges the {@code message} with the byte array using the given {@code schema}. */ public static <T> void mergeFrom(byte[] data, int offset, int length, T message, Schema<T> schema, boolean numeric) throws IOException { final IOContext context = new IOContext(DEFAULT_SMILE_FACTORY._getBufferRecycler(), data, false); final SmileParser parser = newSmileParser(null, data, offset, offset + length, false, context); // final SmileParser parser = DEFAULT_SMILE_FACTORY.createJsonParser(data, offset, length); try { JsonIOUtil.mergeFrom(parser, message, schema, numeric); } finally { parser.close(); } }