1 2 package org.enhydra.tool.archive.xml; 3 import java.io.IOException ; 5 import java.io.Reader ; 6 import java.io.FilterReader ; 7 public class DocTypeFilterReader extends FilterReader { 9 public DocTypeFilterReader(Reader in) { 10 super(in); 11 } 12 13 public int read(char buf[], int off, int len) throws IOException { 14 int nRead = in.read(buf, off, len); 15 int index = -1; 16 int top = (nRead == -1 ? len : nRead); 17 StringBuffer sb = new StringBuffer (); 18 19 for (int i = 0; i < top; i++) { 20 if ((i + 1) < top) { 21 if (buf[i] == '<' && buf[i + 1] == '!') { 22 while (buf[i] != '>' && i < top) { 23 i++; 24 } 25 } else { 26 sb.append(buf[i]); 27 } 28 } else { 29 sb.append(buf[i]); 30 } 31 } 32 char[] newBuf = sb.toString().toCharArray(); 33 34 for (int i = 0; i < buf.length; i++) { 35 if (i < newBuf.length) { 36 buf[i] = newBuf[i]; 37 } else { 38 buf[i] = 0; 39 } 40 } 41 if (nRead > -1) { 42 nRead = sb.toString().toCharArray().length; 43 } 44 return nRead; 45 } 46 47 } 48 | Popular Tags |