1 #ifndef __INKSCAPE_IO_URISTREAM_H__
2 #define __INKSCAPE_IO_URISTREAM_H__
3 /**
4 * This should be the only way that we provide sources/sinks
5 * to any input/output stream.
6 *
7 * Authors:
8 * Bob Jamison <rjamison@titan.com>
9 *
10 * Copyright (C) 2004 Inkscape.org
11 *
12 * Released under GNU GPL, read the file 'COPYING' for more information
13 */
16 #include <uri.h>
18 #include "inkscapestream.h"
21 namespace Inkscape
22 {
23 namespace IO
24 {
26 //#########################################################################
27 //# U R I I N P U T S T R E A M / R E A D E R
28 //#########################################################################
30 /**
31 * This class is for receiving a stream of data from a resource
32 * defined in a URI
33 */
34 class UriInputStream : public InputStream
35 {
37 public:
38 UriInputStream(FILE *source, Inkscape::URI &uri) throw(StreamException);
40 UriInputStream(Inkscape::URI &source) throw(StreamException);
42 virtual ~UriInputStream() throw(StreamException);
44 virtual int available() throw(StreamException);
46 virtual void close() throw(StreamException);
48 virtual int get() throw(StreamException);
50 private:
52 bool closed;
54 FILE *inf; //for file: uris
55 unsigned char *data; //for data: uris
56 int dataPos; // current read position in data field
57 int dataLen; // length of data buffer
59 Inkscape::URI &uri;
61 int scheme;
63 }; // class UriInputStream
68 /**
69 * This class is for receiving a stream of formatted data from a resource
70 * defined in a URI
71 */
72 class UriReader : public BasicReader
73 {
75 public:
77 UriReader(Inkscape::URI &source) throw(StreamException);
79 virtual ~UriReader() throw(StreamException);
81 virtual int available() throw(StreamException);
83 virtual void close() throw(StreamException);
85 virtual gunichar get() throw(StreamException);
87 private:
89 UriInputStream *inputStream;
91 }; // class UriReader
95 //#########################################################################
96 //# U R I O U T P U T S T R E A M / W R I T E R
97 //#########################################################################
99 /**
100 * This class is for sending a stream to a destination resource
101 * defined in a URI
102 *
103 */
104 class UriOutputStream : public OutputStream
105 {
107 public:
109 UriOutputStream(FILE *fp, Inkscape::URI &destination) throw(StreamException);
111 UriOutputStream(Inkscape::URI &destination) throw(StreamException);
113 virtual ~UriOutputStream() throw(StreamException);
115 virtual void close() throw(StreamException);
117 virtual void flush() throw(StreamException);
119 virtual void put(int ch) throw(StreamException);
121 private:
123 bool closed;
124 bool ownsFile;
126 FILE *outf; //for file: uris
127 Glib::ustring data; //for data: uris
129 Inkscape::URI &uri;
131 int scheme;
133 }; // class UriOutputStream
139 /**
140 * This class is for sending a stream of formatted data to a resource
141 * defined in a URI
142 */
143 class UriWriter : public BasicWriter
144 {
146 public:
148 UriWriter(Inkscape::URI &source) throw(StreamException);
150 virtual ~UriWriter() throw(StreamException);
152 virtual void close() throw(StreamException);
154 virtual void flush() throw(StreamException);
156 virtual void put(gunichar ch) throw(StreamException);
158 private:
160 UriOutputStream *outputStream;
162 }; // class UriReader
169 } // namespace IO
170 } // namespace Inkscape
173 #endif /* __INKSCAPE_IO_URISTREAM_H__ */