Class JavaBinCodec
- All Implemented Interfaces:
Closeable,AutoCloseable,PushWriter
JavaBinCodec has built in support many commonly used types. This includes primitive types
(boolean, byte, short, double, int, long, float), common Java containers/utilities (Date, Map,
Collection, Iterator, String, Object[], byte[]), and frequently used Solr types (NamedList, SolrDocument, SolrDocumentList). Each of the above types has a pair
of associated methods which read and write that type to a stream.
Classes that aren't supported natively can still be serialized/deserialized by providing an
JavaBinCodec.ObjectResolver object that knows how to work with the unsupported class.
This allows JavaBinCodec to be used to marshall/unmarshall arbitrary content.
NOTE -- JavaBinCodec instances cannot be reused for more than one marshall or
unmarshall operation.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassstatic interfaceAllows extension ofJavaBinCodecto support serialization of arbitrary data types.static classstatic interface -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final bytestatic final bytestatic final bytestatic final bytestatic final byteprotected FastOutputStreamstatic final bytestatic final bytestatic final byteprotected static final Objectstatic final bytestatic final bytestatic final bytestatic final bytestatic final bytestatic final bytestatic final bytestatic final bytestatic final bytestatic final bytestatic final bytestatic final bytestatic final byteprotected booleanstatic final bytestatic final bytestatic final bytestatic final bytestatic final bytestatic final bytestatic final bytestatic final byteprotected bytestatic final byte -
Constructor Summary
ConstructorsConstructorDescriptionJavaBinCodec(OutputStream os, JavaBinCodec.ObjectResolver resolver) Use this to use this as a PushWriter.JavaBinCodec(JavaBinCodec.ObjectResolver resolver) JavaBinCodec(JavaBinCodec.ObjectResolver resolver, JavaBinCodec.StringCache stringCache) -
Method Summary
Modifier and TypeMethodDescriptionprotected FastInputStream_init(FastInputStream dis) voidclose()protected SolrInputDocumentcreateSolrInputDocument(int sz) longvoidinit(FastOutputStream os) expert: sets a new output streamprotected FastInputStreaminitRead(byte[] buf) protected FastInputStreaminitRead(InputStream is) protected voidvoidmarshal(Object nl, OutputStream os) newMap(int size) create a new Map objectprotected ListreadArray(DataInputInputStream dis, int sz) byte[]readEnumFieldValue(int+string) from input streamreadMap(DataInputInputStream dis, int sz) voidreadMapAsNamedList(boolean readMapAsNamedList) If set, Maps will be deserialized asSimpleOrderedMapinstead ofLinkedHashMapprotected ObjectintintlongreadStr(DataInputInputStream dis, JavaBinCodec.StringCache stringCache, boolean readStringAsCharSeq) protected CharSequenceprotected CharSequencereadUtf8(DataInputInputStream dis, int sz) static intThe counterpart forwriteVInt(int, FastOutputStream)static longsetReadStringAsCharSeq(boolean flag) setWritableDocFields(JavaBinCodec.WritableDocFields writableDocFields) protected booleanunmarshal(byte[] buf) unmarshal(InputStream is) voidwriteArray(Object[] arr) voidwriteArray(Collection<?> coll) voidwriteArray(List<?> l) voidwriteBoolArr(boolean[] vals) protected voidwriteBoolean(boolean val) voidwriteByteArray(byte[] arr, int offset, int len) protected voidwriteDouble(double val) voidwriteDoubleArr(double[] vals) voidwriteEnumFieldValue(EnumFieldValue enumFieldValue) writeEnumFieldValueas tag+int value+string valuevoidvoidwriteFloat(float val) voidwriteFloatArr(float[] vals) voidwriteInt(int val) voidwriteIntArr(int[] vals) voidwriteIterator(Iterator<?> iter) voidWrite an array.booleanwriteKnownType(Object val) voidwriteLong(long val) voidwriteLongArr(long[] vals) voidvoidWrite a Map.voidwriteMapEntry(Map.Entry<?, ?> val) voidwriteNamedList(NamedList<?> nl) booleanwritePrimitive(Object val) voidwritePrimitiveArrHeader(byte tag, int len) voidwriteShortArr(short[] vals) voidvoidvoidvoidwrite the string as tag+length, with length being the number of UTF-8 bytesvoidwriteTag(byte tag) voidwriteTag(byte tag, int size) voidwriteUTF8Str(Utf8CharSequence utf8) voidstatic voidwriteVInt(int i, FastOutputStream out) Special method for variable length int (copied from lucene).static voidwriteVLong(long i, FastOutputStream out)
-
Field Details
-
NULL
public static final byte NULL- See Also:
-
BOOL_TRUE
public static final byte BOOL_TRUE- See Also:
-
BOOL_FALSE
public static final byte BOOL_FALSE- See Also:
-
BYTE
public static final byte BYTE- See Also:
-
SHORT
public static final byte SHORT- See Also:
-
DOUBLE
public static final byte DOUBLE- See Also:
-
INT
public static final byte INT- See Also:
-
LONG
public static final byte LONG- See Also:
-
FLOAT
public static final byte FLOAT- See Also:
-
DATE
public static final byte DATE- See Also:
-
MAP
public static final byte MAP- See Also:
-
SOLRDOC
public static final byte SOLRDOC- See Also:
-
SOLRDOCLST
public static final byte SOLRDOCLST- See Also:
-
BYTEARR
public static final byte BYTEARR- See Also:
-
ITERATOR
public static final byte ITERATOR- See Also:
-
END
public static final byte END- See Also:
-
SOLRINPUTDOC
public static final byte SOLRINPUTDOC- See Also:
-
MAP_ENTRY_ITER
public static final byte MAP_ENTRY_ITER- See Also:
-
ENUM_FIELD_VALUE
public static final byte ENUM_FIELD_VALUE- See Also:
-
MAP_ENTRY
public static final byte MAP_ENTRY- See Also:
-
UUID
public static final byte UUID- See Also:
-
PRIMITIVE_ARR
public static final byte PRIMITIVE_ARR- See Also:
-
TAG_AND_LEN
public static final byte TAG_AND_LEN- See Also:
-
STR
public static final byte STR- See Also:
-
SINT
public static final byte SINT- See Also:
-
SLONG
public static final byte SLONG- See Also:
-
ARR
public static final byte ARR- See Also:
-
ORDERED_MAP
public static final byte ORDERED_MAP- See Also:
-
NAMED_LST
public static final byte NAMED_LST- See Also:
-
EXTERN_STRING
public static final byte EXTERN_STRING- See Also:
-
daos
-
readStringAsCharSeq
protected boolean readStringAsCharSeq -
END_OBJ
-
tagByte
protected byte tagByte -
ew
-
itemWriter
-
-
Constructor Details
-
JavaBinCodec
public JavaBinCodec() -
JavaBinCodec
Use this to use this as a PushWriter. ensure that close() is called explicitly after use- Parameters:
os- The output stream- Throws:
IOException
-
JavaBinCodec
-
JavaBinCodec
-
-
Method Details
-
setReadStringAsCharSeq
-
setWritableDocFields
-
getResolver
-
marshal
- Throws:
IOException
-
initWrite
- Throws:
IOException
-
init
expert: sets a new output stream -
unmarshal
- Throws:
IOException
-
unmarshal
- Throws:
IOException
-
initRead
- Throws:
IOException
-
initRead
- Throws:
IOException
-
_init
- Throws:
IOException
-
readOrderedMap
- Throws:
IOException
-
readNamedList
- Throws:
IOException
-
writeNamedList
- Throws:
IOException
-
writeVal
- Throws:
IOException
-
readVal
- Throws:
IOException
-
readObject
- Throws:
IOException
-
writeKnownType
- Throws:
IOException
-
readPrimitiveArray
- Throws:
IOException
-
writePrimitiveArrHeader
- Throws:
IOException
-
writeFloatArr
- Throws:
IOException
-
writeIntArr
- Throws:
IOException
-
writeDoubleArr
- Throws:
IOException
-
writeLongArr
- Throws:
IOException
-
writeBoolArr
- Throws:
IOException
-
writeShortArr
- Throws:
IOException
-
writeMap
Description copied from interface:PushWriterWrite a Map. The map is opened in the beginning of the method and closed at the end. All map entries MUST be written before this method returns- Specified by:
writeMapin interfacePushWriter- Throws:
IOException
-
writeTag
- Throws:
IOException
-
writeTag
- Throws:
IOException
-
writeByteArray
- Throws:
IOException
-
readByteArray
- Throws:
IOException
-
writeSolrDocument
- Throws:
IOException
-
toWrite
-
readSolrDocument
- Throws:
IOException
-
readSolrDocumentList
- Throws:
IOException
-
writeSolrDocumentList
- Throws:
IOException
-
readSolrInputDocument
- Throws:
IOException
-
createSolrInputDocument
-
writeSolrInputDocument
- Throws:
IOException
-
readMapIter
- Throws:
IOException
-
newMap
create a new Map object- Parameters:
size- expected size, -1 means unknown size
-
readMap
- Throws:
IOException
-
readMap
- Throws:
IOException
-
readMapAsSimpleOrderedMapForStringKeys
protected Map<?,Object> readMapAsSimpleOrderedMapForStringKeys(DataInputInputStream dis, int sz) throws IOException - Throws:
IOException
-
writeIterator
Description copied from interface:PushWriterWrite an array. The array is opened at the beginning of this method and closed at the end. All array entries must be written before this method returns- Specified by:
writeIteratorin interfacePushWriter- Throws:
IOException
-
writeIterator
- Throws:
IOException
-
readIterator
- Throws:
IOException
-
writeArray
- Throws:
IOException
-
writeArray
- Throws:
IOException
-
writeArray
- Throws:
IOException
-
readArray
- Throws:
IOException
-
readArray
- Throws:
IOException
-
writeEnumFieldValue
writeEnumFieldValueas tag+int value+string value- Parameters:
enumFieldValue- to write- Throws:
IOException
-
writeMapEntry
- Throws:
IOException
-
readEnumFieldValue
readEnumFieldValue(int+string) from input stream- Parameters:
dis- data input stream- Returns:
EnumFieldValue- Throws:
IOException
-
readMapEntry
- Throws:
IOException
-
writeStr
write the string as tag+length, with length being the number of UTF-8 bytes- Throws:
IOException
-
readStr
- Throws:
IOException
-
readStr
public CharSequence readStr(DataInputInputStream dis, JavaBinCodec.StringCache stringCache, boolean readStringAsCharSeq) throws IOException - Throws:
IOException
-
readUtf8
- Throws:
IOException
-
readUtf8
- Throws:
IOException
-
writeInt
- Throws:
IOException
-
readSmallInt
- Throws:
IOException
-
writeLong
- Throws:
IOException
-
readSmallLong
- Throws:
IOException
-
writeFloat
- Throws:
IOException
-
writePrimitive
- Throws:
IOException
-
writeBoolean
- Throws:
IOException
-
writeDouble
- Throws:
IOException
-
writeMap
- Throws:
IOException
-
readSize
- Throws:
IOException
-
writeVInt
Special method for variable length int (copied from lucene). Usually used for writing the length of a collection/array/map In most of the cases the length can be represented in one byte (length < 127) so it saves 3 bytes/object- Throws:
IOException- If there is a low-level I/O error.
-
readVInt
The counterpart forwriteVInt(int, FastOutputStream)- Throws:
IOException- If there is a low-level I/O error.
-
writeVLong
- Throws:
IOException
-
readVLong
- Throws:
IOException
-
writeExternString
- Throws:
IOException
-
readExternString
- Throws:
IOException
-
writeUTF8Str
- Throws:
IOException
-
getTotalBytesWritten
public long getTotalBytesWritten() -
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
readMapAsNamedList
public void readMapAsNamedList(boolean readMapAsNamedList) If set, Maps will be deserialized asSimpleOrderedMapinstead ofLinkedHashMap
-