public void write(Writer out,Document doc,int pos,int len) throws IOException, BadLocationException {
  if ((pos < 0) || ((pos + len) > doc.getLength())) {
    throw new BadLocationException("DefaultEditorKit.write",pos);
  }
  Segment data=new Segment();
  int nleft=len;
  int offs=pos;
  Object endOfLineProperty=doc.getProperty(EndOfLineStringProperty);
  if (endOfLineProperty == null) {
    try {
      endOfLineProperty=System.getProperty("line.separator");
    }
 catch (    SecurityException se) {
    }
  }
  String endOfLine;
  if (endOfLineProperty instanceof String) {
    endOfLine=(String)endOfLineProperty;
  }
 else {
    endOfLine=null;
  }
  if (endOfLineProperty != null && !endOfLine.equals("\n")) {
    while (nleft > 0) {
      int n=Math.min(nleft,4096);
      doc.getText(offs,n,data);
      int last=data.offset;
      char[] array=data.array;
      int maxCounter=last + data.count;
      for (int counter=last; counter < maxCounter; counter++) {
        if (array[counter] == '\n') {
          if (counter > last) {
            out.write(array,last,counter - last);
          }
          out.write(endOfLine);
          last=counter + 1;
        }
      }
      if (maxCounter > last) {
        out.write(array,last,maxCounter - last);
      }
      offs+=n;
      nleft-=n;
    }
  }
 else {
    while (nleft > 0) {
      int n=Math.min(nleft,4096);
      doc.getText(offs,n,data);
      out.write(data.array,data.offset,data.count);
      offs+=n;
      nleft-=n;
    }
  }
  out.flush();
}

public void write ( Writer out , Document doc , int pos , int len ) throws IOException , BadLocationException { if ( ( pos < 0 ) || ( ( pos + len ) > doc . getLength ( ) ) ) { throw new BadLocationException ( "DefaultEditorKit.write" , pos ) ; } Segment data = new Segment ( ) ; int nleft = len ; int offs = pos ; Object endOfLineProperty = doc . getProperty ( EndOfLineStringProperty ) ; if ( endOfLineProperty == null ) { try { endOfLineProperty = System . getProperty ( "line.separator" ) ; } catch ( SecurityException se ) { } } String endOfLine ; if ( endOfLineProperty instanceof String ) { endOfLine = ( String ) endOfLineProperty ; } else { endOfLine = null ; } if ( endOfLineProperty != null && ! endOfLine . equals ( "\n" ) ) { while ( nleft > 0 ) { int n = Math . min ( nleft , 4096 ) ; doc . getText ( offs , n , data ) ; int last = data . offset ; char [ ] array = data . array ; int maxCounter = last + data . count ; for ( int counter = last ; counter < maxCounter ; counter ++ ) { if ( array [ counter ] == '\n' ) { if ( counter > last ) { out . write ( array , last , counter - last ) ; } out . write ( endOfLine ) ; last = counter + 1 ; } } if ( maxCounter > last ) { out . write ( array , last , maxCounter - last ) ; } offs += n ; nleft -= n ; } } else { while ( nleft > 0 ) { int n = Math . min ( nleft , 4096 ) ; doc . getText ( offs , n , data ) ; out . write ( data . array , data . offset , data . count ) ; offs += n ; nleft -= n ; } } out . flush ( ) ; }
writes content from a document to the given stream as plain text .
