diff -r ed84c8bdd87b -r 74139325d305 src/org/sonews/daemon/LineEncoder.java --- a/src/org/sonews/daemon/LineEncoder.java Sun Aug 29 17:28:58 2010 +0200 +++ b/src/org/sonews/daemon/LineEncoder.java Sun Aug 29 18:17:37 2010 +0200 @@ -33,48 +33,46 @@ class LineEncoder { - private CharBuffer characters; - private Charset charset; - - /** - * Constructs new LineEncoder. - * @param characters - * @param charset - */ - public LineEncoder(CharBuffer characters, Charset charset) - { - this.characters = characters; - this.charset = charset; - } - - /** - * Encodes the characters of this instance to the given ChannelLineBuffers - * using the Charset of this instance. - * @param buffer - * @throws java.nio.channels.ClosedChannelException - */ - public void encode(ChannelLineBuffers buffer) - throws ClosedChannelException - { - CharsetEncoder encoder = charset.newEncoder(); - while (characters.hasRemaining()) - { - ByteBuffer buf = ChannelLineBuffers.newLineBuffer(); - assert buf.position() == 0; - assert buf.capacity() >= 512; + private CharBuffer characters; + private Charset charset; - CoderResult res = encoder.encode(characters, buf, true); + /** + * Constructs new LineEncoder. + * @param characters + * @param charset + */ + public LineEncoder(CharBuffer characters, Charset charset) + { + this.characters = characters; + this.charset = charset; + } - // Set limit to current position and current position to 0; - // means make ready for read from buffer - buf.flip(); - buffer.addOutputBuffer(buf); + /** + * Encodes the characters of this instance to the given ChannelLineBuffers + * using the Charset of this instance. + * @param buffer + * @throws java.nio.channels.ClosedChannelException + */ + public void encode(ChannelLineBuffers buffer) + throws ClosedChannelException + { + CharsetEncoder encoder = charset.newEncoder(); + while (characters.hasRemaining()) { + ByteBuffer buf = ChannelLineBuffers.newLineBuffer(); + assert buf.position() == 0; + assert buf.capacity() >= 512; - if (res.isUnderflow()) // All input processed - { - break; - } - } - } - + CoderResult res = encoder.encode(characters, buf, true); + + // Set limit to current position and current position to 0; + // means make ready for read from buffer + buf.flip(); + buffer.addOutputBuffer(buf); + + if (res.isUnderflow()) // All input processed + { + break; + } + } + } }