MCPcopy Create free account
hub / github.com/dumbledore/AlbiteREADER / XhtmlStreamReader

Class XhtmlStreamReader

src/org/albite/io/html/XhtmlStreamReader.java:17–699  ·  view source on GitHub ↗

@author albus

Source from the content-addressed store, hash-verified

15 * @author albus
16 */
17public 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;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected