bundles/org.tukani.xz/src/org/tukaani/xz/LZMA2InputStream.java
public int read(byte[] buf, int off, int len) throws IOException {
        if (off < 0 || len < 0 || off + len < 0 || off + len > buf.length)
            throw new IndexOutOfBoundsException();

        if (len == 0)
            return 0;

        if (in == null)
            throw new XZIOException("Stream closed");

        if (exception != null)
            throw exception;

        if (endReached)
            return -1;

        try {
            int size = 0;

            while (len > 0) {
                if (uncompressedSize == 0) {
                    decodeChunkHeader();
                    if (endReached)
                        return size == 0 ? -1 : size;
                }

                int copySizeMax = Math.min(uncompressedSize, len);

                if (!isLZMAChunk) {
                    lz.copyUncompressed(in, copySizeMax);
                } else {
                    lz.setLimit(copySizeMax);
                    lzma.decode();
                }

                int copiedSize = lz.flush(buf, off);
                off += copiedSize;
                len -= copiedSize;
                size += copiedSize;
                uncompressedSize -= copiedSize;

                if (uncompressedSize == 0)
                    if (!rc.isFinished() || lz.hasPending())
                        throw new CorruptedInputException();
            }

            return size;

        } catch (IOException e) {
            exception = e;
            throw e;
        }
    }
public int read(byte[] buf, int off, int len) throws IOException {
        if (off < 0 || len < 0 || off + len < 0 || off + len > buf.length)
            throw new IndexOutOfBoundsException();

        if (len == 0)
            return 0;

        if (in == null)
            throw new XZIOException("Stream closed");

        if (exception != null)
            throw exception;

        if (endReached)
            return -1;

        try {
            int size = 0;

            while (len > 0) {
                if (uncompressedSize == 0) {
                    decodeChunkHeader();
                    if (endReached)
                        return size == 0 ? -1 : size;
                }

                int copySizeMax = Math.min(uncompressedSize, len);

                if (!isLZMAChunk) {
                    lz.copyUncompressed(in, copySizeMax);
                } else {
                    lz.setLimit(copySizeMax);
                    lzma.decode();
                }

                int copiedSize = lz.flush(buf, off);
                off += copiedSize;
                len -= copiedSize;
                size += copiedSize;
                uncompressedSize -= copiedSize;

                if (uncompressedSize == 0)
                    if (!rc.isFinished() || lz.hasPending())
                        throw new CorruptedInputException();
            }

            return size;

        } catch (IOException e) {
            exception = e;
            throw e;
        }
    }
public int read ( byte [ ] buf , int off , int len ) throws IOException { if ( off < 0 || len < 0 || off + len < 0 || off + len > buf . length ) throw new IndexOutOfBoundsException ( ) ; if ( len == 0 ) return 0 ; if ( in == null ) throw new XZIOException ( "Stream closed" ) ; if ( exception != null ) throw exception ; if ( endReached ) return - 1 ; try { int size = 0 ; while ( len > 0 ) { if ( uncompressedSize == 0 ) { decodeChunkHeader ( ) ; if ( endReached ) return size == 0 ? - 1 : size ; } int copySizeMax = Math . min ( uncompressedSize , len ) ; if ( ! isLZMAChunk ) { lz . copyUncompressed ( in , copySizeMax ) ; } else { lz . setLimit ( copySizeMax ) ; lzma . decode ( ) ; } int copiedSize = lz . flush ( buf , off ) ; off += copiedSize ; len -= copiedSize ; size += copiedSize ; uncompressedSize -= copiedSize ; if ( uncompressedSize == 0 ) if ( ! rc . isFinished ( ) || lz . hasPending ( ) ) throw new CorruptedInputException ( ) ; } return size ; } catch ( IOException e ) { exception = e ; throw e ; } }
Decompresses into an array of bytes.
<p>
If <code>len</code> is zero, no bytes are read and <code>0</code>
is returned. Otherwise this will block until <code>len</code>
bytes have been decompressed, the end of the LZMA2 stream is reached,
or an exception is thrown.

@param       buf         target buffer for uncompressed data
@param       off         start offset in <code>buf</code>
@param       len         maximum number of uncompressed bytes to read

@return      number of bytes read, or <code>-1</code> to indicate
the end of the compressed stream

@throws      CorruptedInputException

@throws      XZIOException if the stream has been closed

@throws      EOFException
compressed input is truncated or corrupt

@throws      IOException may be thrown by <code>in</code>
Decompresses into an array of bytes . <p > If <code > len< / code > is zero no bytes are read and <code > 0< / code > is returned . Otherwise this will block until <code > len< / code > bytes have been decompressed the end of the LZMA2 stream is reached or an exception is thrown .