public byte [ ] createDataFrames ( List < Object > dataObjects ) throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream ( ) ; for ( int i = 0 ; i < dataObjects . size ( ) ; i ++ ) { ByteArrayOutputStream dataObjectStream = new ByteArrayOutputStream ( ) ; @ SuppressWarnings ( "unchecked" ) LumberjackEvent < String , String > dataObject = ( LumberjackEvent < String , String > ) dataObjects . get ( i ) ; dataObjectStream . write ( PROTOCOL_VERSION . getBytes ( UTF_8 ) ) ; //Protocol version dataObjectStream . write ( DATA_FRAME_TYPE . getBytes ( UTF_8 ) ) ; //Frame type 'D' dataObjectStream . write ( ByteBuffer . allocate ( 4 ) . putInt ( seqNumber ++ ) . array ( ) ) ; //32-bit sequence number dataObjectStream . write ( ByteBuffer . allocate ( 4 ) . putInt ( dataObject . size ( ) ) . array ( ) ) ; //32-bit pair count for ( int j = 0 ; j < dataObject . size ( ) ; j ++ ) { Entry < String , String > entry = dataObject . get ( j ) ; String key = entry . getKey ( ) ; String value = entry . getValue ( ) ; byte [ ] keyBytes = key . getBytes ( UTF_8 ) ; byte [ ] valueBytes = value . getBytes ( UTF_8 ) ; dataObjectStream . write ( ByteBuffer . allocate ( 4 ) . putInt ( keyBytes . length ) . array ( ) ) ; //32-bit key length dataObjectStream . write ( keyBytes ) ; //Key dataObjectStream . write ( ByteBuffer . allocate ( 4 ) . putInt ( valueBytes . length ) . array ( ) ) ; //32-bit value length dataObjectStream . write ( valueBytes ) ; //Value } output . write ( dataObjectStream . toByteArray ( ) ) ; } if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isEventEnabled ( ) ) Tr . event ( tc , "created data frame for " + dataObjects . size ( ) + " events - last sequence number used = " + ( seqNumber - 1 ) ) ; return output . toByteArray ( ) ; }
Creates data frames for lumberjack protocol