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 69 private import glib.ErrorG; 70 private import glib.GException; 71 private import gio.AsyncResultIF; 72 private import gio.Cancellable; 73 private import gio.InputStream; 74 75 76 77 private import gio.FilterInputStream; 78 79 /** 80 * Buffered input stream implements GFilterInputStream and provides 81 * for buffered reads. 82 * 83 * By default, GBufferedInputStream's buffer size is set at 4 kilobytes. 84 * 85 * To create a buffered input stream, use g_buffered_input_stream_new(), 86 * or g_buffered_input_stream_new_sized() to specify the buffer's size at 87 * construction. 88 * 89 * To get the size of a buffer within a buffered input stream, use 90 * g_buffered_input_stream_get_buffer_size(). To change the size of a 91 * buffered input stream's buffer, use 92 * g_buffered_input_stream_set_buffer_size(). Note that the buffer's size 93 * cannot be reduced below the size of the data within the buffer. 94 */ 95 public class BufferedInputStream : FilterInputStream 96 { 97 98 /** the main Gtk struct */ 99 protected GBufferedInputStream* gBufferedInputStream; 100 101 102 public GBufferedInputStream* getBufferedInputStreamStruct() 103 { 104 return gBufferedInputStream; 105 } 106 107 108 /** the main Gtk struct as a void* */ 109 protected override void* getStruct() 110 { 111 return cast(void*)gBufferedInputStream; 112 } 113 114 /** 115 * Sets our main struct and passes it to the parent class 116 */ 117 public this (GBufferedInputStream* gBufferedInputStream) 118 { 119 super(cast(GFilterInputStream*)gBufferedInputStream); 120 this.gBufferedInputStream = gBufferedInputStream; 121 } 122 123 protected override void setStruct(GObject* obj) 124 { 125 super.setStruct(obj); 126 gBufferedInputStream = cast(GBufferedInputStream*)obj; 127 } 128 129 /** 130 */ 131 132 /** 133 * Creates a new GInputStream from the given base_stream, with 134 * a buffer set to the default size (4 kilobytes). 135 * Params: 136 * baseStream = a GInputStream 137 * Throws: ConstructionException GTK+ fails to create the object. 138 */ 139 public this (InputStream baseStream) 140 { 141 // GInputStream * g_buffered_input_stream_new (GInputStream *base_stream); 142 auto p = g_buffered_input_stream_new((baseStream is null) ? null : baseStream.getInputStreamStruct()); 143 if(p is null) 144 { 145 throw new ConstructionException("null returned by g_buffered_input_stream_new((baseStream is null) ? null : baseStream.getInputStreamStruct())"); 146 } 147 this(cast(GBufferedInputStream*) p); 148 } 149 150 /** 151 * Creates a new GBufferedInputStream from the given base_stream, 152 * with a buffer set to size. 153 * Params: 154 * baseStream = a GInputStream 155 * size = a gsize 156 * Throws: ConstructionException GTK+ fails to create the object. 157 */ 158 public this (InputStream baseStream, gsize size) 159 { 160 // GInputStream * g_buffered_input_stream_new_sized (GInputStream *base_stream, gsize size); 161 auto p = g_buffered_input_stream_new_sized((baseStream is null) ? null : baseStream.getInputStreamStruct(), size); 162 if(p is null) 163 { 164 throw new ConstructionException("null returned by g_buffered_input_stream_new_sized((baseStream is null) ? null : baseStream.getInputStreamStruct(), size)"); 165 } 166 this(cast(GBufferedInputStream*) p); 167 } 168 169 /** 170 * Gets the size of the input buffer. 171 * Returns: the current buffer size. 172 */ 173 public gsize getBufferSize() 174 { 175 // gsize g_buffered_input_stream_get_buffer_size (GBufferedInputStream *stream); 176 return g_buffered_input_stream_get_buffer_size(gBufferedInputStream); 177 } 178 179 /** 180 * Sets the size of the internal buffer of stream to size, or to the 181 * size of the contents of the buffer. The buffer can never be resized 182 * smaller than its current contents. 183 * Params: 184 * size = a gsize 185 */ 186 public void setBufferSize(gsize size) 187 { 188 // void g_buffered_input_stream_set_buffer_size (GBufferedInputStream *stream, gsize size); 189 g_buffered_input_stream_set_buffer_size(gBufferedInputStream, size); 190 } 191 192 /** 193 * Gets the size of the available data within the stream. 194 * Returns: size of the available stream. 195 */ 196 public gsize getAvailable() 197 { 198 // gsize g_buffered_input_stream_get_available (GBufferedInputStream *stream); 199 return g_buffered_input_stream_get_available(gBufferedInputStream); 200 } 201 202 /** 203 * Returns the buffer with the currently available bytes. The returned 204 * buffer must not be modified and will become invalid when reading from 205 * the stream or filling the buffer. 206 * Params: 207 * count = a gsize to get the number of bytes available in the buffer. [out] 208 * Returns: read-only buffer. [array length=count][element-type guint8][transfer none] 209 */ 210 public void* peekBuffer(out gsize count) 211 { 212 // const void * g_buffered_input_stream_peek_buffer (GBufferedInputStream *stream, gsize *count); 213 return g_buffered_input_stream_peek_buffer(gBufferedInputStream, &count); 214 } 215 216 /** 217 * Peeks in the buffer, copying data of size count into buffer, 218 * offset offset bytes. 219 * Params: 220 * buffer = a pointer to 221 * an allocated chunk of memory. [array length=count][element-type guint8] 222 * offset = a gsize 223 * count = a gsize 224 * Returns: a gsize of the number of bytes peeked, or -1 on error. 225 */ 226 public gsize peek(void* buffer, gsize offset, gsize count) 227 { 228 // gsize g_buffered_input_stream_peek (GBufferedInputStream *stream, void *buffer, gsize offset, gsize count); 229 return g_buffered_input_stream_peek(gBufferedInputStream, buffer, offset, count); 230 } 231 232 /** 233 * Tries to read count bytes from the stream into the buffer. 234 * Will block during this read. 235 * If count is zero, returns zero and does nothing. A value of count 236 * larger than G_MAXSSIZE will cause a G_IO_ERROR_INVALID_ARGUMENT error. 237 * On success, the number of bytes read into the buffer is returned. 238 * It is not an error if this is not the same as the requested size, as it 239 * can happen e.g. near the end of a file. Zero is returned on end of file 240 * (or if count is zero), but never otherwise. 241 * If count is -1 then the attempted read size is equal to the number of 242 * bytes that are required to fill the buffer. 243 * If cancellable is not NULL, then the operation can be cancelled by 244 * triggering the cancellable object from another thread. If the operation 245 * was cancelled, the error G_IO_ERROR_CANCELLED will be returned. If an 246 * operation was partially finished when the operation was cancelled the 247 * partial result will be returned, without an error. 248 * On error -1 is returned and error is set accordingly. 249 * For the asynchronous, non-blocking, version of this function, see 250 * g_buffered_input_stream_fill_async(). 251 * Params: 252 * count = the number of bytes that will be read from the stream 253 * cancellable = optional GCancellable object, NULL to ignore. [allow-none] 254 * Returns: the number of bytes read into stream's buffer, up to count, or -1 on error. 255 * Throws: GException on failure. 256 */ 257 public gssize fill(gssize count, Cancellable cancellable) 258 { 259 // gssize g_buffered_input_stream_fill (GBufferedInputStream *stream, gssize count, GCancellable *cancellable, GError **error); 260 GError* err = null; 261 262 auto p = g_buffered_input_stream_fill(gBufferedInputStream, count, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 263 264 if (err !is null) 265 { 266 throw new GException( new ErrorG(err) ); 267 } 268 269 return p; 270 } 271 272 /** 273 * Reads data into stream's buffer asynchronously, up to count size. 274 * io_priority can be used to prioritize reads. For the synchronous 275 * version of this function, see g_buffered_input_stream_fill(). 276 * If count is -1 then the attempted read size is equal to the number 277 * of bytes that are required to fill the buffer. 278 * Params: 279 * count = the number of bytes that will be read from the stream 280 * ioPriority = the I/O priority 281 * of the request 282 * cancellable = optional GCancellable object. [allow-none] 283 * callback = a GAsyncReadyCallback. [scope async] 284 * userData = a gpointer. [closure] 285 */ 286 public void fillAsync(gssize count, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 287 { 288 // void g_buffered_input_stream_fill_async (GBufferedInputStream *stream, gssize count, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); 289 g_buffered_input_stream_fill_async(gBufferedInputStream, count, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 290 } 291 292 /** 293 * Finishes an asynchronous read. 294 * Params: 295 * result = a GAsyncResult 296 * Returns: a gssize of the read stream, or -1 on an error. 297 * Throws: GException on failure. 298 */ 299 public gssize fillFinish(AsyncResultIF result) 300 { 301 // gssize g_buffered_input_stream_fill_finish (GBufferedInputStream *stream, GAsyncResult *result, GError **error); 302 GError* err = null; 303 304 auto p = g_buffered_input_stream_fill_finish(gBufferedInputStream, (result is null) ? null : result.getAsyncResultTStruct(), &err); 305 306 if (err !is null) 307 { 308 throw new GException( new ErrorG(err) ); 309 } 310 311 return p; 312 } 313 314 /** 315 * Tries to read a single byte from the stream or the buffer. Will block 316 * during this read. 317 * On success, the byte read from the stream is returned. On end of stream 318 * -1 is returned but it's not an exceptional error and error is not set. 319 * If cancellable is not NULL, then the operation can be cancelled by 320 * triggering the cancellable object from another thread. If the operation 321 * was cancelled, the error G_IO_ERROR_CANCELLED will be returned. If an 322 * operation was partially finished when the operation was cancelled the 323 * partial result will be returned, without an error. 324 * On error -1 is returned and error is set accordingly. 325 * Params: 326 * cancellable = optional GCancellable object, NULL to ignore. [allow-none] 327 * Returns: the byte read from the stream, or -1 on end of stream or error. 328 * Throws: GException on failure. 329 */ 330 public int readByte(Cancellable cancellable) 331 { 332 // int g_buffered_input_stream_read_byte (GBufferedInputStream *stream, GCancellable *cancellable, GError **error); 333 GError* err = null; 334 335 auto p = g_buffered_input_stream_read_byte(gBufferedInputStream, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 336 337 if (err !is null) 338 { 339 throw new GException( new ErrorG(err) ); 340 } 341 342 return p; 343 } 344 }