org.apache.solr.common.util
Class JavaBinCodec

java.lang.Object
  extended by org.apache.solr.common.util.JavaBinCodec

public class JavaBinCodec
extends Object

The class is designed to optimaly serialize/deserialize any supported types in Solr response. As we know there are only a limited type of items this class can do it with very minimal amount of payload and code. There are 15 known types and if there is an object in the object tree which does not fall into these types, It must be converted to one of these. Implement an ObjectResolver and pass it over It is expected that this class is used on both end of the pipes. The class has one read method and one write method for each of the datatypes

Note -- Never re-use an instance of this class for more than one marshal or unmarshall operation. Always create a new instance.


Nested Class Summary
static interface JavaBinCodec.ObjectResolver
           
 
Field Summary
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
           
static byte EXTERN_STRING
           
static byte FLOAT
           
static byte INT
           
static byte ITERATOR
           
static byte LONG
           
static byte MAP
           
static byte MAP_ENTRY
           
static byte NAMED_LST
           
static byte NULL
           
static byte ORDERED_MAP
           
static byte SHORT
           
static byte SINT
           
static byte SLONG
           
static byte SOLRDOC
           
static byte SOLRDOCLST
           
static byte SOLRINPUTDOC
           
static byte SOLRINPUTDOC_CHILDS
           
static byte STR
           
static byte TAG_AND_LEN
           
protected  byte tagByte
           
 
Constructor Summary
JavaBinCodec()
           
JavaBinCodec(JavaBinCodec.ObjectResolver resolver)
           
 
Method Summary
 void init(FastOutputStream os)
          expert: sets a new output stream
 void marshal(Object nl, OutputStream os)
           
 List<Object> readArray(DataInputInputStream dis)
           
 byte[] readByteArray(DataInputInputStream dis)
           
 EnumFieldValue readEnumFieldValue(DataInputInputStream dis)
          read EnumFieldValue (int+string) from input stream
 String readExternString(DataInputInputStream fis)
           
 List<Object> readIterator(DataInputInputStream fis)
           
 Map<Object,Object> readMap(DataInputInputStream dis)
           
 Map.Entry<Object,Object> readMapEntry(DataInputInputStream dis)
           
 NamedList<Object> readNamedList(DataInputInputStream dis)
           
 SimpleOrderedMap<Object> readOrderedMap(DataInputInputStream dis)
           
 int readSize(DataInputInputStream in)
           
 int readSmallInt(DataInputInputStream dis)
           
 long readSmallLong(DataInputInputStream dis)
           
 SolrDocument readSolrDocument(DataInputInputStream dis)
           
 SolrDocumentList readSolrDocumentList(DataInputInputStream dis)
           
 SolrInputDocument readSolrInputDocument(DataInputInputStream dis)
           
 String readStr(DataInputInputStream dis)
           
 Object readVal(DataInputInputStream dis)
           
static int readVInt(DataInputInputStream in)
          The counterpart for writeVInt(int, FastOutputStream)
static long readVLong(DataInputInputStream in)
           
 Object unmarshal(InputStream is)
           
 void writeArray(Collection coll)
           
 void writeArray(List l)
           
 void writeArray(Object[] arr)
           
 void writeByteArray(byte[] arr, int offset, int len)
           
 void writeEnumFieldValue(EnumFieldValue enumFieldValue)
          write EnumFieldValue as tag+int value+string value
 void writeExternString(String s)
           
 void writeFloat(float val)
           
 void writeInt(int val)
           
 void writeIterator(Iterator iter)
           
 boolean writeKnownType(Object val)
           
 void writeLong(long val)
           
 void writeMap(Map<?,?> val)
           
 void writeMapEntry(Map.Entry<Object,Object> val)
           
 void writeNamedList(NamedList<?> nl)
           
 boolean writePrimitive(Object val)
           
 void writeSolrDocument(SolrDocument doc)
           
 void writeSolrDocumentList(SolrDocumentList docs)
           
 void writeSolrInputDocument(SolrInputDocument sdoc)
           
 void writeStr(String s)
          write the string as tag+length, with length being the number of UTF-8 bytes
 void writeTag(byte tag)
           
 void writeTag(byte tag, int size)
           
 void writeVal(Object val)
           
static void writeVInt(int i, FastOutputStream out)
          Special method for variable length int (copied from lucene).
static void writeVLong(long i, FastOutputStream out)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULL

public static final byte NULL
See Also:
Constant Field Values

BOOL_TRUE

public static final byte BOOL_TRUE
See Also:
Constant Field Values

BOOL_FALSE

public static final byte BOOL_FALSE
See Also:
Constant Field Values

BYTE

public static final byte BYTE
See Also:
Constant Field Values

SHORT

public static final byte SHORT
See Also:
Constant Field Values

DOUBLE

public static final byte DOUBLE
See Also:
Constant Field Values

INT

public static final byte INT
See Also:
Constant Field Values

LONG

public static final byte LONG
See Also:
Constant Field Values

FLOAT

public static final byte FLOAT
See Also:
Constant Field Values

DATE

public static final byte DATE
See Also:
Constant Field Values

MAP

public static final byte MAP
See Also:
Constant Field Values

SOLRDOC

public static final byte SOLRDOC
See Also:
Constant Field Values

SOLRDOCLST

public static final byte SOLRDOCLST
See Also:
Constant Field Values

BYTEARR

public static final byte BYTEARR
See Also:
Constant Field Values

ITERATOR

public static final byte ITERATOR
See Also:
Constant Field Values

END

public static final byte END
See Also:
Constant Field Values

SOLRINPUTDOC

public static final byte SOLRINPUTDOC
See Also:
Constant Field Values

SOLRINPUTDOC_CHILDS

public static final byte SOLRINPUTDOC_CHILDS
See Also:
Constant Field Values

ENUM_FIELD_VALUE

public static final byte ENUM_FIELD_VALUE
See Also:
Constant Field Values

MAP_ENTRY

public static final byte MAP_ENTRY
See Also:
Constant Field Values

TAG_AND_LEN

public static final byte TAG_AND_LEN
See Also:
Constant Field Values

STR

public static final byte STR
See Also:
Constant Field Values

SINT

public static final byte SINT
See Also:
Constant Field Values

SLONG

public static final byte SLONG
See Also:
Constant Field Values

ARR

public static final byte ARR
See Also:
Constant Field Values

ORDERED_MAP

public static final byte ORDERED_MAP
See Also:
Constant Field Values

NAMED_LST

public static final byte NAMED_LST
See Also:
Constant Field Values

EXTERN_STRING

public static final byte EXTERN_STRING
See Also:
Constant Field Values

daos

protected FastOutputStream daos

END_OBJ

protected static final Object END_OBJ

tagByte

protected byte tagByte
Constructor Detail

JavaBinCodec

public JavaBinCodec()

JavaBinCodec

public JavaBinCodec(JavaBinCodec.ObjectResolver resolver)
Method Detail

marshal

public void marshal(Object nl,
                    OutputStream os)
             throws IOException
Throws:
IOException

init

public void init(FastOutputStream os)
expert: sets a new output stream


unmarshal

public Object unmarshal(InputStream is)
                 throws IOException
Throws:
IOException

readOrderedMap

public SimpleOrderedMap<Object> readOrderedMap(DataInputInputStream dis)
                                        throws IOException
Throws:
IOException

readNamedList

public NamedList<Object> readNamedList(DataInputInputStream dis)
                                throws IOException
Throws:
IOException

writeNamedList

public void writeNamedList(NamedList<?> nl)
                    throws IOException
Throws:
IOException

writeVal

public void writeVal(Object val)
              throws IOException
Throws:
IOException

readVal

public Object readVal(DataInputInputStream dis)
               throws IOException
Throws:
IOException

writeKnownType

public boolean writeKnownType(Object val)
                       throws IOException
Throws:
IOException

writeTag

public void writeTag(byte tag)
              throws IOException
Throws:
IOException

writeTag

public void writeTag(byte tag,
                     int size)
              throws IOException
Throws:
IOException

writeByteArray

public void writeByteArray(byte[] arr,
                           int offset,
                           int len)
                    throws IOException
Throws:
IOException

readByteArray

public byte[] readByteArray(DataInputInputStream dis)
                     throws IOException
Throws:
IOException

writeSolrDocument

public void writeSolrDocument(SolrDocument doc)
                       throws IOException
Throws:
IOException

readSolrDocument

public SolrDocument readSolrDocument(DataInputInputStream dis)
                              throws IOException
Throws:
IOException

readSolrDocumentList

public SolrDocumentList readSolrDocumentList(DataInputInputStream dis)
                                      throws IOException
Throws:
IOException

writeSolrDocumentList

public void writeSolrDocumentList(SolrDocumentList docs)
                           throws IOException
Throws:
IOException

readSolrInputDocument

public SolrInputDocument readSolrInputDocument(DataInputInputStream dis)
                                        throws IOException
Throws:
IOException

writeSolrInputDocument

public void writeSolrInputDocument(SolrInputDocument sdoc)
                            throws IOException
Throws:
IOException

readMap

public Map<Object,Object> readMap(DataInputInputStream dis)
                           throws IOException
Throws:
IOException

writeIterator

public void writeIterator(Iterator iter)
                   throws IOException
Throws:
IOException

readIterator

public List<Object> readIterator(DataInputInputStream fis)
                          throws IOException
Throws:
IOException

writeArray

public void writeArray(List l)
                throws IOException
Throws:
IOException

writeArray

public void writeArray(Collection coll)
                throws IOException
Throws:
IOException

writeArray

public void writeArray(Object[] arr)
                throws IOException
Throws:
IOException

readArray

public List<Object> readArray(DataInputInputStream dis)
                       throws IOException
Throws:
IOException

writeEnumFieldValue

public void writeEnumFieldValue(EnumFieldValue enumFieldValue)
                         throws IOException
write EnumFieldValue as tag+int value+string value

Parameters:
enumFieldValue - to write
Throws:
IOException

writeMapEntry

public void writeMapEntry(Map.Entry<Object,Object> val)
                   throws IOException
Throws:
IOException

readEnumFieldValue

public EnumFieldValue readEnumFieldValue(DataInputInputStream dis)
                                  throws IOException
read EnumFieldValue (int+string) from input stream

Parameters:
dis - data input stream
Returns:
EnumFieldValue
Throws:
IOException

readMapEntry

public Map.Entry<Object,Object> readMapEntry(DataInputInputStream dis)
                                      throws IOException
Throws:
IOException

writeStr

public void writeStr(String s)
              throws IOException
write the string as tag+length, with length being the number of UTF-8 bytes

Throws:
IOException

readStr

public String readStr(DataInputInputStream dis)
               throws IOException
Throws:
IOException

writeInt

public void writeInt(int val)
              throws IOException
Throws:
IOException

readSmallInt

public int readSmallInt(DataInputInputStream dis)
                 throws IOException
Throws:
IOException

writeLong

public void writeLong(long val)
               throws IOException
Throws:
IOException

readSmallLong

public long readSmallLong(DataInputInputStream dis)
                   throws IOException
Throws:
IOException

writeFloat

public void writeFloat(float val)
                throws IOException
Throws:
IOException

writePrimitive

public boolean writePrimitive(Object val)
                       throws IOException
Throws:
IOException

writeMap

public void writeMap(Map<?,?> val)
              throws IOException
Throws:
IOException

readSize

public int readSize(DataInputInputStream in)
             throws IOException
Throws:
IOException

writeVInt

public static void writeVInt(int i,
                             FastOutputStream out)
                      throws IOException
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

public static int readVInt(DataInputInputStream in)
                    throws IOException
The counterpart for writeVInt(int, FastOutputStream)

Throws:
IOException - If there is a low-level I/O error.

writeVLong

public static void writeVLong(long i,
                              FastOutputStream out)
                       throws IOException
Throws:
IOException

readVLong

public static long readVLong(DataInputInputStream in)
                      throws IOException
Throws:
IOException

writeExternString

public void writeExternString(String s)
                       throws IOException
Throws:
IOException

readExternString

public String readExternString(DataInputInputStream fis)
                        throws IOException
Throws:
IOException


Copyright © 2000-2014 Apache Software Foundation. All Rights Reserved.