@ Nonnull public static byte [ ] getSerializedByteArray ( @ Nonnull final Serializable aData ) { ValueEnforcer . notNull ( aData , "Data" ) ; try ( final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream ( ) ) { // Convert to byte array try ( final ObjectOutputStream aOOS = new ObjectOutputStream ( aBAOS ) ) { aOOS . writeObject ( aData ) ; } // Main sending return aBAOS . toByteArray ( ) ; } catch ( final NotSerializableException ex ) { throw new IllegalArgumentException ( "Not serializable: " + ex . getMessage ( ) , ex ) ; } catch ( final IOException ex ) { throw new IllegalArgumentException ( "Failed to write serializable object " + aData + " of type " + aData . getClass ( ) . getName ( ) , ex ) ; } }
Convert the passed Serializable object to a serialized byte array .