@Override public int read(@NotNull byte[] buf,int offset,int numToRead) throws IOException {
  int totalRead=0;
  if (entryOffset >= entrySize) {
    return -1;
  }
  if ((numToRead + entryOffset) > entrySize) {
    numToRead=(int)(entrySize - entryOffset);
  }
  if (readBuf != null) {
    int sz=(numToRead > readBuf.length) ? readBuf.length : numToRead;
    System.arraycopy(readBuf,0,buf,offset,sz);
    if (sz >= readBuf.length) {
      readBuf=null;
    }
 else {
      int newLen=readBuf.length - sz;
      byte[] newBuf=new byte[newLen];
      System.arraycopy(readBuf,sz,newBuf,0,newLen);
      readBuf=newBuf;
    }
    totalRead+=sz;
    numToRead-=sz;
    offset+=sz;
  }
  while (numToRead > 0) {
    byte[] rec=buffer.readRecord();
    if (rec == null) {
      throw new IOException("unexpected EOF with " + numToRead + " bytes unread");
    }
    int sz=numToRead;
    int recLen=rec.length;
    if (recLen > sz) {
      System.arraycopy(rec,0,buf,offset,sz);
      readBuf=new byte[recLen - sz];
      System.arraycopy(rec,sz,readBuf,0,recLen - sz);
    }
 else {
      sz=recLen;
      System.arraycopy(rec,0,buf,offset,recLen);
    }
    totalRead+=sz;
    numToRead-=sz;
    offset+=sz;
  }
  entryOffset+=totalRead;
  return totalRead;
}

@ Override public int read ( @ NotNull byte [ ] buf , int offset , int numToRead ) throws IOException { int totalRead = 0 ; if ( entryOffset >= entrySize ) { return - 1 ; } if ( ( numToRead + entryOffset ) > entrySize ) { numToRead = ( int ) ( entrySize - entryOffset ) ; } if ( readBuf != null ) { int sz = ( numToRead > readBuf . length ) ? readBuf . length : numToRead ; System . arraycopy ( readBuf , 0 , buf , offset , sz ) ; if ( sz >= readBuf . length ) { readBuf = null ; } else { int newLen = readBuf . length - sz ; byte [ ] newBuf = new byte [ newLen ] ; System . arraycopy ( readBuf , sz , newBuf , 0 , newLen ) ; readBuf = newBuf ; } totalRead += sz ; numToRead -= sz ; offset += sz ; } while ( numToRead > 0 ) { byte [ ] rec = buffer . readRecord ( ) ; if ( rec == null ) { throw new IOException ( "unexpected EOF with " + numToRead + " bytes unread" ) ; } int sz = numToRead ; int recLen = rec . length ; if ( recLen > sz ) { System . arraycopy ( rec , 0 , buf , offset , sz ) ; readBuf = new byte [ recLen - sz ] ; System . arraycopy ( rec , sz , readBuf , 0 , recLen - sz ) ; } else { sz = recLen ; System . arraycopy ( rec , 0 , buf , offset , recLen ) ; } totalRead += sz ; numToRead -= sz ; offset += sz ; } entryOffset += totalRead ; return totalRead ; }
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 .
