public static final byte [ ] fromHex ( String hexDump ) { List < Integer > list = new ArrayList <> ( ) ; String [ ] lines = hexDump . split ( "\n" ) ; if ( lines . length < 2 ) { throw new IllegalArgumentException ( "not a hex dump" ) ; } if ( ! lines [ 0 ] . contains ( Title ) ) { throw new IllegalArgumentException ( "not a hex dump" ) ; } for ( int ll = 1 ; ll < lines . length ; ll ++ ) { String line = lines [ ll ] ; int i1 = line . indexOf ( ' ' ) ; if ( i1 == - 1 ) { throw new IllegalArgumentException ( "not a hex dump" ) ; } int i2 = line . indexOf ( " " , i1 + 2 ) ; if ( i2 == - 1 ) { throw new IllegalArgumentException ( "not a hex dump" ) ; } String [ ] fields = line . substring ( i1 + 2 , i2 ) . split ( " " ) ; for ( int ii = 0 ; ii < fields . length ; ii ++ ) { list . add ( Integer . parseInt ( fields [ ii ] , 16 ) ) ; } } byte [ ] bytes = new byte [ list . size ( ) ] ; for ( int ii = 0 ; ii < bytes . length ; ii ++ ) { bytes [ ii ] = list . get ( ii ) . byteValue ( ) ; } return bytes ; }
Recreates byte array from hex dump .