我有一个加密任务,它接收一个输入文件和一个输出文件以及要对其执行加密的密钥。奇怪的是,当我尝试提取一个执行行加密并将其作为参数接收的方法时,我会得到下一个错误:
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
}
如何使用这个加密行的私有方法来解决这个问题?