@Override protected ByteBuffer readBytes(Decoder decoder) throws IOException { return decoder.readBytes(); }
@Override protected ByteBuffer readBytes(Decoder decoder) throws IOException { return decoder.readBytes(); }
/** * Decodes from the given {@link Decoder} to reconstruct a {@link StreamEventData}. * The set of headers provided is used as the default set of headers. * * @param decoder the decoder to read data from * @param defaultHeaders A map of headers available by default. * @return A new instance of {@link co.cask.cdap.api.stream.StreamEventData}. * @throws IOException If there is any IO error during decoding. */ public static StreamEventData decode(Decoder decoder, Map<String, String> defaultHeaders) throws IOException { // Reads the body ByteBuffer body = decoder.readBytes(); // Reads the headers int len = decoder.readInt(); // A special optimization for the case where there is no event header. if (len == 0) { return new StreamEventData(defaultHeaders, body); } Map<String, String> headers = defaultHeaders.isEmpty() ? Maps.<String, String>newHashMap() : Maps.newHashMap(defaultHeaders); do { for (int i = 0; i < len; i++) { String key = decoder.readString(); String value = decoder.readInt() == 0 ? decoder.readString() : (String) decoder.readNull(); headers.put(key, value); } len = decoder.readInt(); } while (len != 0); return new StreamEventData(headers, body); }
return decoder.readDouble(); case BYTES: return decoder.readBytes(); case STRING: return decoder.readString();
return decoder.readDouble(); case BYTES: return decoder.readBytes(); case STRING: return decoder.readString();
buf.asIntBuffer().put(10).put(1024).put(9999999); encoder.writeBytes(buf); IntBuffer inBuf = decoder.readBytes().asIntBuffer(); Assert.assertEquals(10, inBuf.get()); Assert.assertEquals(1024, inBuf.get());