1 /**
2 * Phoebe DOM Implementation.
3 *
4 * This is a C++ approximation of the W3C DOM model, which follows
5 * fairly closely the specifications in the various .idl files, copies of
6 * which are provided for reference. Most important is this one:
7 *
8 * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html
9 *
10 * Authors:
11 * Bob Jamison
12 *
13 * Copyright (C) 2006 Bob Jamison
14 *
15 * This library is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU Lesser General Public
17 * License as published by the Free Software Foundation; either
18 * version 2.1 of the License, or (at your option) any later version.
19 *
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
24 *
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 */
30 /**
31 * This class provided buffered endpoints for input and output.
32 */
34 #include "bufferstream.h"
36 namespace org
37 {
38 namespace w3c
39 {
40 namespace dom
41 {
42 namespace io
43 {
47 //#########################################################################
48 //# B U F F E R I N P U T S T R E A M
49 //#########################################################################
52 /**
53 *
54 */
55 BufferInputStream::BufferInputStream(
56 const std::vector<unsigned char> &sourceBuffer)
57 : buffer(sourceBuffer)
58 {
59 position = 0;
60 closed = false;
61 }
63 /**
64 *
65 */
66 BufferInputStream::~BufferInputStream()
67 {
69 }
71 /**
72 * Returns the number of bytes that can be read (or skipped over) from
73 * this input stream without blocking by the next caller of a method for
74 * this input stream.
75 */
76 int BufferInputStream::available()
77 {
78 if (closed)
79 return -1;
80 return buffer.size() - position;
81 }
84 /**
85 * Closes this input stream and releases any system resources
86 * associated with the stream.
87 */
88 void BufferInputStream::close()
89 {
90 closed = true;
91 }
93 /**
94 * Reads the next byte of data from the input stream. -1 if EOF
95 */
96 int BufferInputStream::get()
97 {
98 if (closed)
99 return -1;
100 if (position >= (int)buffer.size())
101 return -1;
102 int ch = (int) buffer[position++];
103 return ch;
104 }
109 //#########################################################################
110 //# B U F F E R O U T P U T S T R E A M
111 //#########################################################################
113 /**
114 *
115 */
116 BufferOutputStream::BufferOutputStream()
117 {
118 closed = false;
119 }
121 /**
122 *
123 */
124 BufferOutputStream::~BufferOutputStream()
125 {
126 }
128 /**
129 * Closes this output stream and releases any system resources
130 * associated with this stream.
131 */
132 void BufferOutputStream::close()
133 {
134 closed = true;
135 }
137 /**
138 * Flushes this output stream and forces any buffered output
139 * bytes to be written out.
140 */
141 void BufferOutputStream::flush()
142 {
143 //nothing to do
144 }
146 /**
147 * Writes the specified byte to this output stream.
148 */
149 void BufferOutputStream::put(XMLCh ch)
150 {
151 if (closed)
152 return;
153 buffer.push_back(ch);
154 }
159 } //namespace io
160 } //namespace dom
161 } //namespace w3c
162 } //namespace org
164 //#########################################################################
165 //# E N D O F F I L E
166 //#########################################################################