Skip to content

Commit

Permalink
Fix potential bug
Browse files Browse the repository at this point in the history
There was a chance .read() did not give a divisible by 8 number of bytes
This is unlikely to happen til the end but fix this incase it ever would
  • Loading branch information
gamax92 committed Mar 31, 2017
1 parent 88b23ab commit 7250324
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/main/java/LionRay.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,20 @@ public static void convert(String inputFilename, String outputFilename, boolean
BufferedOutputStream outFile = new BufferedOutputStream(new FileOutputStream(outputFilename));

byte[] readBuffer = new byte[1024];
byte[] outBuffer = new byte[1024 / 8];
byte[] outBuffer = new byte[readBuffer.length / 8];
DFPWM converter = new DFPWM(dfpwmNew);

int read;
while ((read = inFile.read(readBuffer)) > 0) {
do {
for(read = 0; read < readBuffer.length;) {
int amt = inFile.read(readBuffer, read, readBuffer.length - read);
if(amt == -1) break;
read += amt;
}
read &= ~0x07;
converter.compress(outBuffer, readBuffer, 0, 0, read / 8);
outFile.write(outBuffer, 0, read / 8);
}
} while(read == readBuffer.length);
outFile.close();
}

Expand Down

0 comments on commit 7250324

Please sign in to comment.