org.apache.solr.common.util

## Class JavaBinCodec

- java.lang.Object
- - org.apache.solr.common.util.JavaBinCodec

-     public class JavaBinCodec
      extends Object

  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.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 Classes
    Modifier and Type | Class and Description
    --- | ---
    `static interface` | `JavaBinCodec.ObjectResolver` Allows extension of `JavaBinCodec` to support serialization of arbitrary data types.
    `static class` | `JavaBinCodec.StringBytes`
    `static class` | `JavaBinCodec.StringCache`
    `static interface` | `JavaBinCodec.WritableDocFields`

  - ### Field Summary

    Fields
    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`
    `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

    Constructors
    Constructor and Description
    `JavaBinCodec()`
    `JavaBinCodec(JavaBinCodec.ObjectResolver resolver)`
    `JavaBinCodec(JavaBinCodec.ObjectResolver resolver, JavaBinCodec.StringCache stringCache)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `JavaBinCodec.ObjectResolver` | `getResolver()`
    `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)`
    `String` | `readStr(DataInputInputStream dis, JavaBinCodec.StringCache stringCache)`
    `Object` | `readVal(DataInputInputStream dis)`
    `static int` | `readVInt(DataInputInputStream in)` The counterpart for `writeVInt(int, FastOutputStream)`
    `static long` | `readVLong(DataInputInputStream in)`
    `JavaBinCodec` | `setWritableDocFields(JavaBinCodec.WritableDocFields writableDocFields)`
    `protected boolean` | `toWrite(String key)`
    `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)

    - #### JavaBinCodec

          public JavaBinCodec(JavaBinCodec.ObjectResolver resolver,
                              JavaBinCodec.StringCache stringCache)

  - ### Method Detail

    - #### setWritableDocFields

          public JavaBinCodec setWritableDocFields(JavaBinCodec.WritableDocFields writableDocFields)

    - #### getResolver

          public JavaBinCodec.ObjectResolver getResolver()

    - #### 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`

    - #### toWrite

          protected boolean toWrite(String key)

    - #### 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`

    - #### readStr

          public String readStr(DataInputInputStream dis,
                                JavaBinCodec.StringCache stringCache)
                         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-2016 Apache Software Foundation. All Rights Reserved.