Be a bit more careful with error handling and printing warning messages.

This commit is contained in:
Scott Crosby 2010-09-02 07:42:30 -05:00
parent d5d93f9609
commit 4f013ebbfc
1 changed files with 10 additions and 4 deletions

View File

@ -18,6 +18,9 @@ public class FileBlock extends FileBlockBase {
/** Contains the contents of a block for use or further processing */ /** Contains the contents of a block for use or further processing */
ByteString data; // serialized Format.Blob ByteString data; // serialized Format.Blob
/** Don't be noisy unless the warning occurs somewhat often */
static int warncount = 0;
private FileBlock(String type, ByteString blob, ByteString indexdata) { private FileBlock(String type, ByteString blob, ByteString indexdata) {
super(type, indexdata); super(type, indexdata);
this.data = blob; this.data = blob;
@ -39,15 +42,18 @@ public class FileBlock extends FileBlockBase {
deflater.finish(); deflater.finish();
byte out[] = new byte[size]; byte out[] = new byte[size];
deflater.deflate(out); deflater.deflate(out);
if (!deflater.finished()) { if (!deflater.finished()) {
// Buffer wasn't long enough. Be noisy. // Buffer wasn't long enough. Be noisy.
System.out ++warncount;
.println("Compressed buffer too short causing extra copy"); if (warncount > 10 && warncount%100 == 0)
System.out.println("Compressed buffers are too short, causing extra copy");
out = Arrays.copyOf(out, size + size / 64 + 16); out = Arrays.copyOf(out, size + size / 64 + 16);
deflater.deflate(out, deflater.getTotalOut(), out.length deflater.deflate(out, deflater.getTotalOut(), out.length
- deflater.getTotalOut()); - deflater.getTotalOut());
assert (deflater.finished()); if (!deflater.finished()) {
throw new Error("Internal error in compressor");
}
} }
ByteString compressed = ByteString.copyFrom(out, 0, deflater ByteString compressed = ByteString.copyFrom(out, 0, deflater
.getTotalOut()); .getTotalOut());