feat: fix buffer

This commit is contained in:
2024-01-01 14:48:11 +08:00
parent 5e4e74f1a5
commit 9b18e9ed3c

View File

@@ -58,6 +58,7 @@ public class Main {
final byte[] encrypted = gcmCrypt(keyBytes, nonceBytes, true, resultBytes);
writeFile(file, encrypted);
}
System.exit(0);
}
@@ -139,11 +140,10 @@ public class Main {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final byte[] buffer = new byte[1024 * 8];
try (FileInputStream fis = new FileInputStream(file)) {
final int len = fis.read(buffer);
if (len == -1) {
return baos.toByteArray();
int len;
while ((len = fis.read(buffer)) != -1) {
baos.write(buffer, 0, len);
}
baos.write(buffer, 0, len);
} catch (IOException e) {
throw new RuntimeException("Read file: " + file + " failed: " + e.getMessage(), e);
}