larksuite-oapi/src/main/java/com/larksuite/oapi/okio1_17/Buffer.java
public final int seek(long offset) {
      if (offset < -1 || offset > buffer.size) {
        throw new ArrayIndexOutOfBoundsException(
            String.format("offset=%s > size=%s", offset, buffer.size));
      }

      if (offset == -1 || offset == buffer.size) {
        this.segment = null;
        this.offset = offset;
        this.data = null;
        this.start = -1;
        this.end = -1;
        return -1;
      }

      // Navigate to the segment that contains `offset`. Start from our current segment if possible.
      long min = 0L;
      long max = buffer.size;
      Segment head = buffer.head;
      Segment tail = buffer.head;
      if (this.segment != null) {
        long segmentOffset = this.offset - (this.start - this.segment.pos);
        if (segmentOffset > offset) {
          // Set the cursor segment to be the 'end'
          max = segmentOffset;
          tail = this.segment;
        } else {
          // Set the cursor segment to be the 'beginning'
          min = segmentOffset;
          head = this.segment;
        }
      }

      Segment next;
      long nextOffset;
      if (max - offset > offset - min) {
        // Start at the 'beginning' and search forwards
        next = head;
        nextOffset = min;
        while (offset >= nextOffset + (next.limit - next.pos)) {
          nextOffset += (next.limit - next.pos);
          next = next.next;
        }
      } else {
        // Start at the 'end' and search backwards
        next = tail;
        nextOffset = max;
        while (nextOffset > offset) {
          next = next.prev;
          nextOffset -= (next.limit - next.pos);
        }
      }

      // If we're going to write and our segment is shared, swap it for a read-write one.
      if (readWrite && next.shared) {
        Segment unsharedNext = next.unsharedCopy();
        if (buffer.head == next) {
          buffer.head = unsharedNext;
        }
        next = next.push(unsharedNext);
        next.prev.pop();
      }

      // Update this cursor to the requested offset within the found segment.
      this.segment = next;
      this.offset = offset;
      this.data = next.data;
      this.start = next.pos + (int) (offset - nextOffset);
      this.end = next.limit;
      return end - start;
    }
/**
     * Reposition the cursor so that the data at {@code offset} is readable at {@code data[start]}.
     * Returns the number of bytes readable in {@code data} (at least 1), or -1 if there are no data
     * to read.
     */
Reposition the cursor so that the data at  offset is readable at  data[start].
Returns the number of bytes readable in  data (at least 1), or -1 if there are no data
to read.
Reposition the cursor so that the data at offset is readable at data [ start ] . Returns the number of bytes readable in data ( at least 1 ) or - 1 if there are no data to read .
public final int seek(long offset) {
      if (offset < -1 || offset > buffer.size) {
        throw new ArrayIndexOutOfBoundsException(
            String.format("offset=%s > size=%s", offset, buffer.size));
      }
      if (offset == -1 || offset == buffer.size) {
        this.segment = null;
        this.offset = offset;
        this.data = null;
        this.start = -1;
        this.end = -1;
        return -1;
      }
      long min = 0L;
      long max = buffer.size;
      Segment head = buffer.head;
      Segment tail = buffer.head;
      if (this.segment != null) {
        long segmentOffset = this.offset - (this.start - this.segment.pos);
        if (segmentOffset > offset) {
          max = segmentOffset;
          tail = this.segment;
        } else {
          min = segmentOffset;
          head = this.segment;
        }
      }
      Segment next;
      long nextOffset;
      if (max - offset > offset - min) {
        next = head;
        nextOffset = min;
        while (offset >= nextOffset + (next.limit - next.pos)) {
          nextOffset += (next.limit - next.pos);
          next = next.next;
        }
      } else {
        next = tail;
        nextOffset = max;
        while (nextOffset > offset) {
          next = next.prev;
          nextOffset -= (next.limit - next.pos);
        }
      }
      if (readWrite && next.shared) {
        Segment unsharedNext = next.unsharedCopy();
        if (buffer.head == next) {
          buffer.head = unsharedNext;
        }
        next = next.push(unsharedNext);
        next.prev.pop();
      }
      this.segment = next;
      this.offset = offset;
      this.data = next.data;
      this.start = next.pos + (int) (offset - nextOffset);
      this.end = next.limit;
      return end - start;
    }
public final int seek ( long offset ) { if ( offset < - 1 || offset > buffer . size ) { throw new ArrayIndexOutOfBoundsException ( String . format ( "offset=%s > size=%s" , offset , buffer . size ) ) ; } if ( offset == - 1 || offset == buffer . size ) { this . segment = null ; this . offset = offset ; this . data = null ; this . start = - 1 ; this . end = - 1 ; return - 1 ; } long min = 0L ; long max = buffer . size ; Segment head = buffer . head ; Segment tail = buffer . head ; if ( this . segment != null ) { long segmentOffset = this . offset - ( this . start - this . segment . pos ) ; if ( segmentOffset > offset ) { max = segmentOffset ; tail = this . segment ; } else { min = segmentOffset ; head = this . segment ; } } Segment next ; long nextOffset ; if ( max - offset > offset - min ) { next = head ; nextOffset = min ; while ( offset >= nextOffset + ( next . limit - next . pos ) ) { nextOffset += ( next . limit - next . pos ) ; next = next . next ; } } else { next = tail ; nextOffset = max ; while ( nextOffset > offset ) { next = next . prev ; nextOffset -= ( next . limit - next . pos ) ; } } if ( readWrite && next . shared ) { Segment unsharedNext = next . unsharedCopy ( ) ; if ( buffer . head == next ) { buffer . head = unsharedNext ; } next = next . push ( unsharedNext ) ; next . prev . pop ( ) ; } this . segment = next ; this . offset = offset ; this . data = next . data ; this . start = next . pos + ( int ) ( offset - nextOffset ) ; this . end = next . limit ; return end - start ; }
Reposition the cursor so that the data at {@code offset} is readable at {@code data[start]}.
Reposition the cursor so that the data at { @code offset } is readable at { @code data [ start ] } .
// Navigate to the segment that contains `offset`. Start from our current segment if possible. // Set the cursor segment to be the 'end' // Set the cursor segment to be the 'beginning' // Start at the 'beginning' and search forwards // Start at the 'end' and search backwards // If we're going to write and our segment is shared, swap it for a read-write one. // Update this cursor to the requested offset within the found segment.