1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19  
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 /*
25  * Conversion parameters:
26  * inFile  = GBufferedInputStream.html
27  * outPack = gio
28  * outFile = BufferedInputStream
29  * strct   = GBufferedInputStream
30  * realStrct=
31  * ctorStrct=GInputStream
32  * clss    = BufferedInputStream
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_buffered_input_stream_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.ErrorG
47  * 	- glib.GException
48  * 	- gio.AsyncResultIF
49  * 	- gio.Cancellable
50  * 	- gio.InputStream
51  * structWrap:
52  * 	- GAsyncResult* -> AsyncResultIF
53  * 	- GCancellable* -> Cancellable
54  * 	- GInputStream* -> InputStream
55  * module aliases:
56  * local aliases:
57  * overrides:
58  */
59 
60 module gio.BufferedInputStream;
61 
62 public  import gtkc.giotypes;
63 
64 private import gtkc.gio;
65 private import glib.ConstructionException;
66 private import gobject.ObjectG;
67 
68 private import glib.ErrorG;
69 private import glib.GException;
70 private import gio.AsyncResultIF;
71 private import gio.Cancellable;
72 private import gio.InputStream;
73 
74 
75 private import gio.FilterInputStream;
76 
77 /**
78  * Buffered input stream implements GFilterInputStream and provides
79  * for buffered reads.
80  *
81  * By default, GBufferedInputStream's buffer size is set at 4 kilobytes.
82  *
83  * To create a buffered input stream, use g_buffered_input_stream_new(),
84  * or g_buffered_input_stream_new_sized() to specify the buffer's size at
85  * construction.
86  *
87  * To get the size of a buffer within a buffered input stream, use
88  * g_buffered_input_stream_get_buffer_size(). To change the size of a
89  * buffered input stream's buffer, use
90  * g_buffered_input_stream_set_buffer_size(). Note that the buffer's size
91  * cannot be reduced below the size of the data within the buffer.
92  */
93 public class BufferedInputStream : FilterInputStream
94 {
95 	
96 	/** the main Gtk struct */
97 	protected GBufferedInputStream* gBufferedInputStream;
98 	
99 	
100 	/** Get the main Gtk struct */
101 	public GBufferedInputStream* getBufferedInputStreamStruct()
102 	{
103 		return gBufferedInputStream;
104 	}
105 	
106 	
107 	/** the main Gtk struct as a void* */
108 	protected override void* getStruct()
109 	{
110 		return cast(void*)gBufferedInputStream;
111 	}
112 	
113 	/**
114 	 * Sets our main struct and passes it to the parent class
115 	 */
116 	public this (GBufferedInputStream* gBufferedInputStream)
117 	{
118 		super(cast(GFilterInputStream*)gBufferedInputStream);
119 		this.gBufferedInputStream = gBufferedInputStream;
120 	}
121 	
122 	protected override void setStruct(GObject* obj)
123 	{
124 		super.setStruct(obj);
125 		gBufferedInputStream = cast(GBufferedInputStream*)obj;
126 	}
127 	
128 	/**
129 	 */
130 	
131 	/**
132 	 * Creates a new GInputStream from the given base_stream, with
133 	 * a buffer set to the default size (4 kilobytes).
134 	 * Params:
135 	 * baseStream = a GInputStream
136 	 * Throws: ConstructionException GTK+ fails to create the object.
137 	 */
138 	public this (InputStream baseStream)
139 	{
140 		// GInputStream * g_buffered_input_stream_new (GInputStream *base_stream);
141 		auto p = g_buffered_input_stream_new((baseStream is null) ? null : baseStream.getInputStreamStruct());
142 		if(p is null)
143 		{
144 			throw new ConstructionException("null returned by g_buffered_input_stream_new((baseStream is null) ? null : baseStream.getInputStreamStruct())");
145 		}
146 		this(cast(GBufferedInputStream*) p);
147 	}
148 	
149 	/**
150 	 * Creates a new GBufferedInputStream from the given base_stream,
151 	 * with a buffer set to size.
152 	 * Params:
153 	 * baseStream = a GInputStream
154 	 * size = a gsize
155 	 * Throws: ConstructionException GTK+ fails to create the object.
156 	 */
157 	public this (InputStream baseStream, gsize size)
158 	{
159 		// GInputStream * g_buffered_input_stream_new_sized (GInputStream *base_stream,  gsize size);
160 		auto p = g_buffered_input_stream_new_sized((baseStream is null) ? null : baseStream.getInputStreamStruct(), size);
161 		if(p is null)
162 		{
163 			throw new ConstructionException("null returned by g_buffered_input_stream_new_sized((baseStream is null) ? null : baseStream.getInputStreamStruct(), size)");
164 		}
165 		this(cast(GBufferedInputStream*) p);
166 	}
167 	
168 	/**
169 	 * Gets the size of the input buffer.
170 	 * Returns: the current buffer size.
171 	 */
172 	public gsize getBufferSize()
173 	{
174 		// gsize g_buffered_input_stream_get_buffer_size  (GBufferedInputStream *stream);
175 		return g_buffered_input_stream_get_buffer_size(gBufferedInputStream);
176 	}
177 	
178 	/**
179 	 * Sets the size of the internal buffer of stream to size, or to the
180 	 * size of the contents of the buffer. The buffer can never be resized
181 	 * smaller than its current contents.
182 	 * Params:
183 	 * size = a gsize
184 	 */
185 	public void setBufferSize(gsize size)
186 	{
187 		// void g_buffered_input_stream_set_buffer_size  (GBufferedInputStream *stream,  gsize size);
188 		g_buffered_input_stream_set_buffer_size(gBufferedInputStream, size);
189 	}
190 	
191 	/**
192 	 * Gets the size of the available data within the stream.
193 	 * Returns: size of the available stream.
194 	 */
195 	public gsize getAvailable()
196 	{
197 		// gsize g_buffered_input_stream_get_available  (GBufferedInputStream *stream);
198 		return g_buffered_input_stream_get_available(gBufferedInputStream);
199 	}
200 	
201 	/**
202 	 * Returns the buffer with the currently available bytes. The returned
203 	 * buffer must not be modified and will become invalid when reading from
204 	 * the stream or filling the buffer.
205 	 * Params:
206 	 * count = a gsize to get the number of bytes available in the buffer. [out]
207 	 * Returns: read-only buffer. [array length=count][element-type guint8][transfer none]
208 	 */
209 	public void* peekBuffer(out gsize count)
210 	{
211 		// const void * g_buffered_input_stream_peek_buffer (GBufferedInputStream *stream,  gsize *count);
212 		return g_buffered_input_stream_peek_buffer(gBufferedInputStream, &count);
213 	}
214 	
215 	/**
216 	 * Peeks in the buffer, copying data of size count into buffer,
217 	 * offset offset bytes.
218 	 * Params:
219 	 * buffer = a pointer to
220 	 * an allocated chunk of memory. [array length=count][element-type guint8]
221 	 * offset = a gsize
222 	 * count = a gsize
223 	 * Returns: a gsize of the number of bytes peeked, or -1 on error.
224 	 */
225 	public gsize peek(void* buffer, gsize offset, gsize count)
226 	{
227 		// gsize g_buffered_input_stream_peek (GBufferedInputStream *stream,  void *buffer,  gsize offset,  gsize count);
228 		return g_buffered_input_stream_peek(gBufferedInputStream, buffer, offset, count);
229 	}
230 	
231 	/**
232 	 * Tries to read count bytes from the stream into the buffer.
233 	 * Will block during this read.
234 	 * If count is zero, returns zero and does nothing. A value of count
235 	 * larger than G_MAXSSIZE will cause a G_IO_ERROR_INVALID_ARGUMENT error.
236 	 * On success, the number of bytes read into the buffer is returned.
237 	 * It is not an error if this is not the same as the requested size, as it
238 	 * can happen e.g. near the end of a file. Zero is returned on end of file
239 	 * (or if count is zero), but never otherwise.
240 	 * If count is -1 then the attempted read size is equal to the number of
241 	 * bytes that are required to fill the buffer.
242 	 * If cancellable is not NULL, then the operation can be cancelled by
243 	 * triggering the cancellable object from another thread. If the operation
244 	 * was cancelled, the error G_IO_ERROR_CANCELLED will be returned. If an
245 	 * operation was partially finished when the operation was cancelled the
246 	 * partial result will be returned, without an error.
247 	 * On error -1 is returned and error is set accordingly.
248 	 * For the asynchronous, non-blocking, version of this function, see
249 	 * g_buffered_input_stream_fill_async().
250 	 * Params:
251 	 * count = the number of bytes that will be read from the stream
252 	 * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
253 	 * Returns: the number of bytes read into stream's buffer, up to count, or -1 on error.
254 	 * Throws: GException on failure.
255 	 */
256 	public gssize fill(gssize count, Cancellable cancellable)
257 	{
258 		// gssize g_buffered_input_stream_fill (GBufferedInputStream *stream,  gssize count,  GCancellable *cancellable,  GError **error);
259 		GError* err = null;
260 		
261 		auto p = g_buffered_input_stream_fill(gBufferedInputStream, count, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
262 		
263 		if (err !is null)
264 		{
265 			throw new GException( new ErrorG(err) );
266 		}
267 		
268 		return p;
269 	}
270 	
271 	/**
272 	 * Reads data into stream's buffer asynchronously, up to count size.
273 	 * io_priority can be used to prioritize reads. For the synchronous
274 	 * version of this function, see g_buffered_input_stream_fill().
275 	 * If count is -1 then the attempted read size is equal to the number
276 	 * of bytes that are required to fill the buffer.
277 	 * Params:
278 	 * count = the number of bytes that will be read from the stream
279 	 * ioPriority = the I/O priority
280 	 * of the request
281 	 * cancellable = optional GCancellable object. [allow-none]
282 	 * callback = a GAsyncReadyCallback. [scope async]
283 	 * userData = a gpointer. [closure]
284 	 */
285 	public void fillAsync(gssize count, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
286 	{
287 		// void g_buffered_input_stream_fill_async (GBufferedInputStream *stream,  gssize count,  int io_priority,  GCancellable *cancellable,  GAsyncReadyCallback callback,  gpointer user_data);
288 		g_buffered_input_stream_fill_async(gBufferedInputStream, count, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
289 	}
290 	
291 	/**
292 	 * Finishes an asynchronous read.
293 	 * Params:
294 	 * result = a GAsyncResult
295 	 * Returns: a gssize of the read stream, or -1 on an error.
296 	 * Throws: GException on failure.
297 	 */
298 	public gssize fillFinish(AsyncResultIF result)
299 	{
300 		// gssize g_buffered_input_stream_fill_finish (GBufferedInputStream *stream,  GAsyncResult *result,  GError **error);
301 		GError* err = null;
302 		
303 		auto p = g_buffered_input_stream_fill_finish(gBufferedInputStream, (result is null) ? null : result.getAsyncResultTStruct(), &err);
304 		
305 		if (err !is null)
306 		{
307 			throw new GException( new ErrorG(err) );
308 		}
309 		
310 		return p;
311 	}
312 	
313 	/**
314 	 * Tries to read a single byte from the stream or the buffer. Will block
315 	 * during this read.
316 	 * On success, the byte read from the stream is returned. On end of stream
317 	 * -1 is returned but it's not an exceptional error and error is not set.
318 	 * If cancellable is not NULL, then the operation can be cancelled by
319 	 * triggering the cancellable object from another thread. If the operation
320 	 * was cancelled, the error G_IO_ERROR_CANCELLED will be returned. If an
321 	 * operation was partially finished when the operation was cancelled the
322 	 * partial result will be returned, without an error.
323 	 * On error -1 is returned and error is set accordingly.
324 	 * Params:
325 	 * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
326 	 * Returns: the byte read from the stream, or -1 on end of stream or error.
327 	 * Throws: GException on failure.
328 	 */
329 	public int readByte(Cancellable cancellable)
330 	{
331 		// int g_buffered_input_stream_read_byte (GBufferedInputStream *stream,  GCancellable *cancellable,  GError **error);
332 		GError* err = null;
333 		
334 		auto p = g_buffered_input_stream_read_byte(gBufferedInputStream, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
335 		
336 		if (err !is null)
337 		{
338 			throw new GException( new ErrorG(err) );
339 		}
340 		
341 		return p;
342 	}
343 }