Code example for Buffer

Methods: limitremainingrewind

0
    if (off < 0 || len < 0 || off > b.length - len) {
      throw new ArrayIndexOutOfBoundsException();
    } 
     
    // Check if there is compressed data. 
    int n = compressedDirectBuf.remaining();
    if (n > 0) {
      n = Math.min(n, len);
      ((ByteBuffer)compressedDirectBuf).get(b, off, n);
      return n;
    } 
 
    // Re-initialize bzip2's output direct buffer. 
    compressedDirectBuf.rewind();
    compressedDirectBuf.limit(directBufferSize);
 
    // Compress the data. 
    n = deflateBytesDirect();
    compressedDirectBuf.limit(n);
     
    // Check if bzip2 has consumed the entire input buffer. 
    // Set keepUncompressedBuf properly. 
    if (uncompressedDirectBufLen <= 0) { // bzip2 consumed all input
      keepUncompressedBuf = false;