Index: Field.java
===================================================================
--- Field.java (revision 157812)
+++ Field.java (working copy)
@@ -38,6 +38,8 @@
// the one and only data object for all different kind of field values
private Object fieldsData = null;
+ // if fieldsData is a byte[], then this is how many bytes in it represent the field value
+ private int fieldsDataLength;
private boolean storeTermVector = false;
private boolean storeOffsetWithTermVector = false;
@@ -261,11 +263,15 @@
* and binaryValue() must be set. */
public Reader readerValue() { try { return (Reader)fieldsData; } catch (ClassCastException ignore) { return null; } }
- /** The value of the field in Binary, or null. If null, the Reader or
- * String value is used. Exactly one of stringValue(), readerValue() and
+ /** The value of the field in Binary, or null.
+ * If this field was set with a length parameter on the binary value, then use binaryLength() also.
+ * If the value is null, the Reader or String value is used. Exactly one of stringValue(), readerValue() and
* binaryValue() must be set. */
public byte[] binaryValue() { try { return (byte[])fieldsData; } catch (ClassCastException ignore) { return null; } }
+ /** The number of bytes in a binaryValue() that hold field data. */
+ public int binaryLength() { return fieldsDataLength; }
+
/**
* Create a field by specifying its name, value and how it will
* be saved in the index. Term vectors will not be stored in the index.
@@ -398,7 +404,6 @@
this(name, string, store, index, token, false);
}
-
/**
* Create a stored field with binary value. Optionally the value may be compressed.
*
@@ -407,6 +412,19 @@
* @param store How value should be stored (compressed or not.)
*/
public Field(String name, byte[] value, Store store) {
+ this(name, value, value.length, store);
+ }
+
+
+ /**
+ * Create a stored field with binary value. Optionally the value may be compressed.
+ *
+ * @param name The name of the field
+ * @param value The byte[] holding the binary value
+ * @param length The number of bytes in value holding data
+ * @param store How value should be stored (compressed or not.)
+ */
+ public Field(String name, byte[] value, int length, Store store) {
if (name == null)
throw new IllegalArgumentException("name cannot be null");
if (value == null)
@@ -414,6 +432,7 @@
this.name = name.intern();
this.fieldsData = value;
+ this.fieldsDataLength = length;
if (store == Store.YES){
this.isStored = true;