@Override public BytesRef buildPayload(BytesRef surfaceForm, long weight, BytesRef payload) throws IOException { if (weight < -1 || weight > Integer.MAX_VALUE) { throw new IllegalArgumentException("weight must be >= -1 && <= Integer.MAX_VALUE"); } for (int i = 0; i < surfaceForm.length; i++) { if (surfaceForm.bytes[i] == UNIT_SEPARATOR) { throw new IllegalArgumentException( "surface form cannot contain unit separator character U+001F; this character is reserved"); } } ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); OutputStreamDataOutput output = new OutputStreamDataOutput(byteArrayOutputStream); output.writeVLong(weight + 1); output.writeVInt(surfaceForm.length); output.writeBytes(surfaceForm.bytes, surfaceForm.offset, surfaceForm.length); output.writeVInt(payload.length); output.writeBytes(payload.bytes, 0, payload.length); output.close(); return new BytesRef(byteArrayOutputStream.toByteArray()); }
@Override public BytesRef buildPayload(BytesRef surfaceForm, long weight, BytesRef payload) throws IOException { if (weight < -1 || weight > Integer.MAX_VALUE) { throw new IllegalArgumentException("weight must be >= -1 && <= Integer.MAX_VALUE"); } for (int i = 0; i < surfaceForm.length; i++) { if (surfaceForm.bytes[i] == UNIT_SEPARATOR) { throw new IllegalArgumentException( "surface form cannot contain unit separator character U+001F; this character is reserved"); } } ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); OutputStreamDataOutput output = new OutputStreamDataOutput(byteArrayOutputStream); output.writeVLong(weight + 1); output.writeVInt(surfaceForm.length); output.writeBytes(surfaceForm.bytes, surfaceForm.offset, surfaceForm.length); output.writeVInt(payload.length); output.writeBytes(payload.bytes, 0, payload.length); output.close(); return new BytesRef(byteArrayOutputStream.toByteArray()); }
@Override public BytesRef buildPayload(BytesRef surfaceForm, long weight, BytesRef payload) throws IOException { if (weight < -1 || weight > Integer.MAX_VALUE) { throw new IllegalArgumentException("weight must be >= -1 && <= Integer.MAX_VALUE"); } for (int i = 0; i < surfaceForm.length; i++) { if (surfaceForm.bytes[i] == UNIT_SEPARATOR) { throw new IllegalArgumentException( "surface form cannot contain unit separator character U+001F; this character is reserved"); } } ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); OutputStreamDataOutput output = new OutputStreamDataOutput(byteArrayOutputStream); output.writeVLong(weight + 1); output.writeVInt(surfaceForm.length); output.writeBytes(surfaceForm.bytes, surfaceForm.offset, surfaceForm.length); output.writeVInt(payload.length); output.writeBytes(payload.bytes, 0, payload.length); output.close(); return new BytesRef(byteArrayOutputStream.toByteArray()); }