public class JavaBinCodec extends Object implements 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.
| Modifier and Type | Class and Description |
|---|---|
class |
JavaBinCodec.BinEntryWriter |
static interface |
JavaBinCodec.ObjectResolver
Allows extension of
JavaBinCodec to support serialization of arbitrary data types. |
static class |
JavaBinCodec.StringCache |
static interface |
JavaBinCodec.WritableDocFields |
| Modifier and Type | Field and Description |
|---|---|
static byte |
ARR |
static byte |
BOOL_FALSE |
static byte |
BOOL_TRUE |
static byte |
BYTE |
static byte |
BYTEARR |
protected FastOutputStream |
daos |
static byte |
DATE |
static byte |
DOUBLE |
static byte |
END |
protected static Object |
END_OBJ |
static byte |
ENUM_FIELD_VALUE |
JavaBinCodec.BinEntryWriter |
ew |
static byte |
EXTERN_STRING |
static byte |
FLOAT |
static byte |
INT |
IteratorWriter.ItemWriter |
itemWriter |
static byte |
ITERATOR |
static byte |
LONG |
static byte |
MAP |
static byte |
MAP_ENTRY |
static byte |
MAP_ENTRY_ITER |
static byte |
NAMED_LST |
static byte |
NULL |
static byte |
ORDERED_MAP |
protected boolean |
readStringAsCharSeq |
static byte |
SHORT |
static byte |
SINT |
static byte |
SLONG |
static byte |
SOLRDOC |
static byte |
SOLRDOCLST |
static byte |
SOLRINPUTDOC |
static byte |
STR |
static byte |
TAG_AND_LEN |
protected byte |
tagByte |
static byte |
UUID |
| Constructor and Description |
|---|
JavaBinCodec() |
JavaBinCodec(JavaBinCodec.ObjectResolver resolver) |
JavaBinCodec(JavaBinCodec.ObjectResolver resolver,
JavaBinCodec.StringCache stringCache) |
JavaBinCodec(OutputStream os,
JavaBinCodec.ObjectResolver resolver)
Use this to use this as a PushWriter.
|
public static final byte NULL
public static final byte BOOL_TRUE
public static final byte BOOL_FALSE
public static final byte BYTE
public static final byte SHORT
public static final byte DOUBLE
public static final byte INT
public static final byte LONG
public static final byte FLOAT
public static final byte DATE
public static final byte MAP
public static final byte SOLRDOC
public static final byte SOLRDOCLST
public static final byte BYTEARR
public static final byte ITERATOR
public static final byte END
public static final byte SOLRINPUTDOC
public static final byte MAP_ENTRY_ITER
public static final byte ENUM_FIELD_VALUE
public static final byte MAP_ENTRY
public static final byte UUID
public static final byte TAG_AND_LEN
public static final byte STR
public static final byte SINT
public static final byte SLONG
public static final byte ARR
public static final byte ORDERED_MAP
public static final byte NAMED_LST
public static final byte EXTERN_STRING
protected FastOutputStream daos
protected boolean readStringAsCharSeq
protected static final Object END_OBJ
protected byte tagByte
public final JavaBinCodec.BinEntryWriter ew
public final IteratorWriter.ItemWriter itemWriter
public JavaBinCodec()
public JavaBinCodec(OutputStream os, JavaBinCodec.ObjectResolver resolver) throws IOException
os - The output streamIOExceptionpublic JavaBinCodec(JavaBinCodec.ObjectResolver resolver)
public JavaBinCodec(JavaBinCodec.ObjectResolver resolver, JavaBinCodec.StringCache stringCache)
public JavaBinCodec setReadStringAsCharSeq(boolean flag)
public JavaBinCodec setWritableDocFields(JavaBinCodec.WritableDocFields writableDocFields)
public JavaBinCodec.ObjectResolver getResolver()
public void marshal(Object nl, OutputStream os) throws IOException
IOExceptionprotected void initWrite(OutputStream os) throws IOException
IOExceptionpublic void init(FastOutputStream os)
public Object unmarshal(byte[] buf) throws IOException
IOExceptionpublic Object unmarshal(InputStream is) throws IOException
IOExceptionprotected FastInputStream initRead(InputStream is) throws IOException
IOExceptionprotected FastInputStream initRead(byte[] buf) throws IOException
IOExceptionprotected FastInputStream _init(FastInputStream dis) throws IOException
IOExceptionpublic SimpleOrderedMap<Object> readOrderedMap(DataInputInputStream dis) throws IOException
IOExceptionpublic NamedList<Object> readNamedList(DataInputInputStream dis) throws IOException
IOExceptionpublic void writeNamedList(NamedList<?> nl) throws IOException
IOExceptionpublic void writeVal(Object val) throws IOException
IOExceptionpublic Object readVal(DataInputInputStream dis) throws IOException
IOExceptionprotected Object readObject(DataInputInputStream dis) throws IOException
IOExceptionpublic boolean writeKnownType(Object val) throws IOException
IOExceptionpublic void writeMap(MapWriter val) throws IOException
PushWriterwriteMap in interface PushWriterIOExceptionpublic void writeTag(byte tag)
throws IOException
IOExceptionpublic void writeTag(byte tag,
int size)
throws IOException
IOExceptionpublic void writeByteArray(byte[] arr,
int offset,
int len)
throws IOException
IOExceptionpublic byte[] readByteArray(DataInputInputStream dis) throws IOException
IOExceptionpublic void writeSolrDocument(SolrDocument doc) throws IOException
IOExceptionprotected boolean toWrite(String key)
public SolrDocument readSolrDocument(DataInputInputStream dis) throws IOException
IOExceptionpublic SolrDocumentList readSolrDocumentList(DataInputInputStream dis) throws IOException
IOExceptionpublic void writeSolrDocumentList(SolrDocumentList docs) throws IOException
IOExceptionpublic SolrInputDocument readSolrInputDocument(DataInputInputStream dis) throws IOException
IOExceptionprotected SolrInputDocument createSolrInputDocument(int sz)
public void writeSolrInputDocument(SolrInputDocument sdoc) throws IOException
IOExceptionpublic Map<Object,Object> readMapIter(DataInputInputStream dis) throws IOException
IOExceptionprotected Map<Object,Object> newMap(int size)
size - expected size, -1 means unknown sizepublic Map<Object,Object> readMap(DataInputInputStream dis) throws IOException
IOExceptionprotected Map<Object,Object> readMap(DataInputInputStream dis, int sz) throws IOException
IOExceptionpublic void writeIterator(IteratorWriter val) throws IOException
PushWriterwriteIterator in interface PushWriterIOExceptionpublic void writeIterator(Iterator iter) throws IOException
IOExceptionpublic List<Object> readIterator(DataInputInputStream fis) throws IOException
IOExceptionpublic void writeArray(List l) throws IOException
IOExceptionpublic void writeArray(Collection coll) throws IOException
IOExceptionpublic void writeArray(Object[] arr) throws IOException
IOExceptionpublic List<Object> readArray(DataInputInputStream dis) throws IOException
IOExceptionprotected List readArray(DataInputInputStream dis, int sz) throws IOException
IOExceptionpublic void writeEnumFieldValue(EnumFieldValue enumFieldValue) throws IOException
EnumFieldValue as tag+int value+string valueenumFieldValue - to writeIOExceptionpublic void writeMapEntry(Map.Entry<?,?> val) throws IOException
IOExceptionpublic EnumFieldValue readEnumFieldValue(DataInputInputStream dis) throws IOException
EnumFieldValue (int+string) from input streamdis - data input streamEnumFieldValueIOExceptionpublic Map.Entry<Object,Object> readMapEntry(DataInputInputStream dis) throws IOException
IOExceptionpublic void writeStr(CharSequence s) throws IOException
IOExceptionpublic CharSequence readStr(DataInputInputStream dis) throws IOException
IOExceptionpublic CharSequence readStr(DataInputInputStream dis, JavaBinCodec.StringCache stringCache, boolean readStringAsCharSeq) throws IOException
IOExceptionprotected CharSequence readUtf8(DataInputInputStream dis) throws IOException
IOExceptionprotected CharSequence readUtf8(DataInputInputStream dis, int sz) throws IOException
IOExceptionpublic void writeInt(int val)
throws IOException
IOExceptionpublic int readSmallInt(DataInputInputStream dis) throws IOException
IOExceptionpublic void writeLong(long val)
throws IOException
IOExceptionpublic long readSmallLong(DataInputInputStream dis) throws IOException
IOExceptionpublic void writeFloat(float val)
throws IOException
IOExceptionpublic boolean writePrimitive(Object val) throws IOException
IOExceptionprotected void writeBoolean(boolean val)
throws IOException
IOExceptionprotected void writeDouble(double val)
throws IOException
IOExceptionpublic void writeMap(Map<?,?> val) throws IOException
IOExceptionpublic int readSize(DataInputInputStream in) throws IOException
IOExceptionpublic static void writeVInt(int i,
FastOutputStream out)
throws IOException
IOException - If there is a low-level I/O error.public static int readVInt(DataInputInputStream in) throws IOException
writeVInt(int, FastOutputStream)IOException - If there is a low-level I/O error.public static void writeVLong(long i,
FastOutputStream out)
throws IOException
IOExceptionpublic static long readVLong(DataInputInputStream in) throws IOException
IOExceptionpublic void writeExternString(CharSequence s) throws IOException
IOExceptionpublic CharSequence readExternString(DataInputInputStream fis) throws IOException
IOExceptionpublic void writeUTF8Str(Utf8CharSequence utf8) throws IOException
IOExceptionpublic long getTotalBytesWritten()
public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionCopyright © 2000-2020 Apache Software Foundation. All Rights Reserved.