Class JavaBinCodec
- java.lang.Object
- 
- org.apache.solr.common.util.JavaBinCodec
 
- 
- All Implemented Interfaces:
- Closeable,- AutoCloseable,- PushWriter
 - Direct Known Subclasses:
- JavabinTupleStreamParser
 
 public class JavaBinCodec extends Object implements PushWriter Defines a space-efficient serialization/deserialization format for transferring data.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.ObjectResolverobject that knows how to work with the unsupported class. This allowsJavaBinCodecto be used to marshall/unmarshall arbitrary content.NOTE -- JavaBinCodecinstances cannot be reused for more than one marshall or unmarshall operation.
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description classJavaBinCodec.BinEntryWriterstatic interfaceJavaBinCodec.ObjectResolverAllows extension ofJavaBinCodecto support serialization of arbitrary data types.static classJavaBinCodec.StringBytesstatic classJavaBinCodec.StringCachestatic interfaceJavaBinCodec.WritableDocFields
 - 
Field SummaryFields Modifier and Type Field Description static byteARRstatic byteBOOL_FALSEstatic byteBOOL_TRUEstatic byteBYTEstatic byteBYTEARRprotected FastOutputStreamdaosstatic byteDATEstatic byteDOUBLEstatic byteENDprotected static ObjectEND_OBJstatic byteENUM_FIELD_VALUEJavaBinCodec.BinEntryWriterewstatic byteEXTERN_STRINGstatic byteFLOATstatic byteINTIteratorWriter.ItemWriteritemWriterstatic byteITERATORstatic byteLONGstatic byteMAPstatic byteMAP_ENTRYstatic byteMAP_ENTRY_ITERstatic byteNAMED_LSTstatic byteNULLstatic byteORDERED_MAPprotected booleanreadStringAsCharSeqstatic byteSHORTstatic byteSINTstatic byteSLONGstatic byteSOLRDOCstatic byteSOLRDOCLSTstatic byteSOLRINPUTDOCstatic byteSTRstatic byteTAG_AND_LENprotected bytetagByte
 - 
Constructor SummaryConstructors Constructor Description JavaBinCodec()JavaBinCodec(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
 
- 
- 
- 
Field Detail- 
NULLpublic static final byte NULL - See Also:
- Constant Field Values
 
 - 
BOOL_TRUEpublic static final byte BOOL_TRUE - See Also:
- Constant Field Values
 
 - 
BOOL_FALSEpublic static final byte BOOL_FALSE - See Also:
- Constant Field Values
 
 - 
BYTEpublic static final byte BYTE - See Also:
- Constant Field Values
 
 - 
SHORTpublic static final byte SHORT - See Also:
- Constant Field Values
 
 - 
DOUBLEpublic static final byte DOUBLE - See Also:
- Constant Field Values
 
 - 
INTpublic static final byte INT - See Also:
- Constant Field Values
 
 - 
LONGpublic static final byte LONG - See Also:
- Constant Field Values
 
 - 
FLOATpublic static final byte FLOAT - See Also:
- Constant Field Values
 
 - 
DATEpublic static final byte DATE - See Also:
- Constant Field Values
 
 - 
MAPpublic static final byte MAP - See Also:
- Constant Field Values
 
 - 
SOLRDOCpublic static final byte SOLRDOC - See Also:
- Constant Field Values
 
 - 
SOLRDOCLSTpublic static final byte SOLRDOCLST - See Also:
- Constant Field Values
 
 - 
BYTEARRpublic static final byte BYTEARR - See Also:
- Constant Field Values
 
 - 
ITERATORpublic static final byte ITERATOR - See Also:
- Constant Field Values
 
 - 
ENDpublic static final byte END - See Also:
- Constant Field Values
 
 - 
SOLRINPUTDOCpublic static final byte SOLRINPUTDOC - See Also:
- Constant Field Values
 
 - 
MAP_ENTRY_ITERpublic static final byte MAP_ENTRY_ITER - See Also:
- Constant Field Values
 
 - 
ENUM_FIELD_VALUEpublic static final byte ENUM_FIELD_VALUE - See Also:
- Constant Field Values
 
 - 
MAP_ENTRYpublic static final byte MAP_ENTRY - See Also:
- Constant Field Values
 
 - 
TAG_AND_LENpublic static final byte TAG_AND_LEN - See Also:
- Constant Field Values
 
 - 
STRpublic static final byte STR - See Also:
- Constant Field Values
 
 - 
SINTpublic static final byte SINT - See Also:
- Constant Field Values
 
 - 
SLONGpublic static final byte SLONG - See Also:
- Constant Field Values
 
 - 
ARRpublic static final byte ARR - See Also:
- Constant Field Values
 
 - 
ORDERED_MAPpublic static final byte ORDERED_MAP - See Also:
- Constant Field Values
 
 - 
NAMED_LSTpublic static final byte NAMED_LST - See Also:
- Constant Field Values
 
 - 
EXTERN_STRINGpublic static final byte EXTERN_STRING - See Also:
- Constant Field Values
 
 - 
daosprotected FastOutputStream daos 
 - 
readStringAsCharSeqprotected boolean readStringAsCharSeq 
 - 
END_OBJprotected static final Object END_OBJ 
 - 
tagByteprotected byte tagByte 
 - 
ewpublic final JavaBinCodec.BinEntryWriter ew 
 - 
itemWriterpublic final IteratorWriter.ItemWriter itemWriter 
 
- 
 - 
Constructor Detail- 
JavaBinCodecpublic JavaBinCodec() 
 - 
JavaBinCodecpublic JavaBinCodec(OutputStream os, JavaBinCodec.ObjectResolver resolver) throws IOException Use this to use this as a PushWriter. ensure that close() is called explicitly after use- Parameters:
- os- The output stream
- Throws:
- IOException
 
 - 
JavaBinCodecpublic JavaBinCodec(JavaBinCodec.ObjectResolver resolver) 
 - 
JavaBinCodecpublic JavaBinCodec(JavaBinCodec.ObjectResolver resolver, JavaBinCodec.StringCache stringCache) 
 
- 
 - 
Method Detail- 
setReadStringAsCharSeqpublic JavaBinCodec setReadStringAsCharSeq(boolean flag) 
 - 
setWritableDocFieldspublic JavaBinCodec setWritableDocFields(JavaBinCodec.WritableDocFields writableDocFields) 
 - 
getResolverpublic JavaBinCodec.ObjectResolver getResolver() 
 - 
marshalpublic void marshal(Object nl, OutputStream os) throws IOException - Throws:
- IOException
 
 - 
initWriteprotected void initWrite(OutputStream os) throws IOException - Throws:
- IOException
 
 - 
initpublic void init(FastOutputStream os) expert: sets a new output stream
 - 
unmarshalpublic Object unmarshal(byte[] buf) throws IOException - Throws:
- IOException
 
 - 
unmarshalpublic Object unmarshal(InputStream is) throws IOException - Throws:
- IOException
 
 - 
initReadprotected FastInputStream initRead(InputStream is) throws IOException - Throws:
- IOException
 
 - 
initReadprotected FastInputStream initRead(byte[] buf) throws IOException - Throws:
- IOException
 
 - 
readOrderedMappublic SimpleOrderedMap<Object> readOrderedMap(DataInputInputStream dis) throws IOException - Throws:
- IOException
 
 - 
readNamedListpublic NamedList<Object> readNamedList(DataInputInputStream dis) throws IOException - Throws:
- IOException
 
 - 
writeNamedListpublic void writeNamedList(NamedList<?> nl) throws IOException - Throws:
- IOException
 
 - 
writeValpublic void writeVal(Object val) throws IOException - Throws:
- IOException
 
 - 
readValpublic Object readVal(DataInputInputStream dis) throws IOException - Throws:
- IOException
 
 - 
readObjectprotected Object readObject(DataInputInputStream dis) throws IOException - Throws:
- IOException
 
 - 
writeKnownTypepublic boolean writeKnownType(Object val) throws IOException - Throws:
- IOException
 
 - 
writeMappublic void writeMap(MapWriter val) throws IOException 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 interface- PushWriter
- Throws:
- IOException
 
 - 
writeTagpublic void writeTag(byte tag) throws IOException- Throws:
- IOException
 
 - 
writeTagpublic void writeTag(byte tag, int size) throws IOException- Throws:
- IOException
 
 - 
writeByteArraypublic void writeByteArray(byte[] arr, int offset, int len) throws IOException- Throws:
- IOException
 
 - 
readByteArraypublic byte[] readByteArray(DataInputInputStream dis) throws IOException - Throws:
- IOException
 
 - 
writeSolrDocumentpublic void writeSolrDocument(SolrDocument doc) throws IOException - Throws:
- IOException
 
 - 
toWriteprotected boolean toWrite(String key) 
 - 
readSolrDocumentpublic SolrDocument readSolrDocument(DataInputInputStream dis) throws IOException - Throws:
- IOException
 
 - 
readSolrDocumentListpublic SolrDocumentList readSolrDocumentList(DataInputInputStream dis) throws IOException - Throws:
- IOException
 
 - 
writeSolrDocumentListpublic void writeSolrDocumentList(SolrDocumentList docs) throws IOException - Throws:
- IOException
 
 - 
readSolrInputDocumentpublic SolrInputDocument readSolrInputDocument(DataInputInputStream dis) throws IOException - Throws:
- IOException
 
 - 
createSolrInputDocumentprotected SolrInputDocument createSolrInputDocument(int sz) 
 - 
writeSolrInputDocumentpublic void writeSolrInputDocument(SolrInputDocument sdoc) throws IOException - Throws:
- IOException
 
 - 
readMapIterpublic Map<Object,Object> readMapIter(DataInputInputStream dis) throws IOException - Throws:
- IOException
 
 - 
newMapprotected Map<Object,Object> newMap(int size) create a new Map object- Parameters:
- size- expected size, -1 means unknown size
 
 - 
readMappublic Map<Object,Object> readMap(DataInputInputStream dis) throws IOException - Throws:
- IOException
 
 - 
writeIteratorpublic void writeIterator(IteratorWriter val) throws IOException 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 interface- PushWriter
- Throws:
- IOException
 
 - 
writeIteratorpublic void writeIterator(Iterator iter) throws IOException - Throws:
- IOException
 
 - 
readIteratorpublic List<Object> readIterator(DataInputInputStream fis) throws IOException - Throws:
- IOException
 
 - 
writeArraypublic void writeArray(List l) throws IOException - Throws:
- IOException
 
 - 
writeArraypublic void writeArray(Collection coll) throws IOException - Throws:
- IOException
 
 - 
writeArraypublic void writeArray(Object[] arr) throws IOException - Throws:
- IOException
 
 - 
readArraypublic List<Object> readArray(DataInputInputStream dis) throws IOException - Throws:
- IOException
 
 - 
writeEnumFieldValuepublic void writeEnumFieldValue(EnumFieldValue enumFieldValue) throws IOException writeEnumFieldValueas tag+int value+string value- Parameters:
- enumFieldValue- to write
- Throws:
- IOException
 
 - 
writeMapEntrypublic void writeMapEntry(Map.Entry<Object,Object> val) throws IOException - Throws:
- IOException
 
 - 
readEnumFieldValuepublic EnumFieldValue readEnumFieldValue(DataInputInputStream dis) throws IOException readEnumFieldValue(int+string) from input stream- Parameters:
- dis- data input stream
- Returns:
- EnumFieldValue
- Throws:
- IOException
 
 - 
readMapEntrypublic Map.Entry<Object,Object> readMapEntry(DataInputInputStream dis) throws IOException - Throws:
- IOException
 
 - 
writeStrpublic void writeStr(CharSequence s) throws IOException write the string as tag+length, with length being the number of UTF-8 bytes- Throws:
- IOException
 
 - 
readStrpublic CharSequence readStr(DataInputInputStream dis) throws IOException - Throws:
- IOException
 
 - 
readStrpublic CharSequence readStr(DataInputInputStream dis, JavaBinCodec.StringCache stringCache, boolean readStringAsCharSeq) throws IOException - Throws:
- IOException
 
 - 
readUtf8protected CharSequence readUtf8(DataInputInputStream dis) throws IOException - Throws:
- IOException
 
 - 
writeIntpublic void writeInt(int val) throws IOException- Throws:
- IOException
 
 - 
readSmallIntpublic int readSmallInt(DataInputInputStream dis) throws IOException - Throws:
- IOException
 
 - 
writeLongpublic void writeLong(long val) throws IOException- Throws:
- IOException
 
 - 
readSmallLongpublic long readSmallLong(DataInputInputStream dis) throws IOException - Throws:
- IOException
 
 - 
writeFloatpublic void writeFloat(float val) throws IOException- Throws:
- IOException
 
 - 
writePrimitivepublic boolean writePrimitive(Object val) throws IOException - Throws:
- IOException
 
 - 
writeBooleanprotected void writeBoolean(boolean val) throws IOException- Throws:
- IOException
 
 - 
writeDoubleprotected void writeDouble(double val) throws IOException- Throws:
- IOException
 
 - 
writeMappublic void writeMap(Map<?,?> val) throws IOException - Throws:
- IOException
 
 - 
readSizepublic int readSize(DataInputInputStream in) throws IOException - Throws:
- IOException
 
 - 
writeVIntpublic static void writeVInt(int i, FastOutputStream out) throws IOExceptionSpecial 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.
 
 - 
readVIntpublic static int readVInt(DataInputInputStream in) throws IOException The counterpart forwriteVInt(int, FastOutputStream)- Throws:
- IOException- If there is a low-level I/O error.
 
 - 
writeVLongpublic static void writeVLong(long i, FastOutputStream out) throws IOException- Throws:
- IOException
 
 - 
readVLongpublic static long readVLong(DataInputInputStream in) throws IOException - Throws:
- IOException
 
 - 
writeExternStringpublic void writeExternString(CharSequence s) throws IOException - Throws:
- IOException
 
 - 
readExternStringpublic CharSequence readExternString(DataInputInputStream fis) throws IOException - Throws:
- IOException
 
 - 
writeUTF8Strpublic void writeUTF8Str(Utf8CharSequence utf8) throws IOException - Throws:
- IOException
 
 - 
getTotalBytesWrittenpublic long getTotalBytesWritten() 
 - 
closepublic void close() throws IOException- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
- Throws:
- IOException
 
 
- 
 
-