When a buffer is done, we send it to the receiver to store. If we are encrypting, encrypt the buffer before we pass it on. @param buffer the buffer to store
(ByteBuffer buffer)
| 133 | * @param buffer the buffer to store |
| 134 | */ |
| 135 | void outputBuffer(ByteBuffer buffer) throws IOException { |
| 136 | if (cipher != null) { |
| 137 | ByteBuffer output = buffer.duplicate(); |
| 138 | int len = buffer.remaining(); |
| 139 | try { |
| 140 | int encrypted = cipher.update(buffer, output); |
| 141 | output.flip(); |
| 142 | receiver.output(output); |
| 143 | if (encrypted != len) { |
| 144 | throw new IllegalArgumentException("Encryption of incomplete buffer " |
| 145 | + len + " -> " + encrypted + " in " + this); |
| 146 | } |
| 147 | } catch (ShortBufferException e) { |
| 148 | throw new IOException("Short buffer in encryption in " + this, e); |
| 149 | } |
| 150 | } else { |
| 151 | receiver.output(buffer); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Ensure that the cipher didn't save any data. |
no test coverage detected