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