@Override public EncodableHistogram read() throws DataFormatException { // prevent double calls to this method if (gotIt) { throw new IllegalStateException(); } gotIt = true; final String compressedPayloadString = scanner.next(); final ByteBuffer buffer = ByteBuffer.wrap(Base64Helper.parseBase64Binary(compressedPayloadString)); EncodableHistogram histogram = EncodableHistogram.decodeFromCompressedByteBuffer(buffer, 0); return histogram; } }
@Override public Histogram deserialize(String serialized) { try { byte[] rawBytes = DatatypeConverter.parseBase64Binary(serialized); final ByteBuffer buffer = ByteBuffer.wrap(rawBytes, 0, rawBytes.length - (2 * Long.BYTES)); Histogram histogram = (Histogram) EncodableHistogram.decodeFromCompressedByteBuffer(buffer, 0); final ByteBuffer timestamps = ByteBuffer.wrap(rawBytes, 0, rawBytes.length); histogram.setStartTimeStamp(timestamps.getLong(rawBytes.length - (2 * Long.BYTES))); histogram.setEndTimeStamp(timestamps.getLong(rawBytes.length - (2 * Long.BYTES) + Long.BYTES)); return histogram; } catch (DataFormatException e) { throw new RuntimeException(e); } }
@Override public EncodableHistogram read() throws DataFormatException { // prevent double calls to this method if (gotIt) throw new IllegalStateException(); gotIt = true; final String compressedPayloadString = scanner.next(); final ByteBuffer buffer = ByteBuffer.wrap(Base64Helper.parseBase64Binary(compressedPayloadString)); EncodableHistogram histogram = EncodableHistogram.decodeFromCompressedByteBuffer(buffer, 0); return histogram; } }