@SuppressWarnings("resource") static ByteBuffer serializeRoaring(ImmutableRoaringBitmap mrb) throws IOException { byte[] backingArray = new byte[mrb.serializedSizeInBytes() + 1024]; ByteBuffer outbb = ByteBuffer.wrap(backingArray, 1024, mrb.serializedSizeInBytes()).slice(); DataOutputStream dos = new DataOutputStream( new OutputStream() { ByteBuffer mBB; OutputStream init(ByteBuffer mbb) { mBB = mbb; return this; } @Override public void write(byte[] b) {} @Override public void write(byte[] b, int off, int l) { mBB.put(b, off, l); } @Override public void write(int b) { mBB.put((byte) b); } }.init(outbb)); mrb.serialize(dos); dos.close(); return outbb; }