|
28 | 28 | import java.io.IOException;
|
29 | 29 | import java.io.InputStream;
|
30 | 30 | import java.io.OutputStream;
|
| 31 | +import java.io.BufferedOutputStream; |
31 | 32 | import java.lang.reflect.InvocationTargetException;
|
32 | 33 | import java.net.InetAddress;
|
33 | 34 | import java.net.InetSocketAddress;
|
@@ -850,17 +851,20 @@ public void run() {
|
850 | 851 | * @throws IOException if write or flush did not work
|
851 | 852 | */
|
852 | 853 | private void runWriteData() throws IOException {
|
| 854 | + BufferedOutputStream bufferedInputStream = new BufferedOutputStream(ostream); |
853 | 855 | try {
|
854 | 856 | while (!Thread.interrupted()) {
|
855 | 857 | ByteBuffer buffer = engine.outQueue.take();
|
856 |
| - ostream.write(buffer.array(), 0, buffer.limit()); |
857 |
| - ostream.flush(); |
| 858 | + bufferedInputStream.write(buffer.array(), 0, buffer.limit()); |
| 859 | + if(engine.outQueue.isEmpty()) { |
| 860 | + bufferedInputStream.flush(); |
| 861 | + } |
858 | 862 | }
|
859 | 863 | } catch (InterruptedException e) {
|
860 | 864 | for (ByteBuffer buffer : engine.outQueue) {
|
861 |
| - ostream.write(buffer.array(), 0, buffer.limit()); |
862 |
| - ostream.flush(); |
| 865 | + bufferedInputStream.write(buffer.array(), 0, buffer.limit()); |
863 | 866 | }
|
| 867 | + bufferedInputStream.flush(); |
864 | 868 | Thread.currentThread().interrupt();
|
865 | 869 | }
|
866 | 870 | }
|
|
0 commit comments