Exemple #1
0
 public final void write(Buffer source, long byteCount) throws IOException {
   Util.checkOffsetAndCount(source.size, 0, byteCount);
   while (byteCount > 0) {
     Segment head = source.head;
     int toDeflate = (int) Math.min(byteCount, (long) (head.limit - head.pos));
     this.deflater.setInput(head.data, head.pos, toDeflate);
     deflate(false);
     source.size -= (long) toDeflate;
     head.pos += toDeflate;
     if (head.pos == head.limit) {
       source.head = head.pop();
       SegmentPool.recycle(head);
     }
     byteCount -= (long) toDeflate;
   }
 }
Exemple #2
0
 @IgnoreJRERequirement
 private void deflate(boolean syncFlush) throws IOException {
   Buffer buffer = this.sink.buffer();
   while (true) {
     Segment s = buffer.writableSegment(1);
     int deflated =
         syncFlush
             ? this.deflater.deflate(s.data, s.limit, 2048 - s.limit, 2)
             : this.deflater.deflate(s.data, s.limit, 2048 - s.limit);
     if (deflated > 0) {
       s.limit += deflated;
       buffer.size += (long) deflated;
       this.sink.emitCompleteSegments();
     } else if (this.deflater.needsInput()) {
       break;
     }
   }
   if (s.pos == s.limit) {
     buffer.head = s.pop();
     SegmentPool.recycle(s);
   }
 }