Code example for WritableByteChannel

Methods: write

0
  private CharBuffer charBuffer;
 
  private void writeBuffer() throws IOException 
  { 
    byteBuffer.flip();
    byteChannel.write(byteBuffer);
  } 
 
  /** 
   * Create a new instance, given the output byte channel, the encoder 
   * to use, and the minimum buffer capacity. 
   */ 
  public ChannelWriter(WritableByteChannel ch, CharsetEncoder enc,
                       int minBufferCap)
  { 
    this.byteChannel = ch;
    this.enc = enc;
    if (minBufferCap == -1)
      minBufferCap = DEFAULT_BUFFER_CAP;
    this.byteBuffer
      = ByteBuffer.allocate((int) (minBufferCap * enc.maxBytesPerChar()));