@Override public void encode(long[] value, OutputStream outStream) throws IOException { VarInt.encode(value[0], outStream); }
private static void writeString(String value, OutputStream dos) throws IOException { byte[] bytes = value.getBytes(StandardCharsets.UTF_8); VarInt.encode(bytes.length, dos); dos.write(bytes); }
private void encode(Message value, OutputStream outStream, int messageSize) throws IOException, BufferOverflowException { byte[] data = new byte[messageSize]; int bytesWritten = value.encode(data, 0, data.length); VarInt.encode(bytesWritten, outStream); outStream.write(data, 0, bytesWritten); }
@Override public void encode(Integer value, OutputStream outStream) throws IOException, CoderException { if (value == null) { throw new CoderException("cannot encode a null Integer"); } VarInt.encode(value, outStream); }
@Override public void encode(Integer value, OutputStream outStream) throws IOException { VarInt.encode(value, outStream); } }
@Override public void encode(byte[] value, OutputStream outStream, Context context) throws IOException, CoderException { if (value == null) { throw new CoderException("cannot encode a null byte[]"); } if (!context.isWholeStream) { VarInt.encode(value.length, outStream); outStream.write(value); } else { outStream.write(value); } }
@Override public void encode(Long value, OutputStream outStream) throws IOException, CoderException { if (value == null) { throw new CoderException("cannot encode a null Long"); } VarInt.encode(value, outStream); }
@Override public void encode(T value, OutputStream outStream) throws CoderException, IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); valueCoder.encode(value, bos, Context.OUTER); VarInt.encode(bos.size(), outStream); bos.writeTo(outStream); }
/** Encodes the given value onto the stream. */ public static void encode(int v, OutputStream stream) throws IOException { encode(convertIntToLongNoSignExtend(v), stream); }
@Override public void encode(TestCheckpointMark value, OutputStream outStream) throws IOException { VarInt.encode(value.index, outStream); }
@Override public void encode(RandomAccessData value, OutputStream outStream, Coder.Context context) throws CoderException, IOException { if (Objects.equals(value, POSITIVE_INFINITY)) { throw new CoderException("Positive infinity can not be encoded."); } if (!context.isWholeStream) { VarInt.encode(value.size, outStream); } value.writeTo(outStream, 0, value.size); }
@Override public void encode(T value, OutputStream outStream) throws IOException { if (value == null) { throw new CoderException("cannot encode a null SolrDocument"); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); JavaBinCodec codec = new JavaBinCodec(); codec.marshal(value, baos); byte[] bytes = baos.toByteArray(); VarInt.encode(bytes.length, outStream); outStream.write(bytes); }
private static byte[] encodeInt(int v) throws IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(); VarInt.encode(v, stream); return stream.toByteArray(); }
private static byte[] encodeLong(long v) throws IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(); VarInt.encode(v, stream); return stream.toByteArray(); }
/** Finishes the encoding by flushing any buffered data, and outputting a final count of 0. */ public void finish() throws IOException { if (finished) { return; } flush(); // Finish the stream by stating that there are 0 elements that follow. VarInt.encode(0, os); if (!BUFFER_POOL.offer(buffer)) { // The pool is full, we can't store the buffer. We just drop the buffer. } finished = true; }
@SuppressWarnings("unchecked") @Override public void encode(RawUnionValue union, OutputStream outStream, Context context) throws IOException, CoderException { int index = getIndexForEncoding(union); // Write out the union tag. VarInt.encode(index, outStream); // Write out the actual value. Coder<Object> coder = (Coder<Object>) elementCoders.get(index); coder.encode(union.getValue(), outStream, context); }
@Override public void encode(MultiStepAccumulator value, OutputStream outStream) throws CoderException, IOException { VarInt.encode(value.getValue(), outStream); }
@Override public void encode(ByteString value, OutputStream outStream, Context context) throws IOException, CoderException { if (value == null) { throw new CoderException("cannot encode a null ByteString"); } if (!context.isWholeStream) { // ByteString is not delimited, so write its size before its contents. VarInt.encode(value.size(), outStream); } value.writeTo(outStream); }
@Override public void encode(BoundedWindow value, OutputStream outStream) throws IOException { VarInt.encode(value.maxTimestamp().getMillis(), outStream); }