summaryrefslogtreecommitdiffstats
path: root/src/io/uristream.h
blob: d620659765a3ef3fd2af1aa5f00b2c5f82ed6ebb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#ifndef __INKSCAPE_IO_URISTREAM_H__
#define __INKSCAPE_IO_URISTREAM_H__
/**
 * This should be the only way that we provide sources/sinks
 * to any input/output stream.
 *
 * Authors:
 *   Bob Jamison <rjamison@titan.com>
 *
 * Copyright (C) 2004 Inkscape.org
 *
 * Released under GNU GPL, read the file 'COPYING' for more information
 */


#include <uri.h>

#include "inkscapestream.h"


namespace Inkscape
{
namespace IO
{

//#########################################################################
//# U R I    I N P U T    S T R E A M   /   R E A D E R
//#########################################################################

/**
 * This class is for receiving a stream of data from a resource
 * defined in a URI
 */
class UriInputStream : public InputStream
{

public:
    UriInputStream(FILE *source, Inkscape::URI &uri) throw(StreamException);

    UriInputStream(Inkscape::URI &source) throw(StreamException);

    virtual ~UriInputStream() throw(StreamException);

    virtual int available() throw(StreamException);

    virtual void close() throw(StreamException);

    virtual int get() throw(StreamException);

private:

    bool closed;

    FILE *inf;           //for file: uris
    unsigned char *data; //for data: uris
    int dataPos;         //  current read position in data field
    int dataLen;         //  length of data buffer

    Inkscape::URI &uri;

    int scheme;

}; // class UriInputStream




/**
 * This class is for receiving a stream of formatted data from a resource
 * defined in a URI
 */
class UriReader : public BasicReader
{

public:

    UriReader(Inkscape::URI &source) throw(StreamException);

    virtual ~UriReader() throw(StreamException);

    virtual int available() throw(StreamException);

    virtual void close() throw(StreamException);

    virtual gunichar get() throw(StreamException);

private:

    UriInputStream *inputStream;

}; // class UriReader



//#########################################################################
//# U R I    O U T P U T    S T R E A M    /    W R I T E R
//#########################################################################

/**
 * This class is for sending a stream to a destination resource
 * defined in a URI
 *
 */
class UriOutputStream : public OutputStream
{

public:

    UriOutputStream(FILE *fp, Inkscape::URI &destination) throw(StreamException);

    UriOutputStream(Inkscape::URI &destination) throw(StreamException);

    virtual ~UriOutputStream() throw(StreamException);

    virtual void close() throw(StreamException);

    virtual void flush() throw(StreamException);

    virtual void put(int ch) throw(StreamException);

private:

    bool closed;
    bool ownsFile;

    FILE *outf;         //for file: uris
    Glib::ustring data; //for data: uris

    Inkscape::URI &uri;

    int scheme;

}; // class UriOutputStream





/**
 * This class is for sending a stream of formatted data to a resource
 * defined in a URI
 */
class UriWriter : public BasicWriter
{

public:

    UriWriter(Inkscape::URI &source) throw(StreamException);

    virtual ~UriWriter() throw(StreamException);

    virtual void close() throw(StreamException);

    virtual void flush() throw(StreamException);

    virtual void put(gunichar ch) throw(StreamException);

private:

    UriOutputStream *outputStream;

}; // class UriReader






} // namespace IO
} // namespace Inkscape


#endif /* __INKSCAPE_IO_URISTREAM_H__ */