protected void writeArray ( FSTClazzInfo . FSTFieldInfo referencee , Object array ) throws IOException { if ( array == null ) { getCodec ( ) . writeClass ( Object . class ) ; getCodec ( ) . writeFInt ( - 1 ) ; return ; } final int len = Array . getLength ( array ) ; Class < ? > componentType = array . getClass ( ) . getComponentType ( ) ; getCodec ( ) . writeClass ( array . getClass ( ) ) ; getCodec ( ) . writeFInt ( len ) ; if ( ! componentType . isArray ( ) ) { if ( getCodec ( ) . isPrimitiveArray ( array , componentType ) ) { getCodec ( ) . writePrimitiveArray ( array , 0 , len ) ; } else { // objects Object arr [ ] = ( Object [ ] ) array ; Class lastClz = null ; FSTClazzInfo lastInfo = null ; for ( int i = 0 ; i < len ; i ++ ) { Object toWrite = arr [ i ] ; if ( toWrite != null ) { lastInfo = writeObjectWithContext ( referencee , toWrite , lastClz == toWrite . getClass ( ) ? lastInfo : null ) ; lastClz = toWrite . getClass ( ) ; } else writeObjectWithContext ( referencee , toWrite , null ) ; } } } else { // multidim array. FIXME shared refs to subarrays are not tested !!! Object [ ] arr = ( Object [ ] ) array ; FSTClazzInfo . FSTFieldInfo ref1 = new FSTClazzInfo . FSTFieldInfo ( referencee . getPossibleClasses ( ) , null , conf . getCLInfoRegistry ( ) . isIgnoreAnnotations ( ) ) ; for ( int i = 0 ; i < len ; i ++ ) { Object subArr = arr [ i ] ; boolean needsWrite = true ; if ( getCodec ( ) . isTagMultiDimSubArrays ( ) ) { if ( subArr == null ) { needsWrite = ! getCodec ( ) . writeTag ( NULL , null , 0 , null , this ) ; } else { needsWrite = ! getCodec ( ) . writeTag ( ARRAY , subArr , 0 , subArr , this ) ; } } if ( needsWrite ) { writeArray ( ref1 , subArr ) ; getCodec ( ) . writeArrayEnd ( ) ; } } } }
incoming array is already registered