Example #1
0
    @Override
    public InputStream readAt(final int offset) {
      mBuffer.position(offset);
      return new InputStream() {
        private int mPos = offset;

        @Override
        public int read() throws IOException {
          mBuffer.position(mPos);
          if (!mBuffer.isPositionHasData()) {
            return -1;
          }
          mPos++;
          return mBuffer.get() & 0xff;
        }

        @Override
        public int read(byte[] bytes, int off, int len) throws IOException {
          mBuffer.position(mPos);
          if (mBuffer.remaining() == 0 || !mBuffer.isPositionHasData()) {
            return -1;
          }
          len = Math.min(len, mBuffer.remaining());
          mPos += len;
          mBuffer.get(bytes, off, len);
          return len;
        }
      };
    }
 public long getLength() {
   long length = sb.toString().getBytes().length;
   length += trailer.length();
   for (ByteData byteData : dataList) length += byteData.getSize();
   return length;
 }
 public void write(OutputStream out) throws IOException {
   out.write(sb.toString().getBytes());
   for (ByteData byteData : dataList) byteData.write(out);
   out.write(trailer.getBytes());
 }