Index: FieldsWriter.java =================================================================== --- FieldsWriter.java (revision 157812) +++ FieldsWriter.java (working copy) @@ -82,7 +82,7 @@ byte[] data = null; // check if it is a binary field if (field.isBinary()) { - data = compress(field.binaryValue()); + data = compress(field.binaryValue(), field.binaryLength()); } else { data = compress(field.stringValue().getBytes("UTF-8")); @@ -95,7 +95,7 @@ // compression is disabled for the current field if (field.isBinary()) { byte[] data = field.binaryValue(); - final int len = data.length; + final int len = field.binaryLength(); fieldsStream.writeVInt(len); fieldsStream.writeBytes(data, len); } @@ -108,13 +108,17 @@ } private final byte[] compress (byte[] input) { + return compress(input, input.length); + } + + private final byte[] compress(byte[] input, int length) { // Create the compressor with highest level of compression Deflater compressor = new Deflater(); compressor.setLevel(Deflater.BEST_COMPRESSION); // Give the compressor the data to compress - compressor.setInput(input); + compressor.setInput(input, 0, length); compressor.finish(); /* @@ -123,7 +127,7 @@ * there is no guarantee that the compressed data will be smaller than * the uncompressed data. */ - ByteArrayOutputStream bos = new ByteArrayOutputStream(input.length); + ByteArrayOutputStream bos = new ByteArrayOutputStream(length); // Compress the data byte[] buf = new byte[1024];