1 #ifndef __DOM_IO_BASE64STREAM_H__\r
2 #define __DOM_IO_BASE64STREAM_H__\r
3 \r
4 /**\r
5 * Phoebe DOM Implementation.\r
6 *\r
7 * Base64-enabled input and output streams\r
8 *\r
9 * This class allows easy encoding and decoding\r
10 * of Base64 data with a stream interface, hiding\r
11 * the implementation from the user.\r
12 *\r
13 * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html\r
14 *\r
15 * Authors:\r
16 * Bob Jamison\r
17 *\r
18 * Copyright (C) 2006 Bob Jamison\r
19 *\r
20 * This library is free software; you can redistribute it and/or\r
21 * modify it under the terms of the GNU Lesser General Public\r
22 * License as published by the Free Software Foundation; either\r
23 * version 2.1 of the License, or (at your option) any later version.\r
24 *\r
25 * This library is distributed in the hope that it will be useful,\r
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
28 * Lesser General Public License for more details.\r
29 *\r
30 * You should have received a copy of the GNU Lesser General Public\r
31 * License along with this library; if not, write to the Free Software\r
32 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\r
33 */\r
34 \r
35 \r
36 \r
37 #include "domstream.h"\r
38 \r
39 \r
40 namespace org\r
41 {\r
42 namespace w3c\r
43 {\r
44 namespace dom\r
45 {\r
46 namespace io\r
47 {\r
48 \r
49 \r
50 \r
51 //#########################################################################\r
52 //# B A S E 6 4 I N P U T S T R E A M\r
53 //#########################################################################\r
54 \r
55 /**\r
56 * This class is for decoding a Base-64 encoded InputStream source\r
57 *\r
58 */\r
59 class Base64InputStream : public BasicInputStream\r
60 {\r
61 \r
62 public:\r
63 \r
64 Base64InputStream(InputStream &sourceStream);\r
65 \r
66 virtual ~Base64InputStream();\r
67 \r
68 virtual int available();\r
69 \r
70 virtual void close();\r
71 \r
72 virtual int get();\r
73 \r
74 private:\r
75 \r
76 int outBytes[3];\r
77 \r
78 int outCount;\r
79 \r
80 int padCount;\r
81 \r
82 bool done;\r
83 \r
84 }; // class Base64InputStream\r
85 \r
86 \r
87 \r
88 \r
89 //#########################################################################\r
90 //# B A S E 6 4 O U T P U T S T R E A M\r
91 //#########################################################################\r
92 \r
93 /**\r
94 * This class is for Base-64 encoding data going to the\r
95 * destination OutputStream\r
96 *\r
97 */\r
98 class Base64OutputStream : public BasicOutputStream\r
99 {\r
100 \r
101 public:\r
102 \r
103 Base64OutputStream(OutputStream &destinationStream);\r
104 \r
105 virtual ~Base64OutputStream();\r
106 \r
107 virtual void close();\r
108 \r
109 virtual void flush();\r
110 \r
111 virtual void put(XMLCh ch);\r
112 \r
113 /**\r
114 * Sets the maximum line length for base64 output. If\r
115 * set to <=0, then there will be no line breaks;\r
116 */\r
117 virtual void setColumnWidth(int val)\r
118 { columnWidth = val; }\r
119 \r
120 private:\r
121 \r
122 void putCh(int ch);\r
123 \r
124 int column;\r
125 \r
126 int columnWidth;\r
127 \r
128 unsigned long outBuf;\r
129 \r
130 int bitCount;\r
131 \r
132 }; // class Base64OutputStream\r
133 \r
134 \r
135 \r
136 \r
137 \r
138 \r
139 \r
140 } //namespace io\r
141 } //namespace dom\r
142 } //namespace w3c\r
143 } //namespace org\r
144 \r
145 \r
146 #endif /* __INKSCAPE_IO_BASE64STREAM_H__ */\r