public static byte [ ] toNullTerminatedFixedSizeByteArray ( String s , int length ) { if ( s . length ( ) >= length ) { s = s . substring ( 0 , length - 1 ) ; } while ( s . length ( ) < length ) { s += ' ' ; } return s . getBytes ( ) ; }
Converts a string to a null - terminated fixed size byte array .