()
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public byte[] receive() throws Exception { |
| 89 | byte[] input_data = new byte[100 * 1024]; |
| 90 | |
| 91 | ByteArrayOutputStream bin = new ByteArrayOutputStream(); |
| 92 | ByteArrayOutputStream bout = new ByteArrayOutputStream(); |
| 93 | |
| 94 | int length = 0; |
| 95 | while ((length = in.read(input_data, 0, input_data.length)) >= 0) { |
| 96 | |
| 97 | bin.write(input_data, 0, length); |
| 98 | |
| 99 | int packetLen = 0; |
| 100 | while ((packetLen = callOnServerPacketReceived(bin.toByteArray())) > 0) { |
| 101 | |
| 102 | byte[] packetData = ArrayUtils.subarray(bin.toByteArray(), 0, packetLen); |
| 103 | byte[] restData = ArrayUtils.subarray(bin.toByteArray(), packetLen, bin.size()); |
| 104 | bin.reset(); |
| 105 | bin.write(restData); |
| 106 | |
| 107 | callOnServerChunkArrived(packetData); |
| 108 | |
| 109 | byte[] available_data = callOnServerChunkAvailable(); |
| 110 | if (available_data == null || available_data.length == 0) { |
| 111 | |
| 112 | continue; |
| 113 | } |
| 114 | do { |
| 115 | |
| 116 | byte[] decoded = callOnServerChunkReceived(available_data); |
| 117 | bout.write(decoded); |
| 118 | available_data = callOnServerChunkAvailable(); |
| 119 | } while (available_data != null && available_data.length > 0); |
| 120 | byte[] encoded = callOnServerChunkSend(bout.toByteArray()); |
| 121 | return encoded; |
| 122 | } |
| 123 | } |
| 124 | return null; |
| 125 | } |
| 126 | |
| 127 | @Override |
| 128 | public void close() throws Exception { |
no test coverage detected