private QuantileBuffer<T> decodeBuffer(InputStream inStream) throws IOException, CoderException { DataInputStream inData = new DataInputStream(inStream); return new QuantileBuffer<>( inData.readInt(), inData.readLong(), elementListCoder.decode(inStream)); }
@Override public InputOrAccum<InputT, AccumT> decode(InputStream inStream, Coder.Context context) throws CoderException, IOException { if (inStream.read() == 0) { return InputOrAccum.input(inputCoder.decode(inStream, context)); } else { return InputOrAccum.accum(accumCoder.decode(inStream, context)); } }
@Override public WindowedValue<T> decode(InputStream inStream, Context context) throws CoderException, IOException { T value = valueCoder.decode(inStream, context); return WindowedValue.valueInGlobalWindow(value); }
@Override public final X decode(InputStream inStream) throws CoderException, IOException { return from(delegate.decode(inStream)); }
@Override public ApexStreamTuple<T> decode(InputStream inStream, Context context) throws CoderException, IOException { int b = inStream.read(); if (b == 1) { return new WatermarkTuple<>(new DataInputStream(inStream).readLong()); } else { int unionTag = inStream.read(); return new DataTuple<>(valueCoder.decode(inStream, context), unionTag); } }
private T deserialize() { T val; try { val = coder.decode(new ByteArrayInputStream(bcast.value()), new Coder.Context(true)); } catch (IOException ioe) { // this should not ever happen, log it if it does. LOG.warn(ioe.getMessage()); val = null; } return val; } }
@Override public K decode(InputStream inStream) throws CoderException, IOException { int marker = inStream.read(); if (marker == 0) { return (K) getMetadataKey(); } else if (marker == 1) { return keyCoder.decode(inStream); } else { throw new CoderException(String.format("Expected marker but got %s.", marker)); } }
@Override public RawUnionValue decode(InputStream inStream, Context context) throws IOException, CoderException { int index = VarInt.decodeInt(inStream); Object value = elementCoders.get(index).decode(inStream, context); return new RawUnionValue(index, value); }
@Override public Params decode(InputStream inStream) throws IOException { ResourceId prefix = FileBasedSink.convertToFileResourceIfPossible(stringCoder.decode(inStream)); String shardTemplate = stringCoder.decode(inStream); String suffix = stringCoder.decode(inStream); return new Params() .withBaseFilename(prefix) .withShardTemplate(shardTemplate) .withSuffix(suffix); } }
@Override public IsmRecord<V> decode(InputStream inStream) throws CoderException, IOException { List<Object> keyComponents = new ArrayList<>(keyComponentCoders.size()); for (Coder<?> keyCoder : keyComponentCoders) { keyComponents.add(keyCoder.decode(inStream)); } if (isMetadataKey(keyComponents)) { return IsmRecord.meta(keyComponents, ByteArrayCoder.of().decode(inStream)); } else { return IsmRecord.of(keyComponents, valueCoder.decode(inStream)); } }
@Override public ValueWithRecordId<ValueT> decode(InputStream inStream, Context context) throws IOException { return new ValueWithRecordId<>( valueCoder.decode(inStream), idCoder.decode(inStream, context)); }
@Override public SingletonKeyedWorkItem<K, ElemT> decode(InputStream inStream, Context context) throws CoderException, IOException { K key = keyCoder.decode(inStream); WindowedValue<ElemT> value = valueCoder.decode(inStream, context); return new SingletonKeyedWorkItem<>(key, value); }
@Override public ValueInSingleWindow<T> decode(InputStream inStream, Context context) throws IOException { Instant timestamp = InstantCoder.of().decode(inStream); BoundedWindow window = windowCoder.decode(inStream); PaneInfo pane = PaneInfo.PaneInfoCoder.INSTANCE.decode(inStream); T value = valueCoder.decode(inStream, context); return new AutoValue_ValueInSingleWindow<>(value, timestamp, window, pane); }
@Override public Iterable<V> get(byte[] keyBytes, W window) { K key; try { // TODO: We could skip decoding and just compare encoded values for deterministic keyCoders. key = keyCoder.decode(new ByteArrayInputStream(keyBytes)); } catch (IOException e) { throw new RuntimeException(e); } return collection.get( SideInputKey.of(keyCoder.structuralValue(key), windowCoder.structuralValue(window))); }
@Override public Iterable<V> get(byte[] keyBytes, W window) { K key; try { // TODO: We could skip decoding and just compare encoded values for deterministic keyCoders. key = keyCoder.decode(new ByteArrayInputStream(keyBytes)); } catch (IOException e) { throw new RuntimeException(e); } return collection.get( SideInputKey.of(keyCoder.structuralValue(key), windowCoder.structuralValue(window))); }
@Override public UnserializableRecord decode(InputStream inStream) throws CoderException, IOException { return new UnserializableRecord(stringCoder.decode(inStream)); } }
@Test public void testDecodingError() throws Exception { thrown.expect(CoderException.class); thrown.expectMessage( equalTo("NullableCoder expects either a byte valued 0 (null) " + "or 1 (present), got 5")); InputStream input = new ByteArrayInputStream(new byte[] {5}); TEST_CODER.decode(input, Coder.Context.OUTER); }
@Override public CustomWindow decode(InputStream inStream) throws IOException { IntervalWindow superWindow = INTERVAL_WINDOW_CODER.decode(inStream); boolean isBig = VAR_INT_CODER.decode(inStream) != 0; return new CustomWindow(superWindow.start(), superWindow.end(), isBig); }