<p>Why does the following method hang?</p>

<pre>
public void pipe(Reader in, Writer out) {
    CharBuffer buf = CharBuffer.allocate(DEFAULT_BUFFER_SIZE);
    while( in.read(buf) >= 0 ) {
      out.append(buf.flip());
    }
}
</pre>

Answering my own question: you have to call
```
buf.clear()
```
between
```
read
```
s. Presumably,
```
read
```
is hanging because the buffer is full. The correct code is
```
public void pipe(Reader in, Writer out) {
    CharBuffer buf = CharBuffer.allocate(DEFAULT_BUFFER_SIZE);
    while( in.read(buf) >= 0 ) {
      out.append(buf.flip());
      buf.clear();
    }
}
```