src/org/sonews/daemon/LineEncoder.java
changeset 37 74139325d305
parent 35 ed84c8bdd87b
     1.1 --- a/src/org/sonews/daemon/LineEncoder.java	Sun Aug 29 17:43:58 2010 +0200
     1.2 +++ b/src/org/sonews/daemon/LineEncoder.java	Sun Aug 29 18:17:37 2010 +0200
     1.3 @@ -33,48 +33,46 @@
     1.4  class LineEncoder
     1.5  {
     1.6  
     1.7 -  private CharBuffer    characters;
     1.8 -  private Charset       charset;
     1.9 -  
    1.10 -  /**
    1.11 -   * Constructs new LineEncoder.
    1.12 -   * @param characters
    1.13 -   * @param charset
    1.14 -   */
    1.15 -  public LineEncoder(CharBuffer characters, Charset charset)
    1.16 -  {
    1.17 -    this.characters = characters;
    1.18 -    this.charset    = charset;
    1.19 -  }
    1.20 -  
    1.21 -  /**
    1.22 -   * Encodes the characters of this instance to the given ChannelLineBuffers
    1.23 -   * using the Charset of this instance.
    1.24 -   * @param buffer
    1.25 -   * @throws java.nio.channels.ClosedChannelException
    1.26 -   */
    1.27 -  public void encode(ChannelLineBuffers buffer)
    1.28 -    throws ClosedChannelException
    1.29 -  {
    1.30 -    CharsetEncoder encoder = charset.newEncoder();
    1.31 -    while (characters.hasRemaining())
    1.32 -    {
    1.33 -      ByteBuffer buf = ChannelLineBuffers.newLineBuffer();
    1.34 -      assert buf.position() == 0;
    1.35 -      assert buf.capacity() >= 512;
    1.36 +	private CharBuffer characters;
    1.37 +	private Charset charset;
    1.38  
    1.39 -      CoderResult res = encoder.encode(characters, buf, true);
    1.40 +	/**
    1.41 +	 * Constructs new LineEncoder.
    1.42 +	 * @param characters
    1.43 +	 * @param charset
    1.44 +	 */
    1.45 +	public LineEncoder(CharBuffer characters, Charset charset)
    1.46 +	{
    1.47 +		this.characters = characters;
    1.48 +		this.charset = charset;
    1.49 +	}
    1.50  
    1.51 -      // Set limit to current position and current position to 0;
    1.52 -      // means make ready for read from buffer
    1.53 -      buf.flip();
    1.54 -      buffer.addOutputBuffer(buf);
    1.55 +	/**
    1.56 +	 * Encodes the characters of this instance to the given ChannelLineBuffers
    1.57 +	 * using the Charset of this instance.
    1.58 +	 * @param buffer
    1.59 +	 * @throws java.nio.channels.ClosedChannelException
    1.60 +	 */
    1.61 +	public void encode(ChannelLineBuffers buffer)
    1.62 +		throws ClosedChannelException
    1.63 +	{
    1.64 +		CharsetEncoder encoder = charset.newEncoder();
    1.65 +		while (characters.hasRemaining()) {
    1.66 +			ByteBuffer buf = ChannelLineBuffers.newLineBuffer();
    1.67 +			assert buf.position() == 0;
    1.68 +			assert buf.capacity() >= 512;
    1.69  
    1.70 -      if (res.isUnderflow()) // All input processed
    1.71 -      {
    1.72 -        break;
    1.73 -      }
    1.74 -    }
    1.75 -  }
    1.76 -  
    1.77 +			CoderResult res = encoder.encode(characters, buf, true);
    1.78 +
    1.79 +			// Set limit to current position and current position to 0;
    1.80 +			// means make ready for read from buffer
    1.81 +			buf.flip();
    1.82 +			buffer.addOutputBuffer(buf);
    1.83 +
    1.84 +			if (res.isUnderflow()) // All input processed
    1.85 +			{
    1.86 +				break;
    1.87 +			}
    1.88 +		}
    1.89 +	}
    1.90  }