Skip to content

Commit

Permalink
Merge pull request voldemort#88 from jghoman/badarraycopy
Browse files Browse the repository at this point in the history
Don't make a copy of the buffer, as it may shrink down to one elemnent.
  • Loading branch information
icefury71 committed Jul 31, 2012
2 parents 0aa7f42 + 40a3d99 commit 1b895b2
Showing 1 changed file with 5 additions and 4 deletions.
Expand Up @@ -16,6 +16,7 @@

package voldemort.store.readonly.fetcher;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -283,16 +284,16 @@ private void copyFileWithCheckSum(FileSystem fs,
OutputStream output = null;
try {
input = fs.open(source);
output = new FileOutputStream(dest);
output = new BufferedOutputStream(new FileOutputStream(dest));
byte[] buffer = new byte[bufferSize];
while(true) {
int read = input.read(buffer);
if(read < 0) {
break;
} else if(read < bufferSize) {
buffer = ByteUtils.copy(buffer, 0, read);
} else {
output.write(buffer, 0, read);
}
output.write(buffer);

if(fileCheckSumGenerator != null)
fileCheckSumGenerator.update(buffer);
if(throttler != null)
Expand Down

0 comments on commit 1b895b2

Please sign in to comment.