private String translateBytesToString(byte[] bytes,long format,Transferable localeTransferable) throws IOException {
  Long lFormat=Long.valueOf(format);
  String charset=getBestCharsetForTextFormat(lFormat,localeTransferable);
  String eoln=(String)nativeEOLNs.get(lFormat);
  Integer terminators=(Integer)nativeTerminators.get(lFormat);
  int count;
  if (terminators != null) {
    int numTerminators=terminators.intValue();
    search:     for (count=0; count < (bytes.length - numTerminators + 1); count+=numTerminators) {
      for (int i=count; i < count + numTerminators; i++) {
        if (bytes[i] != 0x0) {
          continue search;
        }
      }
      break search;
    }
  }
 else {
    count=bytes.length;
  }
  String converted=new String(bytes,0,count,charset);
  if (eoln != null) {
    char[] buf=converted.toCharArray();
    char[] eoln_arr=eoln.toCharArray();
    converted=null;
    int j=0;
    boolean match;
    for (int i=0; i < buf.length; ) {
      if (i + eoln_arr.length > buf.length) {
        buf[j++]=buf[i++];
        continue;
      }
      match=true;
      for (int k=0, l=i; k < eoln_arr.length; k++, l++) {
        if (eoln_arr[k] != buf[l]) {
          match=false;
          break;
        }
      }
      if (match) {
        buf[j++]='\n';
        i+=eoln_arr.length;
      }
 else {
        buf[j++]=buf[i++];
      }
    }
    converted=new String(buf,0,j);
  }
  return converted;
}

private String translateBytesToString ( byte [ ] bytes , long format , Transferable localeTransferable ) throws IOException { Long lFormat = Long . valueOf ( format ) ; String charset = getBestCharsetForTextFormat ( lFormat , localeTransferable ) ; String eoln = ( String ) nativeEOLNs . get ( lFormat ) ; Integer terminators = ( Integer ) nativeTerminators . get ( lFormat ) ; int count ; if ( terminators != null ) { int numTerminators = terminators . intValue ( ) ; search : for ( count = 0 ; count < ( bytes . length - numTerminators + 1 ) ; count += numTerminators ) { for ( int i = count ; i < count + numTerminators ; i ++ ) { if ( bytes [ i ] != 0x0 ) { continue search ; } } break search ; } } else { count = bytes . length ; } String converted = new String ( bytes , 0 , count , charset ) ; if ( eoln != null ) { char [ ] buf = converted . toCharArray ( ) ; char [ ] eoln_arr = eoln . toCharArray ( ) ; converted = null ; int j = 0 ; boolean match ; for ( int i = 0 ; i < buf . length ; ) { if ( i + eoln_arr . length > buf . length ) { buf [ j ++ ] = buf [ i ++ ] ; continue ; } match = true ; for ( int k = 0 , l = i ; k < eoln_arr . length ; k ++ , l ++ ) { if ( eoln_arr [ k ] != buf [ l ] ) { match = false ; break ; } } if ( match ) { buf [ j ++ ] = '\n' ; i += eoln_arr . length ; } else { buf [ j ++ ] = buf [ i ++ ] ; } } converted = new String ( buf , 0 , j ) ; } return converted ; }
translating either a byte array or an inputstream into an string . strip terminators and search - and - replace eoln . native to java string conversion
