@NotNull @Override public CharSequence read(Bytes bytes, @Nullable CharSequence ignored) { long size = bytes.readStopBit(); if (size == NULL_LENGTH) return null; if (size < 0 || size > Integer.MAX_VALUE) throw new IllegalStateException("Invalid length: " + size); if (size == 0) return ""; char[] chars = new char[(int) size]; int length = bytes.readInt(); long limit = bytes.readLimit(); try { bytes.readLimit(bytes.readPosition() + length); DataInputStream dis = new DataInputStream( new BufferedInputStream(new InflaterInputStream(bytes.inputStream()))); for (int i = 0; i < size; i++) chars[i] = (char) (dis.readByte() & 0xff); } catch (IOException e) { throw new IORuntimeException(e); } finally { bytes.readPosition(bytes.readLimit()); bytes.readLimit(limit); } try { return STRING_FACTORY.fromChars(chars); } catch (Exception e) { throw new AssertionError(e); } }
public static void rawReadData(@NotNull WireIn wireIn, @NotNull ReadMarshallable dataConsumer) { final Bytes<?> bytes = wireIn.bytes(); int header = bytes.readInt(); assert Wires.isReady(header) && Wires.isData(header); final int len = Wires.lengthOf(header); long limit0 = bytes.readLimit(); long limit = bytes.readPosition() + (long) len; try { bytes.readLimit(limit); dataConsumer.readMarshallable(wireIn); } finally { bytes.readLimit(limit0); } }
@NotNull @Override public Integer read(Bytes in, @Nullable Integer using) { return in.readInt(); }