Commit c1d7fe7e authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Added resize option.

git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/branches@2796 b35dd754-fafc-0310-a699-88a17e54d16e
parent 684cc6e9
...@@ -109,7 +109,8 @@ public class TLSStreamWriter { ...@@ -109,7 +109,8 @@ public class TLSStreamWriter {
} }
public synchronized void write(byte[] bytes, int off, int len) throws IOException { public synchronized void write(byte[] bytes, int off, int len) throws IOException {
outAppData.put(bytes, off, len); outAppData = resizeApplicationBuffer(bytes.length);
outAppData.put(bytes, off, len);
outAppData.flip(); outAppData.flip();
doWrite(outAppData); doWrite(outAppData);
outAppData.clear(); outAppData.clear();
...@@ -117,4 +118,17 @@ public class TLSStreamWriter { ...@@ -117,4 +118,17 @@ public class TLSStreamWriter {
}; };
} }
private ByteBuffer resizeApplicationBuffer(int increment) {
// TODO Creating new buffers and copying over old one may not scale. Consider using views. Thanks to Noah for the tip.
if (outAppData.remaining() < increment) {
System.out.println("resizing writer");
ByteBuffer bb = ByteBuffer.allocate(outAppData.capacity() + wrapper.getAppBuffSize());
outAppData.flip();
bb.put(outAppData);
return bb;
} else {
return outAppData;
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment