1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.backsource.utils.io;
22 import java.io.IOException;
23 import org.w3c.dom.Document;
24 import java.util.Properties;
25 import java.util.Iterator;
26 import java.util.Map;
27 import java.util.Map.Entry;
28 /***
29 * A cached input stream that reads from a {@link DOMInputStream}.
30 *
31 *
32 * @author <a href="mailto:pra@tim.se">Peter Antman</a>
33 * @version $Revision: 1.1.1.1 $
34 */
35
36 public class DOMCachedInputStream extends CachedInputStream{
37 Document doc;
38 private Properties props;
39 public DOMCachedInputStream (DOMCachedOutputStream cout) throws IOException{
40 this((Document)cout.getSink());
41 }
42 public DOMCachedInputStream (Document doc){
43 super( new DOMInputStream(doc));
44 this.doc = doc;
45 setProperties();
46 }
47
48 public void setProperties(Properties props) {
49 this.props = props;
50 setProperties();
51 }
52
53 private void setProperties() {
54 if ( props != null) {
55 DOMInputStream dis = (DOMInputStream)in;
56 Iterator entries = props.entrySet().iterator();
57 while ( entries.hasNext()) {
58 Map.Entry e = (Map.Entry)entries.next();
59 dis.setProperty(
60 (String)e.getKey(),
61 (String)e.getValue() );
62 }
63
64 }
65 }
66
67 public Document getDocument() {
68 return doc;
69 }
70
71 /***
72 * Get the underlying DOMInputStream.
73 */
74 public DOMInputStream getStream() {
75 return (DOMInputStream)in;
76 }
77
78 /***
79 * Resets all buffers and opens a new DOMInputStream.
80 */
81 public void rewind() throws IOException {
82 try {
83
84 in.close();
85 } catch (Exception ignore) {
86 ;
87 }
88 buf = new byte[buf.length];
89 count = 0;
90 pos = 0;
91 markpos = -1;
92 in = new DOMInputStream(doc);
93 setProperties();
94 }
95
96 }