@ Override public @ Sensitive byte [ ] serialize ( ) throws IOException { // Captured thread context ByteArrayOutputStream bout = new ByteArrayOutputStream ( ) ; int size = threadContext . size ( ) ; byte [ ] [ ] contextBytes = new byte [ size ] [ ] ; for ( int i = 0 ; i < size ; i ++ ) { bout . reset ( ) ; ObjectOutputStream oout = new ObjectOutputStream ( bout ) ; oout . writeObject ( threadContext . get ( i ) ) ; oout . flush ( ) ; contextBytes [ i ] = bout . toByteArray ( ) ; oout . close ( ) ; } bout . reset ( ) ; ObjectOutputStream oout = new ObjectOutputStream ( bout ) ; // Number of serialized fields (list of thread context counts as one) oout . writeShort ( 3 ) ; // 1) Bytes for captured thread context oout . writeObject ( contextBytes ) ; // 2) Metadata identifier oout . writeObject ( metaDataIdentifier ) ; // 3) Thread context provider names oout . writeShort ( providerNames . size ( ) ) ; for ( String providerName : providerNames ) if ( providerName . startsWith ( "com.ibm.ws." ) && providerName . endsWith ( ".context.provider" ) ) oout . writeObject ( providerName . substring ( 10 , providerName . length ( ) - 16 ) ) ; else oout . writeObject ( providerName ) ; // Only add primitive or compatible Java types in the future. If necessary, pre-serialize to byte[] oout . flush ( ) ; oout . close ( ) ; return bout . toByteArray ( ) ; }
Serializes this thread context descriptor to bytes .