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