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 streamIOException
public 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
IOException
protected void initWrite(OutputStream os) throws IOException
IOException
public void init(FastOutputStream os)
public Object unmarshal(byte[] buf) throws IOException
IOException
public Object unmarshal(InputStream is) throws IOException
IOException
protected FastInputStream initRead(InputStream is) throws IOException
IOException
protected FastInputStream initRead(byte[] buf) throws IOException
IOException
protected FastInputStream _init(FastInputStream dis) throws IOException
IOException
public SimpleOrderedMap<Object> readOrderedMap(DataInputInputStream dis) throws IOException
IOException
public NamedList<Object> readNamedList(DataInputInputStream dis) throws IOException
IOException
public void writeNamedList(NamedList<?> nl) throws IOException
IOException
public void writeVal(Object val) throws IOException
IOException
public Object readVal(DataInputInputStream dis) throws IOException
IOException
protected Object readObject(DataInputInputStream dis) throws IOException
IOException
public boolean writeKnownType(Object val) throws IOException
IOException
public void writeMap(MapWriter val) throws IOException
PushWriter
writeMap
in interface PushWriter
IOException
public void writeTag(byte tag) throws IOException
IOException
public void writeTag(byte tag, int size) throws IOException
IOException
public void writeByteArray(byte[] arr, int offset, int len) throws IOException
IOException
public byte[] readByteArray(DataInputInputStream dis) throws IOException
IOException
public void writeSolrDocument(SolrDocument doc) throws IOException
IOException
protected boolean toWrite(String key)
public SolrDocument readSolrDocument(DataInputInputStream dis) throws IOException
IOException
public SolrDocumentList readSolrDocumentList(DataInputInputStream dis) throws IOException
IOException
public void writeSolrDocumentList(SolrDocumentList docs) throws IOException
IOException
public SolrInputDocument readSolrInputDocument(DataInputInputStream dis) throws IOException
IOException
protected SolrInputDocument createSolrInputDocument(int sz)
public void writeSolrInputDocument(SolrInputDocument sdoc) throws IOException
IOException
public Map<Object,Object> readMapIter(DataInputInputStream dis) throws IOException
IOException
protected Map<Object,Object> newMap(int size)
size
- expected size, -1 means unknown sizepublic Map<Object,Object> readMap(DataInputInputStream dis) throws IOException
IOException
protected Map<Object,Object> readMap(DataInputInputStream dis, int sz) throws IOException
IOException
public void writeIterator(IteratorWriter val) throws IOException
PushWriter
writeIterator
in interface PushWriter
IOException
public void writeIterator(Iterator iter) throws IOException
IOException
public List<Object> readIterator(DataInputInputStream fis) throws IOException
IOException
public void writeArray(List l) throws IOException
IOException
public void writeArray(Collection coll) throws IOException
IOException
public void writeArray(Object[] arr) throws IOException
IOException
public List<Object> readArray(DataInputInputStream dis) throws IOException
IOException
protected List readArray(DataInputInputStream dis, int sz) throws IOException
IOException
public void writeEnumFieldValue(EnumFieldValue enumFieldValue) throws IOException
EnumFieldValue
as tag+int value+string valueenumFieldValue
- to writeIOException
public void writeMapEntry(Map.Entry<?,?> val) throws IOException
IOException
public EnumFieldValue readEnumFieldValue(DataInputInputStream dis) throws IOException
EnumFieldValue
(int+string) from input streamdis
- data input streamEnumFieldValue
IOException
public Map.Entry<Object,Object> readMapEntry(DataInputInputStream dis) throws IOException
IOException
public void writeStr(CharSequence s) throws IOException
IOException
public CharSequence readStr(DataInputInputStream dis) throws IOException
IOException
public CharSequence readStr(DataInputInputStream dis, JavaBinCodec.StringCache stringCache, boolean readStringAsCharSeq) throws IOException
IOException
protected CharSequence readUtf8(DataInputInputStream dis) throws IOException
IOException
protected CharSequence readUtf8(DataInputInputStream dis, int sz) throws IOException
IOException
public void writeInt(int val) throws IOException
IOException
public int readSmallInt(DataInputInputStream dis) throws IOException
IOException
public void writeLong(long val) throws IOException
IOException
public long readSmallLong(DataInputInputStream dis) throws IOException
IOException
public void writeFloat(float val) throws IOException
IOException
public boolean writePrimitive(Object val) throws IOException
IOException
protected void writeBoolean(boolean val) throws IOException
IOException
protected void writeDouble(double val) throws IOException
IOException
public void writeMap(Map<?,?> val) throws IOException
IOException
public int readSize(DataInputInputStream in) throws IOException
IOException
public 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
IOException
public static long readVLong(DataInputInputStream in) throws IOException
IOException
public void writeExternString(CharSequence s) throws IOException
IOException
public CharSequence readExternString(DataInputInputStream fis) throws IOException
IOException
public void writeUTF8Str(Utf8CharSequence utf8) throws IOException
IOException
public long getTotalBytesWritten()
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
Copyright © 2000-2020 Apache Software Foundation. All Rights Reserved.