final Serializable restoreMapObject ( byte [ ] mapItemArray ) throws IOException , ClassNotFoundException { Serializable item = null ; ; /* If it is a real byte array, we need to return a safe copy with the */ /* header bytes removed. */ if ( ( mapItemArray [ 0 ] == HEADER_BYTE_0 ) && ( mapItemArray [ 1 ] == HEADER_BYTE_1 ) ) { item = new byte [ mapItemArray . length - 2 ] ; System . arraycopy ( mapItemArray , 2 , item , 0 , ( ( byte [ ] ) item ) . length ) ; } /* Anything else needs deserializing. */ else { ByteArrayInputStream bai = new ByteArrayInputStream ( mapItemArray ) ; ObjectInputStream wsin = null ; if ( RuntimeInfo . isThinClient ( ) || RuntimeInfo . isFatClient ( ) ) { //thin client environment. create ObjectInputStream from factory method. //As of now getting twas factory class. //Hard coding now.. once when Libery thin client get developed, this can be taken to a factory type class. Class < ? > clazz = Class . forName ( "com.ibm.ws.util.WsObjectInputStream" ) ; try { wsin = ( ObjectInputStream ) clazz . getConstructor ( ByteArrayInputStream . class ) . newInstance ( bai ) ; } catch ( Exception e ) { // No FFDC code needed if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) SibTr . debug ( this , tc , "Exception closing the ObjectInputStream" , e ) ; } } else { //Liberty server environment ClassLoader cl = AccessController . doPrivileged ( new PrivilegedAction < ClassLoader > ( ) { @ Override public ClassLoader run ( ) { return Thread . currentThread ( ) . getContextClassLoader ( ) ; } } ) ; wsin = new DeserializationObjectInputStream ( bai , cl ) ; } item = ( Serializable ) wsin . readObject ( ) ; try { if ( wsin != null ) { wsin . close ( ) ; } } catch ( IOException ex ) { // No FFDC code needed if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) SibTr . debug ( this , tc , "Exception closing the ObjectInputStream" , ex ) ; } } return item ; }
Restore an item retrieved from a Property or SystemContext map as a byte array into whatever it originally was .