1 11 package org.eclipse.help.internal.search; 12 13 import java.io.*; 14 15 19 public class ParsedDocument { 20 private static final int charsLimit = 1000000; 23 Reader reader; 24 boolean read; 25 char[] docChars; 26 27 33 public ParsedDocument(Reader reader) { 34 this.reader = reader; 35 this.read = false; 36 } 37 public Reader newContentReader() { 38 if (!read) { 39 read = true; 40 readDocument(); 41 } 42 return new CharArrayReader(docChars); 43 } 44 private void readDocument() { 45 CharArrayWriter writer = new CharArrayWriter(); 46 char[] buf = new char[4096]; 47 int n; 48 int charsWritten = 0; 49 try { 50 while (0 <= (n = reader.read(buf))) { 51 if (charsWritten < charsLimit) { 52 if (n > charsLimit - charsWritten) { 53 writer.write(buf, 0, charsLimit - charsWritten); 55 charsWritten = charsLimit; 56 } else { 57 writer.write(buf, 0, n); 58 charsWritten += n; 59 } 60 } else { 61 } 64 } 65 } catch (IOException ioe) { 66 } finally { 68 try { 69 reader.close(); 70 } catch (IOException ioe2) { 71 } 72 } 73 docChars = writer.toCharArray(); 74 } 75 } 76 | Popular Tags |