Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OOM error on some devices due to larger files is fixed. #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions alice/src/main/java/com/rockaport/alice/Alice.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public synchronized void encrypt(File input, File output, char[] password)
// allocate variables
int bytesRead;
byte[] encryptedBytes;
byte[] inputStreamBuffer = new byte[4096];
byte[] inputStreamBuffer = new byte[1024];

// setup streams
bufferedInputStream = new BufferedInputStream(new FileInputStream(input));
Expand All @@ -250,7 +250,7 @@ public synchronized void encrypt(File input, File output, char[] password)
// write the initialization vector
bufferedOutputStream.write(initializationVector);

while ((bytesRead = bufferedInputStream.read(inputStreamBuffer)) > 0) {
while ((bytesRead = bufferedInputStream.read(inputStreamBuffer)) != -1) {
// encrypt
encryptedBytes = cipher.update(inputStreamBuffer, 0, bytesRead);

Expand Down Expand Up @@ -322,8 +322,8 @@ public synchronized void encrypt(InputStream input, OutputStream output, char[]

// allocate variables
int bytesRead;
byte[] inputStreamBuffer = new byte[4096];
while ((bytesRead = bufferedInputStream.read(inputStreamBuffer)) > 0) {
byte[] inputStreamBuffer = new byte[1024];
while ((bytesRead = bufferedInputStream.read(inputStreamBuffer)) != -1) {
// encrypt
bufferedOutputStream.write(cipher.update(inputStreamBuffer, 0, bytesRead));
}
Expand Down Expand Up @@ -455,7 +455,7 @@ public synchronized void decrypt(File input, File output, char[] password)
// allocate loop buffers and variables
int bytesRead;
int numBytesToProcess;
byte[] inputStreamBuffer = new byte[4096];
byte[] inputStreamBuffer = new byte[1024];
long bytesLeft = input.length() - context.getIvLength();

// subtract the mac length if enabled
Expand All @@ -464,7 +464,7 @@ public synchronized void decrypt(File input, File output, char[] password)
}

// decrypt
while ((bytesRead = bufferedInputStream.read(inputStreamBuffer)) > 0) {
while ((bytesRead = bufferedInputStream.read(inputStreamBuffer)) != -1) {
numBytesToProcess = (bytesRead < bytesLeft) ? bytesRead : (int) bytesLeft;

if (numBytesToProcess <= 0) {
Expand Down Expand Up @@ -545,10 +545,10 @@ public synchronized void decrypt(InputStream input, OutputStream output, char[]

// allocate loop buffers and variables
int bytesRead;
byte[] inputStreamBuffer = new byte[4096];
byte[] inputStreamBuffer = new byte[1024];

// decrypt
while ((bytesRead = bufferedInputStream.read(inputStreamBuffer)) > 0) {
while ((bytesRead = bufferedInputStream.read(inputStreamBuffer)) != -1) {
bufferedOutputStream.write(cipher.update(inputStreamBuffer, 0, bytesRead));
}

Expand Down Expand Up @@ -661,4 +661,4 @@ private void closeStream(Closeable stream) {
}
}
}
}
}