/** * Creates a {@link ResolvingDecoder} wrapping the Decoder provided. This * ResolvingDecoder will resolve input conforming to the <i>writer</i> schema * from the wrapped Decoder, and present it as the <i>reader</i> schema. * * @param writer * The Schema that the source data is in. Cannot be null. * @param reader * The Schema that the reader wishes to read the data as. Cannot be * null. * @param wrapped * The Decoder to wrap. * @return A ResolvingDecoder configured to resolve <i>writer</i> to * <i>reader</i> from <i>in</i> * @throws IOException */ public ResolvingDecoder resolvingDecoder(Schema writer, Schema reader, Decoder wrapped) throws IOException { return new ResolvingDecoder(writer, reader, wrapped); }
/** * Creates a {@link ResolvingDecoder} wrapping the Decoder provided. This * ResolvingDecoder will resolve input conforming to the <i>writer</i> schema * from the wrapped Decoder, and present it as the <i>reader</i> schema. * * @param writer * The Schema that the source data is in. Cannot be null. * @param reader * The Schema that the reader wishes to read the data as. Cannot be * null. * @param wrapped * The Decoder to wrap. * @return A ResolvingDecoder configured to resolve <i>writer</i> to * <i>reader</i> from <i>in</i> * @throws IOException */ public ResolvingDecoder resolvingDecoder(Schema writer, Schema reader, Decoder wrapped) throws IOException { return new ResolvingDecoder(writer, reader, wrapped); }
@Override protected Decoder getDecoder() throws IOException { return new ResolvingDecoder(schema, schema, super.getDecoder()); } }
@Override protected Decoder getDecoder() throws IOException { return new ResolvingDecoder(schema, readerSchema, super.getDecoder()); } @Override
@Override protected Decoder getDecoder() throws IOException { return new ResolvingDecoder(schema, readerSchema, super.getDecoder()); } @Override
@Override protected Decoder getDecoder() throws IOException { return new ResolvingDecoder(schema, readerSchema, super.getDecoder()); } @Override
@Override protected Decoder getDecoder() throws IOException { return new ResolvingDecoder(writeSchema, schema, super.getDecoder()); }
static void check(Schema wsc, Schema rsc, byte[] bytes, String calls, Object[] values, Encoding encoding, int skipLevel) throws IOException { // TestValidatingIO.dump(bytes); // System.out.println(new String(bytes, "UTF-8")); Decoder bvi = null; switch (encoding) { case BINARY: case BLOCKING_BINARY: bvi = DecoderFactory.get().binaryDecoder(bytes, null); break; case JSON: InputStream in = new ByteArrayInputStream(bytes); bvi = new JsonDecoder(wsc, in); break; } Decoder vi = new ResolvingDecoder(wsc, rsc, bvi); TestValidatingIO.check(vi, calls, values, skipLevel); }
/** * Creates a {@link ResolvingDecoder} wrapping the Decoder provided. This * ResolvingDecoder will resolve input conforming to the <i>writer</i> schema * from the wrapped Decoder, and present it as the <i>reader</i> schema. * * @param writer * The Schema that the source data is in. Cannot be null. * @param reader * The Schema that the reader wishes to read the data as. Cannot be * null. * @param wrapped * The Decoder to wrap. * @return A ResolvingDecoder configured to resolve <i>writer</i> to * <i>reader</i> from <i>in</i> * @throws IOException */ public ResolvingDecoder resolvingDecoder(Schema writer, Schema reader, Decoder wrapped) throws IOException { return new ResolvingDecoder(writer, reader, wrapped); }
/** * Creates a {@link ResolvingDecoder} wrapping the Decoder provided. This * ResolvingDecoder will resolve input conforming to the <i>writer</i> schema * from the wrapped Decoder, and present it as the <i>reader</i> schema. * * @param writer * The Schema that the source data is in. Cannot be null. * @param reader * The Schema that the reader wishes to read the data as. Cannot be * null. * @param wrapped * The Decoder to wrap. * @return A ResolvingDecoder configured to resolve <i>writer</i> to * <i>reader</i> from <i>in</i> * @throws IOException */ public ResolvingDecoder resolvingDecoder(Schema writer, Schema reader, Decoder wrapped) throws IOException { return new ResolvingDecoder(writer, reader, wrapped); }
private ResolvingDecoder getResolver(Schema actual, Schema expected) throws IOException { ResolvingDecoder resolver = threadResolver.get(); if (resolver != null) return resolver; Map<Schema,ResolvingDecoder> cache = RESOLVER_CACHE.get().get(actual); if (cache == null) { cache = new WeakIdentityHashMap<Schema,ResolvingDecoder>(); RESOLVER_CACHE.get().put(actual, cache); } resolver = cache.get(expected); if (resolver == null) { resolver = new ResolvingDecoder(Schema.applyAliases(actual, expected), expected, null); cache.put(expected, resolver); } threadResolver.set(resolver); return resolver; }
@Override public GenericRecord deserialize(byte[] bytes) throws SerializationException { if (bytes == null) { return null; } try { ByteArrayInputStream in = new ByteArrayInputStream(bytes); Decoder decoder = DecoderFactory.defaultFactory().createBinaryDecoder(in, null); ResolvingDecoder resolvingDecoder = new ResolvingDecoder(_resolver, decoder); GenericDatumReader<Record> datumReader = new GenericDatumReader<Record>(_reader); GenericData.Record record = new GenericData.Record(_reader); datumReader.read(record, resolvingDecoder); return record; } catch(Exception e) { throw new SerializationException("Failed to deserialize", e); } }
@SuppressWarnings("unchecked") public D read(D reuse, Decoder in) throws IOException { if (resolver == null) { resolver = ResolvingDecoder.resolve(actual, expected); } ResolvingDecoder r = new ResolvingDecoder(resolver, in); D result = (D) read(reuse, expected, r); r.drain(); return result; }