in encryption/src/main/java/org/apache/solr/encryption/crypto/DecryptingInputStream.java [152:181]
public int read(byte[] b, int offset, int length) throws IOException {
if (offset < 0 || length < 0 || offset + length > b.length) {
throw new IllegalArgumentException(
"Invalid read buffer parameters (offset=" + offset + ", length=" + length
+ ", arrayLength=" + b.length + ")");
}
int numDecrypted = 0;
while (length > 0) {
// Transfer decrypted bytes from outBuffer.
int outRemaining = outSize - outPos;
if (outRemaining > 0) {
if (length <= outRemaining) {
System.arraycopy(outBuffer, outPos, b, offset, length);
outPos += length;
numDecrypted += length;
return numDecrypted;
}
System.arraycopy(outBuffer, outPos, b, offset, outRemaining);
outPos += outRemaining;
numDecrypted += outRemaining;
offset += outRemaining;
length -= outRemaining;
}
if (!readToFillBuffer(length)) {
return numDecrypted == 0 ? -1 : numDecrypted;
}
decryptBuffer();
}
return numDecrypted;
}