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;
}

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 ; }
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
