Write a portion from the buffer.
@param buffer The buffer
@param offset Offset in the buffer
@param length Maximum possible amount to take
@return How much was taken
@throws IOException If fails
497111
private int next(final byte[] buffer, final int offset,
        final int length) throws IOException {
        final int max = Math.min(length, this.input.remaining());
        this.input.put(buffer, offset, max);
        this.input.flip();
        while (true) {
            final CoderResult result = this.decoder.decode(
                this.input, this.output, false
            );
            if (result.isError()) {
                result.throwException();
            }
            this.writer.write(
                this.output.array(), 0, this.output.position()
            );
            this.writer.flush();
            this.output.rewind();
            if (result.isUnderflow()) {
                break;
            }
        }
        this.input.compact();
        return max;
    }
506285
public void write(String text, int offset, int length) {
        buffer.append(text, offset, offset + length);
    }
673177
private boolean checkBuffer(long offset) throws IOException {
    if (offset - bufferOffset < 0 || offset - bufferOffset >= currentBufferSize) {
      // the given offset is not contained in the buffer
      bufferOffset = offset;
      int index = 0;
      input.seek(offset);
      try {
        //input.read(buffer, 0, maxBufferSize);
        for (long pos = offset; pos < offset + maxBufferSize; pos++) {
          int ch = input.read();
          if (ch > -1) {
            buffer[index] = (byte)ch;
            index++;
          }
        }
      } catch (IOException ex) {
        // not possible
        ex.printStackTrace();
      }
      currentBufferSize = index;
      return true;
    }
    return false;
  }
43796
public void write(char[] ca,int offset, int length)
        throws IOException
    {
        _buffer.append(ca,offset,length);
    }
1161512
public void write(ByteBuffer buffer, int len) {
        if (len < 1) return;
        if (count >= content.length - len) {
            byte[] ns = new byte[content.length + len];
            System.arraycopy(content, 0, ns, 0, count);
            this.content = ns;
        }
        buffer.get(content, count, len);
        count += len;
    }
520041
public void postwrite(byte[] b,int offset, int length)
        throws IOException
    {
        System.arraycopy(b,offset,_buf,_pos,length);
        _pos+=length;
    }
766933
public void writeRawBytes(final byte[] value, int offset, int length)
                            throws IOException {
    if (limit - position >= length) {
      // We have room in the current buffer.
      System.arraycopy(value, offset, buffer, position, length);
      position += length;
    } else {
      // Write extends past current buffer.  Fill the rest of this buffer and
      // flush.
      final int bytesWritten = limit - position;
      System.arraycopy(value, offset, buffer, position, bytesWritten);
      offset += bytesWritten;
      length -= bytesWritten;
      position = limit;
      refreshBuffer();

      // Now deal with the rest.
      // Since we have an output stream, this is our buffer
      // and buffer offset == 0
      if (length <= limit) {
        // Fits in new buffer.
        System.arraycopy(value, offset, buffer, 0, length);
        position = length;
      } else {
        // Write is very big.  Let's do it all at once.
        output.write(value, offset, length);
      }
    }
  }
824039
@Override
  public void write(byte []buf, int offset, int length, boolean isEnd)
    throws IOException
  {
    OutputStream stream = getStream();

    if (stream == null) {
      return;
    }

    synchronized (stream) {
      stream.write(buf, offset, length);
      
      if (isEnd) {
        stream.flush();
      }
    }
  }
471137
public void writeBytes(byte[] buffer)
        throws IOException
    {
        if (buffer == null)
            os.write('N');
        else
            writeBytes(buffer, 0, buffer.length);
    }
430126
public int read(byte []buffer, int offset, int length)
    throws IOException
  {
    return _stream.read(buffer, offset, length);
  }
904849
public void write(byte []buffer, int offset, int length, boolean isEnd)
    throws IOException
  {
    _crc = Crc64.generate(_crc, buffer, offset, length);
    
    _next.write(buffer, offset, length, isEnd);
  }
1339289
public void write(byte b[], int off, int len)
        throws IOException
    {     
        len=prepareOutput(len);
        if (!_nulled)
            _out.write(b,off,len);
        if (_bytes==_contentLength)
            flush();
    }
175813
private int writeAtMost(byte[] data, int offset, int length)
    {
        if (current >= bufferOffset + buffer.length)
            reBuffer();

        assert current < bufferOffset + buffer.length
                : String.format("File (%s) offset %d, buffer offset %d.", getPath(), current, bufferOffset);


        int toCopy = Math.min(length, buffer.length - bufferCursor());

        // copy bytes from external buffer
        System.arraycopy(data, offset, buffer, bufferCursor(), toCopy);

        assert current <= bufferOffset + buffer.length
                : String.format("File (%s) offset %d, buffer offset %d.", getPath(), current, bufferOffset);

        validBufferBytes = Math.max(validBufferBytes, bufferCursor() + toCopy);
        current += toCopy;

        return toCopy;
    }
147000
public void write(byte[] b)
        throws IOException
    {
        ensureSpareCapacity(b.length);
        System.arraycopy(b,0,_buf,_pos,b.length);
        _pos+=b.length;
    }
1130770
public void write(byte[] arr, int off, int len) throws IOException {
    if (len > buf.length - pos) {
      if (buf.length != getMaxPacketLength()) {
        growBuffer(len);
      }

      //max buffer size
      if (len > buf.length - pos) {

        if (mark != -1) {
          growBuffer(len);
          if (mark != -1) {
            flushBufferStopAtMark();
          }

        } else {
          //not enough space in buffer, will stream :
          // fill buffer and flush until all data are snd
          int remainingLen = len;
          do {
            int lenToFillBuffer = Math.min(getMaxPacketLength() - pos, remainingLen);
            System.arraycopy(arr, off, buf, pos, lenToFillBuffer);
            remainingLen -= lenToFillBuffer;
            off += lenToFillBuffer;
            pos += lenToFillBuffer;
            if (remainingLen > 0) {
              flushBuffer(false);
            } else {
              break;
            }
          } while (true);
          return;
        }
      }
    }

    System.arraycopy(arr, off, buf, pos, len);
    pos += len;
  }
1315383
public void write (byte[] buf, int off, int len)
            throws IOException
     {
            out.write (buf, off, len);
     }
910554
public void write(long fileOffset, byte []buffer, int offset, int length)
    throws IOException
  {
    _file.seek(fileOffset);
    
    _file.write(buffer, offset, length);
  }