Writes a buffer to the underlying stream.

@param buffer the byte array to write.
@param offset the offset into the byte array.
@param length the number of bytes to write.
@param isEnd true when the write is flushing a close.
340550
public void write(byte []buf, int offset, int length, boolean isEnd)
    throws IOException
  {
    if (_stream != null)
      _stream.write(buf, offset, length, isEnd);
  }
627738
@Override
    public void write(char[] data, int offset, int length) throws IOException {
        while (true) {
            ensureBufferAvailable();
            if (buffer.remaining() > length) {
                buffer.backingBuffer().put(data, offset, length);
                break;
            } else if (buffer.remaining() == length) {
                buffer.backingBuffer().put(data, offset, length);
                flush(false);
                break;
            } else {
                int chunkSize = buffer.remaining();
                buffer.backingBuffer().put(data, offset, chunkSize);
                flush(false);
                length -= chunkSize;
                offset += chunkSize;
            }
        }
    }
1260636
private void writeBuffer() throws IOException {
    for (int pos = 0; pos < currentBufferSize; pos++) {
      if (isByte[pos]) {
        aFile.write((byte) buffer[pos]);
      } else {
        aFile.write(buffer[pos]);
      }
    }
  }
299382
@Override
  public void writeChunk(long length, boolean isFinal)
  {
    long chunk;
    
    if (isFinal) {
      chunk = length << 1;
    }
    else {
      chunk = (length << 1) + 1;
    }
    
    writeUnsigned(chunk);
  }
43796
public void write(char[] ca,int offset, int length)
        throws IOException
    {
        _buffer.append(ca,offset,length);
    }
294732
protected boolean write(ByteBuffer buffer) throws IOException{
        while(buffer.hasRemaining()){
            if(out.write(buffer)==0){
                out.addWriteInterest();
                return false;
            }
        }
        return true;
    }
1280236
public void write(byte[] b, int off, int len) throws IOException {
        checkForClosed();
        if (b == null) {
            throw new NullPointerException();
        } else if ((off < 0) || (len < 0) || ((off + len) > b.length)) {
            throw new IndexOutOfBoundsException();
        } else if (len == 0) {
            return;
        }
        if (len > bytesLeftInBuffer()) {
            int bytesToWrite = bytesLeftInBuffer();
            write(b, off, bytesToWrite);
            write(b, off + bytesToWrite, len - bytesToWrite);
        } else {
            System.arraycopy(b, off, _buffer, _bufferOffset, len);
            _bufferOffset += len;
            if (bytesLeftInBuffer() == 0) {
                writeBufferToFile();
            }
        }
    }
472805
public void write(byte []buf, int offset, int length, boolean isEnd)
    throws IOException
  {
    OutputStream os = _os;
    
    if (os != null) {
      os.write(buf, offset, length);
    }
  }
1058937
public final void writeToBuffer(T t, byte[] buffer) {
        if (t == null) {
            throw new InvalidArgument("cannot write a null");
        } else if (buffer == null) {
            throw new InvalidArgument("cannot write to a null buffer");
        } else if (buffer.length != recordSize) {
            final String fmt = "invalid buffer (%d bytes, expected %d)";
            final String msg = format(fmt, buffer.length, recordSize);
            throw new InvalidArgument(msg);
        }
        writeTo(t, buffer);
    }
1344517
public void write(final int b)
    {
        if (position == length)
        {
            throw new IllegalStateException("position has reached the end of underlying buffer");
        }

        buffer.putByte(offset + position, (byte)b);
        ++position;
    }
677883
public void write(InputStream is, long length, boolean escape, boolean noBackslashEscapes)
      throws IOException {
    byte[] array = new byte[4096];
    int len;
    while (length > 0 && (len = is.read(array, 0, Math.min(4096, (int) length))) > 0) {
      if (escape) {
        writeBytesEscaped(array, len, noBackslashEscapes);
      } else {
        write(array, 0, len);
      }
      length -= len;
    }
  }
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();
      }
    }
  }
789623
public void writeByteBufferPart(byte[] buffer, int offset, int length)
        throws IOException
    {
        while (length > 0) {
            flushIfFull();

            int sublen = _buffer.length - _offset;

            if (length < sublen)
                sublen = length;

            _buffer[_offset++] = BC_BINARY_CHUNK;
            _buffer[_offset++] = (byte) (sublen >> 8);
            _buffer[_offset++] = (byte) sublen;

            System.arraycopy(buffer, offset, _buffer, _offset, sublen);

            _offset += sublen;
            length -= sublen;
            offset += sublen;
        }
    }
942229
public void writeRawBytes(final ByteString value, int offset, int length)
                            throws IOException {
    if (limit - position >= length) {
      // We have room in the current buffer.
      value.copyTo(buffer, offset, position, length);
      position += length;
    } else {
      // Write extends past current buffer.  Fill the rest of this buffer and
      // flush.
      final int bytesWritten = limit - position;
      value.copyTo(buffer, offset, 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.
        value.copyTo(buffer, offset, 0, length);
        position = length;
      } else {
        // Write is very big, but we can't do it all at once without allocating
        // an a copy of the byte array since ByteString does not give us access
        // to the underlying bytes. Use the InputStream interface on the
        // ByteString and our buffer to copy between the two.
        InputStream inputStreamFrom = value.newInput();
        if (offset != inputStreamFrom.skip(offset)) {
          throw new IllegalStateException("Skip failed? Should never happen.");
        }
        // Use the buffer as the temporary buffer to avoid allocating memory.
        while (length > 0) {
          int bytesToRead = Math.min(length, limit);
          int bytesRead = inputStreamFrom.read(buffer, 0, bytesToRead);
          if (bytesRead != bytesToRead) {
            throw new IllegalStateException("Read failed? Should never happen");
          }
          output.write(buffer, 0, bytesRead);
          length -= bytesRead;
        }
      }
    }
  }
354526
public void write(ByteBuffer buffer) {
    if (buffer.remaining() < 8196) {
      write(buffer.array(), buffer.arrayOffset() + buffer.position(),
          buffer.remaining());
    } else { // append w/o copying bytes
      ByteBuffer dup = buffer.duplicate();
      dup.position(buffer.limit()); // ready for flip
      buffers.add(dup);
    }
  }
1311645
@Override
  public void write(byte []buf, int offset, int length, boolean isEnd)
    throws IOException
  {
    int end = offset + length;
    while (offset < end) {
      int ch1 = buf[offset++] & 0xff;

      if (ch1 < 0x80)
        _cb.append((char) ch1);
      else if ((ch1 & 0xe0) == 0xc0) {
        if (offset >= end)
          throw new EOFException("unexpected end of file in utf8 character");
        
        int ch2 = buf[offset++] & 0xff;
        if ((ch2 & 0xc0) != 0x80)
          throw new CharConversionException("illegal utf8 encoding");
      
        _cb.append((char) (((ch1 & 0x1f) << 6) + (ch2 & 0x3f)));
      }
      else if ((ch1 & 0xf0) == 0xe0) {
        if (offset + 1 >= end)
          throw new EOFException("unexpected end of file in utf8 character");
        
        int ch2 = buf[offset++] & 0xff;
        int ch3 = buf[offset++] & 0xff;
      
        if ((ch2 & 0xc0) != 0x80)
          throw new CharConversionException("illegal utf8 encoding");
      
        if ((ch3 & 0xc0) != 0x80)
          throw new CharConversionException("illegal utf8 encoding");
      
        _cb.append((char) (((ch1 & 0x1f) << 12) + ((ch2 & 0x3f) << 6) + (ch3 & 0x3f)));
      }
      else
        throw new CharConversionException("illegal utf8 encoding at (" +
                                          (int) ch1 + ")");
    }
  }
994829
@Override
	protected synchronized void write(long offset, byte[] b) throws IOException {
		if (byteBuffer != null) {
			byteBuffer.position((int) offset);
			byteBuffer.put(b);
		} else {
			throw new IOException("Write failed, file " + getPath() + " not mapped for I/O");
		}
	}