fix for NPE in BLOBCompressor

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5388 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 16 years ago
parent 5b94498643
commit 7cd08bd5fb

@ -120,6 +120,7 @@ public class kelondroBLOBCompressor extends Thread implements kelondroBLOB {
private byte[] decompress(byte[] b) {
// use a magic in the head of the bytes to identify compression type
if (b == null) return null;
if (kelondroByteArray.equals(b, gzipMagic)) {
//System.out.print("\\"); // DEBUG
cdr--;
@ -194,7 +195,10 @@ public class kelondroBLOBCompressor extends Thread implements kelondroBLOB {
public synchronized long length(byte[] key) throws IOException {
byte[] b = buffer.get(new String(key));
if (b != null) return b.length;
return decompress(this.backend.get(key)).length;
b = this.backend.get(key);
if (b == null) return 0;
b = decompress(b);
return (b == null) ? 0 : b.length;
}
private int removeFromQueues(byte[] key) throws IOException {

@ -170,13 +170,11 @@ public class kelondroByteArray {
}
public static boolean equals(final byte[] buffer, final byte[] pattern) {
return equals(buffer, 0, pattern);
}
public static boolean equals(final byte[] buffer, final int offset, final byte[] pattern) {
// compares two byte arrays: true, if pattern appears completely at offset position
if (buffer.length < offset + pattern.length) return false;
for (int i = 0; i < pattern.length; i++) if (buffer[offset + i] != pattern[i]) return false;
if (buffer == null && pattern == null) return true;
if (buffer == null || pattern == null) return false;
if (buffer.length < pattern.length) return false;
for (int i = 0; i < pattern.length; i++) if (buffer[i] != pattern[i]) return false;
return true;
}

Loading…
Cancel
Save