question: private byte [ ] translateTransferableString ( String str , long format ) throws IOException { Long lFormat = Long . valueOf ( format ) ; String charset = getBestCharsetForTextFormat ( lFormat , null ) ; String eoln = ( String ) nativeEOLNs . get ( lFormat ) ; if ( eoln != null ) { int length = str . length ( ) ; StringBuffer buffer = new StringBuffer ( length * 2 ) ; for ( int i = 0 ; i < length ; i ++ ) { if ( str . startsWith ( eoln , i ) ) { buffer . append ( eoln ) ; i += eoln . length ( ) - 1 ; continue ; } char c = str . charAt ( i ) ; if ( c == '\n' ) { buffer . append ( eoln ) ; } else { buffer . append ( c ) ; } } str = buffer . toString ( ) ; } byte [ ] bytes = str . getBytes ( charset ) ; Integer terminators = ( Integer ) nativeTerminators . get ( lFormat ) ; if ( terminators != null ) { int numTerminators = terminators . intValue ( ) ; byte [ ] terminatedBytes = new byte [ bytes . length + numTerminators ] ; System . arraycopy ( bytes , 0 , terminatedBytes , 0 , bytes . length ) ; for ( int i = bytes . length ; i < terminatedBytes . length ; i ++ ) { terminatedBytes [ i ] = 0x0 ; } bytes = terminatedBytes ; } return bytes ; }
target:  Translation function for converting string into a byte array. Search-and-replace EOLN. Encode into the target format. Append terminating NUL bytes. Java to Native string conversion