core/src/main/java/org/apache/commons/vfs2/provider/tar/TarInputStream.java
/**
     * Reads bytes from the current tar archive entry. This method is aware of
     * the boundaries of the current entry in the archive and will deal with
     * them as if they were this stream's start and EOF.
     *
     * @param buffer The buffer into which to place bytes read.
     * @param offset The offset at which to place bytes read.
     * @param count  The number of bytes to read.
     * @return The number of bytes read, or -1 at EOF.
     * @throws IOException when an IO error causes operation to fail
     */
Reads bytes from the current tar archive entry. This method is aware of
the boundaries of the current entry in the archive and will deal with
them as if they were this stream's start and EOF.

@param buffer The buffer into which to place bytes read.
@param offset The offset at which to place bytes read.
@param count  The number of bytes to read.
@return The number of bytes read, or -1 at EOF.
@throws IOException when an IO error causes operation to fail
Reads bytes from the current tar archive entry . This method is aware of the boundaries of the current entry in the archive and will deal with them as if they were this stream ' s start and EOF . @param buffer The buffer into which to place bytes read . @param offset The offset at which to place bytes read . @param count The number of bytes to read . @return The number of bytes read or - 1 at EOF . @throws IOException when an IO error causes operation to fail
@Override
    public int read(final byte[] buffer, final int offset, final int count) throws IOException
    {
        int position = offset;
        int numToRead = count;
        int totalRead = 0;
        if (entryOffset >= entrySize)
        {
            return -1;
        }
        if ((numToRead + entryOffset) > entrySize)
        {
            numToRead = (int) (entrySize - entryOffset);
        }
        if (null != readBuf)
        {
            final int size =
                (numToRead > readBuf.length) ? readBuf.length : numToRead;
            System.arraycopy(readBuf, 0, buffer, position, size);
            if (size >= readBuf.length)
            {
                readBuf = null;
            }
            else
            {
                final int newLength = readBuf.length - size;
                final byte[] newBuffer = new byte[newLength];
                System.arraycopy(readBuf, size, newBuffer, 0, newLength);
                readBuf = newBuffer;
            }
            totalRead += size;
            numToRead -= size;
            position += size;
        }
        while (numToRead > 0)
        {
            final byte[] rec = this.buffer.readRecord();
            if (null == rec)
            {
                final String message =
                    "unexpected EOF with " + numToRead + " bytes unread";
                throw new IOException(message);
            }
            int size = numToRead;
            final int recordLength = rec.length;
            if (recordLength > size)
            {
                System.arraycopy(rec, 0, buffer, position, size);
                readBuf = new byte[recordLength - size];
                System.arraycopy(rec, size, readBuf, 0, recordLength - size);
            }
            else
            {
                size = recordLength;
                System.arraycopy(rec, 0, buffer, position, recordLength);
            }
            totalRead += size;
            numToRead -= size;
            position += size;
        }
        entryOffset += totalRead;
        return totalRead;
    }
@ Override public int read ( final byte [ ] buffer , final int offset , final int count ) throws IOException { int position = offset ; int numToRead = count ; int totalRead = 0 ; if ( entryOffset >= entrySize ) { return - 1 ; } if ( ( numToRead + entryOffset ) > entrySize ) { numToRead = ( int ) ( entrySize - entryOffset ) ; } if ( null != readBuf ) { final int size = ( numToRead > readBuf . length ) ? readBuf . length : numToRead ; System . arraycopy ( readBuf , 0 , buffer , position , size ) ; if ( size >= readBuf . length ) { readBuf = null ; } else { final int newLength = readBuf . length - size ; final byte [ ] newBuffer = new byte [ newLength ] ; System . arraycopy ( readBuf , size , newBuffer , 0 , newLength ) ; readBuf = newBuffer ; } totalRead += size ; numToRead -= size ; position += size ; } while ( numToRead > 0 ) { final byte [ ] rec = this . buffer . readRecord ( ) ; if ( null == rec ) { final String message = "unexpected EOF with " + numToRead + " bytes unread" ; throw new IOException ( message ) ; } int size = numToRead ; final int recordLength = rec . length ; if ( recordLength > size ) { System . arraycopy ( rec , 0 , buffer , position , size ) ; readBuf = new byte [ recordLength - size ] ; System . arraycopy ( rec , size , readBuf , 0 , recordLength - size ) ; } else { size = recordLength ; System . arraycopy ( rec , 0 , buffer , position , recordLength ) ; } totalRead += size ; numToRead -= size ; position += size ; } entryOffset += totalRead ; return totalRead ; }
Reads bytes from the current tar archive entry.
Reads bytes from the current tar archive entry .
// Unexpected EOF!