Writes into a character buffer using the correct encoding.

@param cbuf character array with the data to write.
@param off starting offset into the character array.
@param len the number of characters to write.
436664
@Override
  public int write(OutputStreamWithBuffer os, char []cbuf, int off, int len)
    throws IOException
  {
    byte []buffer = os.buffer();
    int length = os.offset();
    int capacity = buffer.length;
    int tail = off + len;
    int head = off;

    while (off < tail) {
      while (capacity - length <= 4) {
        buffer = os.nextBuffer(length);
        length = os.offset();
      }
      
      char ch = cbuf[off++];

      if (ch < 0x80) {
        buffer[length++] = (byte) ch;
      }
      else if (ch < 0x800) {
        buffer[length++] = (byte) (0xc0 + (ch >> 6));
        buffer[length++] = (byte) (0x80 + (ch & 0x3f));
      }
      else if (ch < 0xd800 || 0xdfff < ch) {
        // server/0815
        buffer[length++] = (byte) (0xe0 + (ch >> 12));
        buffer[length++] = (byte) (0x80 + ((ch >> 6) & 0x3f));
        buffer[length++] = (byte) (0x80 + (ch & 0x3f));
      }
      else if (off == tail) {
        off--;
        break;
      }
      else {
        char ch2 = cbuf[off++];
        
        int v = 0x10000 + (ch & 0x3ff) * 0x400 + (ch2 & 0x3ff);
          
        buffer[length++] = (byte) (0xf0 + (v >> 18));
        buffer[length++] = (byte) (0x80 + ((v >> 12) & 0x3f));
        buffer[length++] = (byte) (0x80 + ((v >> 6) & 0x3f));
        buffer[length++] = (byte) (0x80 + (v & 0x3f));
      }
    }

    os.offset(length);
    
    return off - head;
  }
309222
@Override
    public int read(char[] cbuf, int off, int len) throws IOException
    {
        return m_fileReader.read(cbuf, off, len);
    }
317730
@Override
    protected void write(EncodingState encodingState, char[] b, int off, int len) throws IOException {
        target.write(b, off, len);
    }
1358610
public static void checkCharacters(char[] cbuf, int off, int len) throws IOException {
		int end = off + len;
		while(off < end) checkCharacter(cbuf[off++]);
	}
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;
  }
695967
public void write(byte[] buf, int off, int len) throws IOException {
    while (true) {
      lockW.lock();
      try {
        // fail if closed
        checkClosed();
        
        final int lenToWrite = Math.min(len, length - availableCount.get());
        final int lenForward = Math.min(lenToWrite, length - writeCursor);
        final int lenRemaining = lenToWrite - lenForward;
        
        // after writeCursor
        if (lenForward > 0) {
          System.arraycopy(buf, off, bytes, writeCursor, lenForward);
          incWriteCursor(lenForward);
        }
        
        // before writeCursor
        if (lenRemaining > 0) {
          System.arraycopy(buf, off + lenForward, bytes, 0, lenRemaining);
          incWriteCursor(lenRemaining);
        } 
        
        availableCount.addAndGet(lenToWrite);
        totalWritten += lenToWrite;
        
        // modify offset and len for next iteration
        off += lenToWrite;
        len -= lenToWrite;        
        if (len == 0) {
          return;
        }
      } finally {
        lockW.unlock();
      }
      sleep(1);
    }
  }
836840
public void write(byte b[], int off, int len) {
    expandIfNecessary(count + len);
    System.arraycopy(b, off, bytes, count, len);
    count += len;
  }
45687
@Override
    public void unread( char[] cbuf, int off, int len ) throws IOException {
        assert len >= 0;
        assert off >= 0;

        final int endIndex = off + len;
        for ( int index = endIndex - 1; index >= off; index-- ) {
            unread( cbuf[ index ] );
        }
    }
652842
public int read(char []cbuf, int off, int len)
    throws IOException
  {
    int i = 0;

    for (i = 0; i < len; i++) {
      int ch1 = is.read();
      int ch2 = is.read();

      if (ch1 < 0)
        return i == 0 ? -1 : i;

      cbuf[off + i] = (char) ((ch2 << 8) + ch1);
    }

    return i;
  }
1087278
protected void set(final byte[] buf, final int off, final int len) {
        _skipped = new int[0];
        _skippedWriteIndex = 0;
        _bufferedString.set(buf, off, len);
    }
1006083
@Override
  public void writeStringData(String value, int offset, int length)
  {
    char []cBuf = _charBuffer;
    int cBufLength = cBuf.length;
    
    for (int i = 0; i < length; i += cBufLength) {
      int sublen = Math.min(length - i, cBufLength);
      
      value.getChars(offset + i, offset + i + sublen, cBuf, 0);
      
      writeStringChunk(cBuf, 0, sublen);
    }
  }
1243990
@Override
  public void write(byte[] b, int off, int len) throws IOException {
    textArea.append(new String(b, off, len));
  }
652946
@Override
	public int read(char[] cbuf, int off, int len) throws IOException {
		try {
			if (closed) {
				throw new IOException("Attempt to read from a closed stream"); //$NON-NLS-1$
			}
			if (eof) {
				return -1;
			}
			if (curr == null) {
				curr = getNextInputReader();
				if (curr == null) {
					eof = true;
					return -1;
				}
			}
			int size, bytesRead = 0, bytesToRead = len;
			while (!eof && bytesRead < bytesToRead) {
				size = curr
						.read(cbuf, off + bytesRead, bytesToRead - bytesRead);
				if (size == -1) {
					curr.close();
					curr = getNextInputReader();
					if (curr == null) {
						eof = true;
					}
				} else {
					bytesRead += size;
				}
			}
			return bytesRead;
		} catch (IOException e) {
			throw e;
		} catch (Exception e) {
			throw new IOException(e);
		}
	}
343744
@Override
    public void write(byte bbuf[], int off, int len) throws IOException {
    	for(OutputStream os : oss) {
    		os.write(bbuf,off,len);
    	}
    }
110429
@Override
    public synchronized void write(final byte[] b, final int off, final int len) {
        if (off < 0 || off > b.length || len < 0 || off + len - b.length > 0) {
            throw new IndexOutOfBoundsException();
        }
        ensureCapacity(super.count + len);
        System.arraycopy(b, off, super.buf, super.count, len);
        super.count += len;
    }
277336
public void write(byte[] b, int off, int len)
        throws IOException
    {
        if (_encoding==null)
            _writer.write(new String(b,off,len));
        else
            _writer.write(new String(b,off,len,_encoding));
    }
1246636
public void append(char c[], int off, int len) throws IOException {
	append(new String(c, off, len));
    }