* ChannelBuffer.writeBytes(InputStream, ...) must return an integer

* Fixed a problem where DynamicChannelBuffer doesn't expand itself for some writeBytes() calls
This commit is contained in:
Trustin Lee 2009-03-12 06:40:36 +00:00
parent 1895864d38
commit 35b08df70a
4 changed files with 23 additions and 5 deletions

View File

@ -418,10 +418,13 @@ public abstract class AbstractChannelBuffer implements ChannelBuffer {
writerIndex += length;
}
public void writeBytes(InputStream in, int length)
public int writeBytes(InputStream in, int length)
throws IOException {
setBytes(writerIndex, in, length);
writerIndex += length;
int writtenBytes = setBytes(writerIndex, in, length);
if (writtenBytes > 0) {
writerIndex += writtenBytes;
}
return writtenBytes;
}
public int writeBytes(ScatteringByteChannel in, int length)

View File

@ -1228,12 +1228,14 @@ public interface ChannelBuffer extends Comparable<ChannelBuffer> {
*
* @param length the number of bytes to transfer
*
* @return the actual number of bytes read in from the specified stream
*
* @throws IndexOutOfBoundsException
* if {@code length} is greater than {@code this.writableBytes}
* @throws IOException
* if the specified stream threw an exception during I/O
*/
void writeBytes(InputStream in, int length) throws IOException;
int writeBytes(InputStream in, int length) throws IOException;
/**
* Transfers the content of the specified channel to this buffer

View File

@ -216,6 +216,19 @@ public class DynamicChannelBuffer extends AbstractChannelBuffer {
super.writeBytes(src);
}
@Override
public int writeBytes(InputStream in, int length) throws IOException {
ensureWritableBytes(length);
return super.writeBytes(in, length);
}
@Override
public int writeBytes(ScatteringByteChannel in, int length)
throws IOException {
ensureWritableBytes(length);
return super.writeBytes(in, length);
}
@Override
public void writeZero(int length) {
ensureWritableBytes(length);

View File

@ -502,7 +502,7 @@ class ReplayingDecoderBuffer implements ChannelBuffer {
throw new UnreplayableOperationException();
}
public void writeBytes(InputStream in, int length) throws IOException {
public int writeBytes(InputStream in, int length) throws IOException {
throw new UnreplayableOperationException();
}