@author albus
| 15 | * @author albus |
| 16 | */ |
| 17 | public class XhtmlStreamReader extends Reader implements HTMLSubstitues { |
| 18 | |
| 19 | private static final int SEARCH_BUFFER = 2048; |
| 20 | private static final Hashtable ENTITIES = new Hashtable(200); |
| 21 | |
| 22 | private final AlbiteStreamReader in; |
| 23 | private final char[] buffer = new char[10]; |
| 24 | private Hashtable customEntities; |
| 25 | |
| 26 | public XhtmlStreamReader( |
| 27 | final AlbiteStreamReader in, |
| 28 | final boolean readXmlDecl, |
| 29 | final boolean readDoctypeDecl) |
| 30 | throws IOException { |
| 31 | |
| 32 | this.in = in; |
| 33 | |
| 34 | if (readXmlDecl) { |
| 35 | /* |
| 36 | * Read xml decl |
| 37 | */ |
| 38 | xmldecl(); |
| 39 | } |
| 40 | |
| 41 | if (readDoctypeDecl) { |
| 42 | /* |
| 43 | * Read doc decl |
| 44 | */ |
| 45 | doctypedecl(); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | private void xmldecl() throws IOException { |
| 50 | /* |
| 51 | * Try to read the xmldecl |
| 52 | */ |
| 53 | |
| 54 | /* |
| 55 | * Mark four times as much, for the underlying AlbiteStreamReader, |
| 56 | * might read multibyte (4-byte) UTF-8 chars |
| 57 | */ |
| 58 | in.mark(SEARCH_BUFFER * 4); |
| 59 | try { |
| 60 | char[] buf = new char[SEARCH_BUFFER]; |
| 61 | int read = in.read(buf); |
| 62 | |
| 63 | if (read > 0) { |
| 64 | String xmldecl = new String(buf, 0, read); |
| 65 | if (!xmldecl.startsWith("<?xml")) { |
| 66 | in.reset(); |
| 67 | return; |
| 68 | } |
| 69 | |
| 70 | int xend = xmldecl.indexOf("?>"); |
| 71 | |
| 72 | if (xend == -1) { |
| 73 | in.reset(); |
| 74 | return; |
nothing calls this directly
no outgoing calls
no test coverage detected