我有一个加密任务,它接收输入文件和输出文件以及执行加密的密钥。奇怪的是,当我尝试提取执行行加密并将其作为参数接收的方法时,我得到下一个错误:Could not find method encryptLine() for arguments [PK] on task ':presentation:encryptScenarios' of type EncryptionTask.
. 当我内联这个方法时 - 它工作正常。
这是内联变体的代码:
@TaskAction
void encryptFile() {
assertThatEncryptionKeyIsPresent()
createNewOutputFileIfNotExists()
final FileOutputStream outputStream = new FileOutputStream(outputFile)
inputFile.eachLine { String line ->
final byte[] inputBytes = line.getBytes()
final byte[] secretBytes = key.getBytes()
final byte[] outputBytes = new byte[inputBytes.length]
int spos = 0
for (int pos = 0; pos < inputBytes.length; ++pos) {
outputBytes[pos] = (byte) (inputBytes[pos] ^ secretBytes[spos])
spos += 1
if (spos >= secretBytes.length) {
spos = 0
}
}
outputStream.write(Base64.encodeBase64String(outputBytes).getBytes())
}
}
这是提取的方法变体的代码:
@TaskAction
void encryptFile() {
assertThatEncryptionKeyIsPresent()
createNewOutputFileIfNotExists()
final FileOutputStream outputStream = new FileOutputStream(outputFile)
inputFile.eachLine { String line ->
byte[] outputBytes = encryptLine(line)
outputStream.write(Base64.encodeBase64String(outputBytes).getBytes())
}
}
private byte[] encryptLine(String line) {
final byte[] inputBytes = line.getBytes()
final byte[] secretBytes = key.getBytes()
final byte[] outputBytes = new byte[inputBytes.length]
int spos = 0
for (int pos = 0; pos < inputBytes.length; ++pos) {
outputBytes[pos] = (byte) (inputBytes[pos] ^ secretBytes[spos])
spos += 1
if (spos >= secretBytes.length) {
spos = 0
}
}
outputBytes
}
如何使用这种加密线路的私有方法解决此问题?