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 = GDataInputStream.html 27 * outPack = gio 28 * outFile = DataInputStream 29 * strct = GDataInputStream 30 * realStrct= 31 * ctorStrct= 32 * clss = DataInputStream 33 * interf = 34 * class Code: No 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - g_data_input_stream_ 41 * omit structs: 42 * omit prefixes: 43 * omit code: 44 * - g_data_input_stream_read_byte 45 * omit signals: 46 * imports: 47 * - glib.Str 48 * - glib.ErrorG 49 * - glib.GException 50 * - gio.Cancellable 51 * - gio.InputStream 52 * structWrap: 53 * - GCancellable* -> Cancellable 54 * - GInputStream* -> InputStream 55 * module aliases: 56 * local aliases: 57 * overrides: 58 */ 59 60 module gio.DataInputStream; 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.Str; 70 private import glib.ErrorG; 71 private import glib.GException; 72 private import gio.Cancellable; 73 private import gio.InputStream; 74 75 76 77 private import gio.BufferedInputStream; 78 79 /** 80 * Description 81 * Data input stream implements GInputStream and includes functions for 82 * reading structured data directly from a binary input stream. 83 */ 84 public class DataInputStream : BufferedInputStream 85 { 86 87 /** the main Gtk struct */ 88 protected GDataInputStream* gDataInputStream; 89 90 91 public GDataInputStream* getDataInputStreamStruct() 92 { 93 return gDataInputStream; 94 } 95 96 97 /** the main Gtk struct as a void* */ 98 protected override void* getStruct() 99 { 100 return cast(void*)gDataInputStream; 101 } 102 103 /** 104 * Sets our main struct and passes it to the parent class 105 */ 106 public this (GDataInputStream* gDataInputStream) 107 { 108 super(cast(GBufferedInputStream*)gDataInputStream); 109 this.gDataInputStream = gDataInputStream; 110 } 111 112 protected override void setStruct(GObject* obj) 113 { 114 super.setStruct(obj); 115 gDataInputStream = cast(GDataInputStream*)obj; 116 } 117 118 /** 119 */ 120 121 /** 122 * Creates a new data input stream for the base_stream. 123 * Params: 124 * baseStream = a GInputStream. 125 * Throws: ConstructionException GTK+ fails to create the object. 126 */ 127 public this (InputStream baseStream) 128 { 129 // GDataInputStream * g_data_input_stream_new (GInputStream *base_stream); 130 auto p = g_data_input_stream_new((baseStream is null) ? null : baseStream.getInputStreamStruct()); 131 if(p is null) 132 { 133 throw new ConstructionException("null returned by g_data_input_stream_new((baseStream is null) ? null : baseStream.getInputStreamStruct())"); 134 } 135 this(cast(GDataInputStream*) p); 136 } 137 138 /** 139 * This function sets the byte order for the given stream. All subsequent 140 * reads from the stream will be read in the given order. 141 * Params: 142 * order = a GDataStreamByteOrder to set. 143 */ 144 public void setByteOrder(GDataStreamByteOrder order) 145 { 146 // void g_data_input_stream_set_byte_order (GDataInputStream *stream, GDataStreamByteOrder order); 147 g_data_input_stream_set_byte_order(gDataInputStream, order); 148 } 149 150 /** 151 * Gets the byte order for the data input stream. 152 * Returns: the stream's current GDataStreamByteOrder. 153 */ 154 public GDataStreamByteOrder getByteOrder() 155 { 156 // GDataStreamByteOrder g_data_input_stream_get_byte_order (GDataInputStream *stream); 157 return g_data_input_stream_get_byte_order(gDataInputStream); 158 } 159 160 /** 161 * Sets the newline type for the stream. 162 * Note that using G_DATA_STREAM_NEWLINE_TYPE_ANY is slightly unsafe. If a read 163 * chunk ends in "CR" we must read an additional byte to know if this is "CR" or 164 * "CR LF", and this might block if there is no more data availible. 165 * Params: 166 * type = the type of new line return as GDataStreamNewlineType. 167 */ 168 public void setNewlineType(GDataStreamNewlineType type) 169 { 170 // void g_data_input_stream_set_newline_type (GDataInputStream *stream, GDataStreamNewlineType type); 171 g_data_input_stream_set_newline_type(gDataInputStream, type); 172 } 173 174 /** 175 * Gets the current newline type for the stream. 176 * Returns: GDataStreamNewlineType for the given stream. 177 */ 178 public GDataStreamNewlineType getNewlineType() 179 { 180 // GDataStreamNewlineType g_data_input_stream_get_newline_type (GDataInputStream *stream); 181 return g_data_input_stream_get_newline_type(gDataInputStream); 182 } 183 184 /** 185 * Reads a 16-bit/2-byte value from stream. 186 * In order to get the correct byte order for this read operation, 187 * see g_data_input_stream_get_byte_order() and g_data_input_stream_set_byte_order(). 188 * Params: 189 * cancellable = optional GCancellable object, NULL to ignore. [allow-none] 190 * Returns: a signed 16-bit/2-byte value read from stream or 0 if an error occurred. 191 * Throws: GException on failure. 192 */ 193 public short readInt16(Cancellable cancellable) 194 { 195 // gint16 g_data_input_stream_read_int16 (GDataInputStream *stream, GCancellable *cancellable, GError **error); 196 GError* err = null; 197 198 auto p = g_data_input_stream_read_int16(gDataInputStream, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 199 200 if (err !is null) 201 { 202 throw new GException( new ErrorG(err) ); 203 } 204 205 return p; 206 } 207 208 /** 209 * Reads an unsigned 16-bit/2-byte value from stream. 210 * In order to get the correct byte order for this read operation, 211 * see g_data_input_stream_get_byte_order() and g_data_input_stream_set_byte_order(). 212 * Params: 213 * cancellable = optional GCancellable object, NULL to ignore. [allow-none] 214 * Returns: an unsigned 16-bit/2-byte value read from the stream or 0 if an error occurred. 215 * Throws: GException on failure. 216 */ 217 public ushort readUint16(Cancellable cancellable) 218 { 219 // guint16 g_data_input_stream_read_uint16 (GDataInputStream *stream, GCancellable *cancellable, GError **error); 220 GError* err = null; 221 222 auto p = g_data_input_stream_read_uint16(gDataInputStream, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 223 224 if (err !is null) 225 { 226 throw new GException( new ErrorG(err) ); 227 } 228 229 return p; 230 } 231 232 /** 233 * Reads a signed 32-bit/4-byte value from stream. 234 * In order to get the correct byte order for this read operation, 235 * see g_data_input_stream_get_byte_order() and g_data_input_stream_set_byte_order(). 236 * If cancellable is not NULL, then the operation can be cancelled by 237 * triggering the cancellable object from another thread. If the operation 238 * was cancelled, the error G_IO_ERROR_CANCELLED will be returned. 239 * Params: 240 * cancellable = optional GCancellable object, NULL to ignore. [allow-none] 241 * Returns: a signed 32-bit/4-byte value read from the stream or 0 if an error occurred. 242 * Throws: GException on failure. 243 */ 244 public int readInt32(Cancellable cancellable) 245 { 246 // gint32 g_data_input_stream_read_int32 (GDataInputStream *stream, GCancellable *cancellable, GError **error); 247 GError* err = null; 248 249 auto p = g_data_input_stream_read_int32(gDataInputStream, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 250 251 if (err !is null) 252 { 253 throw new GException( new ErrorG(err) ); 254 } 255 256 return p; 257 } 258 259 /** 260 * Reads an unsigned 32-bit/4-byte value from stream. 261 * In order to get the correct byte order for this read operation, 262 * see g_data_input_stream_get_byte_order() and g_data_input_stream_set_byte_order(). 263 * If cancellable is not NULL, then the operation can be cancelled by 264 * triggering the cancellable object from another thread. If the operation 265 * was cancelled, the error G_IO_ERROR_CANCELLED will be returned. 266 * Params: 267 * cancellable = optional GCancellable object, NULL to ignore. [allow-none] 268 * Returns: an unsigned 32-bit/4-byte value read from the stream or 0 if an error occurred. 269 * Throws: GException on failure. 270 */ 271 public uint readUint32(Cancellable cancellable) 272 { 273 // guint32 g_data_input_stream_read_uint32 (GDataInputStream *stream, GCancellable *cancellable, GError **error); 274 GError* err = null; 275 276 auto p = g_data_input_stream_read_uint32(gDataInputStream, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 277 278 if (err !is null) 279 { 280 throw new GException( new ErrorG(err) ); 281 } 282 283 return p; 284 } 285 286 /** 287 * Reads a 64-bit/8-byte value from stream. 288 * In order to get the correct byte order for this read operation, 289 * see g_data_input_stream_get_byte_order() and g_data_input_stream_set_byte_order(). 290 * If cancellable is not NULL, then the operation can be cancelled by 291 * triggering the cancellable object from another thread. If the operation 292 * was cancelled, the error G_IO_ERROR_CANCELLED will be returned. 293 * Params: 294 * cancellable = optional GCancellable object, NULL to ignore. [allow-none] 295 * Returns: a signed 64-bit/8-byte value read from stream or 0 if an error occurred. 296 * Throws: GException on failure. 297 */ 298 public long readInt64(Cancellable cancellable) 299 { 300 // gint64 g_data_input_stream_read_int64 (GDataInputStream *stream, GCancellable *cancellable, GError **error); 301 GError* err = null; 302 303 auto p = g_data_input_stream_read_int64(gDataInputStream, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 304 305 if (err !is null) 306 { 307 throw new GException( new ErrorG(err) ); 308 } 309 310 return p; 311 } 312 313 /** 314 * Reads an unsigned 64-bit/8-byte value from stream. 315 * In order to get the correct byte order for this read operation, 316 * see g_data_input_stream_get_byte_order(). 317 * If cancellable is not NULL, then the operation can be cancelled by 318 * triggering the cancellable object from another thread. If the operation 319 * was cancelled, the error G_IO_ERROR_CANCELLED will be returned. 320 * Params: 321 * cancellable = optional GCancellable object, NULL to ignore. [allow-none] 322 * Returns: an unsigned 64-bit/8-byte read from stream or 0 if an error occurred. 323 * Throws: GException on failure. 324 */ 325 public ulong readUint64(Cancellable cancellable) 326 { 327 // guint64 g_data_input_stream_read_uint64 (GDataInputStream *stream, GCancellable *cancellable, GError **error); 328 GError* err = null; 329 330 auto p = g_data_input_stream_read_uint64(gDataInputStream, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 331 332 if (err !is null) 333 { 334 throw new GException( new ErrorG(err) ); 335 } 336 337 return p; 338 } 339 340 /** 341 * Reads a line from the data input stream. 342 * If cancellable is not NULL, then the operation can be cancelled by 343 * triggering the cancellable object from another thread. If the operation 344 * was cancelled, the error G_IO_ERROR_CANCELLED will be returned. 345 * Params: 346 * cancellable = optional GCancellable object, NULL to ignore. [allow-none] 347 * Returns: a string with the line that was read in (without the newlines). Set length to a gsize to get the length of the read line. On an error, it will return NULL and error will be set. If there's no content to read, it will still return NULL, but error won't be set. [transfer full] 348 * Throws: GException on failure. 349 */ 350 public string readLine(Cancellable cancellable) 351 { 352 // char * g_data_input_stream_read_line (GDataInputStream *stream, gsize *length, GCancellable *cancellable, GError **error); 353 gsize length; 354 GError* err = null; 355 356 auto p = g_data_input_stream_read_line(gDataInputStream, &length, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 357 358 if (err !is null) 359 { 360 throw new GException( new ErrorG(err) ); 361 } 362 363 return Str.toString(p, length); 364 } 365 366 /** 367 * The asynchronous version of g_data_input_stream_read_line(). It is 368 * an error to have two outstanding calls to this function. 369 * When the operation is finished, callback will be called. You 370 * can then call g_data_input_stream_read_line_finish() to get 371 * the result of the operation. 372 * Since 2.20 373 * Params: 374 * ioPriority = the I/O priority 375 * of the request. 376 * cancellable = optional GCancellable object, NULL to ignore. [allow-none] 377 * callback = callback to call when the request is satisfied. [scope async] 378 * userData = the data to pass to callback function. [closure] 379 */ 380 public void readLineAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 381 { 382 // void g_data_input_stream_read_line_async (GDataInputStream *stream, gint io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); 383 g_data_input_stream_read_line_async(gDataInputStream, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 384 } 385 386 /** 387 * Finish an asynchronous call started by 388 * g_data_input_stream_read_line_async(). 389 * Since 2.20 390 * Params: 391 * result = the GAsyncResult that was provided to the callback. 392 * Returns: a string with the line that was read in (without the newlines). Set length to a gsize to get the length of the read line. On an error, it will return NULL and error will be set. If there's no content to read, it will still return NULL, but error won't be set. [transfer full] 393 * Throws: GException on failure. 394 */ 395 public string readLineFinish(out GAsyncResult result) 396 { 397 // char * g_data_input_stream_read_line_finish (GDataInputStream *stream, GAsyncResult *result, gsize *length, GError **error); 398 gsize length; 399 GError* err = null; 400 401 auto p = g_data_input_stream_read_line_finish(gDataInputStream, &result, &length, &err); 402 403 if (err !is null) 404 { 405 throw new GException( new ErrorG(err) ); 406 } 407 408 return Str.toString(p, length); 409 } 410 411 /** 412 * Reads a string from the data input stream, up to the first 413 * occurrence of any of the stop characters. 414 * In contrast to g_data_input_stream_read_until(), this function 415 * does not consume the stop character. You have 416 * to use g_data_input_stream_read_byte() to get it before calling 417 * g_data_input_stream_read_upto() again. 418 * Note that stop_chars may contain '\0' if stop_chars_len is 419 * specified. 420 * Since 2.24 421 * Params: 422 * stopChars = characters to terminate the read 423 * cancellable = optional GCancellable object, NULL to ignore. [allow-none] 424 * Returns: a string with the data that was read before encountering any of the stop characters. Set length to a gsize to get the length of the string. This function will return NULL on an error. [transfer full] 425 * Throws: GException on failure. 426 */ 427 public string readUpto(string stopChars, Cancellable cancellable) 428 { 429 // char * g_data_input_stream_read_upto (GDataInputStream *stream, const gchar *stop_chars, gssize stop_chars_len, gsize *length, GCancellable *cancellable, GError **error); 430 gsize length; 431 GError* err = null; 432 433 auto p = g_data_input_stream_read_upto(gDataInputStream, cast(char*)stopChars.ptr, cast(int) stopChars.length, &length, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 434 435 if (err !is null) 436 { 437 throw new GException( new ErrorG(err) ); 438 } 439 440 return Str.toString(p, length); 441 } 442 443 /** 444 * The asynchronous version of g_data_input_stream_read_upto(). 445 * It is an error to have two outstanding calls to this function. 446 * In contrast to g_data_input_stream_read_until(), this function 447 * does not consume the stop character. You have 448 * to use g_data_input_stream_read_byte() to get it before calling 449 * g_data_input_stream_read_upto() again. 450 * Note that stop_chars may contain '\0' if stop_chars_len is 451 * specified. 452 * When the operation is finished, callback will be called. You 453 * can then call g_data_input_stream_read_upto_finish() to get 454 * the result of the operation. 455 * Since 2.24 456 * Params: 457 * stopChars = characters to terminate the read 458 * ioPriority = the I/O priority 459 * of the request. 460 * cancellable = optional GCancellable object, NULL to ignore. [allow-none] 461 * callback = callback to call when the request is satisfied. [scope async] 462 * userData = the data to pass to callback function. [closure] 463 */ 464 public void readUptoAsync(string stopChars, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 465 { 466 // void g_data_input_stream_read_upto_async (GDataInputStream *stream, const gchar *stop_chars, gssize stop_chars_len, gint io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); 467 g_data_input_stream_read_upto_async(gDataInputStream, cast(char*)stopChars.ptr, cast(int) stopChars.length, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 468 } 469 470 /** 471 * Finish an asynchronous call started by 472 * g_data_input_stream_read_upto_async(). 473 * Note that this function does not consume the 474 * stop character. You have to use g_data_input_stream_read_byte() to 475 * get it before calling g_data_input_stream_read_upto_async() again. 476 * Since 2.24 477 * Params: 478 * result = the GAsyncResult that was provided to the callback 479 * Returns: a string with the data that was read before encountering any of the stop characters. Set length to a gsize to get the length of the string. This function will return NULL on an error. [transfer full] 480 * Throws: GException on failure. 481 */ 482 public string readUptoFinish(out GAsyncResult result) 483 { 484 // char * g_data_input_stream_read_upto_finish (GDataInputStream *stream, GAsyncResult *result, gsize *length, GError **error); 485 gsize length; 486 GError* err = null; 487 488 auto p = g_data_input_stream_read_upto_finish(gDataInputStream, &result, &length, &err); 489 490 if (err !is null) 491 { 492 throw new GException( new ErrorG(err) ); 493 } 494 495 return Str.toString(p, length); 496 } 497 498 /** 499 * Reads a string from the data input stream, up to the first 500 * occurrence of any of the stop characters. 501 * Note that, in contrast to g_data_input_stream_read_until_async(), 502 * this function consumes the stop character that it finds. 503 * Don't use this function in new code. Its functionality is 504 * inconsistent with g_data_input_stream_read_until_async(). Both 505 * functions will be marked as deprecated in a future release. Use 506 * g_data_input_stream_read_upto() instead, but note that that function 507 * does not consume the stop character. 508 * Params: 509 * stopChars = characters to terminate the read. 510 * cancellable = optional GCancellable object, NULL to ignore. [allow-none] 511 * Returns: a string with the data that was read before encountering any of the stop characters. Set length to a gsize to get the length of the string. This function will return NULL on an error. [transfer full] 512 * Throws: GException on failure. 513 */ 514 public string readUntil(string stopChars, Cancellable cancellable) 515 { 516 // char * g_data_input_stream_read_until (GDataInputStream *stream, const gchar *stop_chars, gsize *length, GCancellable *cancellable, GError **error); 517 gsize length; 518 GError* err = null; 519 520 auto p = g_data_input_stream_read_until(gDataInputStream, Str.toStringz(stopChars), &length, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 521 522 if (err !is null) 523 { 524 throw new GException( new ErrorG(err) ); 525 } 526 527 return Str.toString(p, length); 528 } 529 530 /** 531 * The asynchronous version of g_data_input_stream_read_until(). 532 * It is an error to have two outstanding calls to this function. 533 * Note that, in contrast to g_data_input_stream_read_until(), 534 * this function does not consume the stop character that it finds. You 535 * must read it for yourself. 536 * When the operation is finished, callback will be called. You 537 * can then call g_data_input_stream_read_until_finish() to get 538 * the result of the operation. 539 * Don't use this function in new code. Its functionality is 540 * inconsistent with g_data_input_stream_read_until(). Both functions 541 * will be marked as deprecated in a future release. Use 542 * g_data_input_stream_read_upto_async() instead. 543 * Since 2.20 544 * Params: 545 * stopChars = characters to terminate the read. 546 * ioPriority = the I/O priority 547 * of the request. 548 * cancellable = optional GCancellable object, NULL to ignore. [allow-none] 549 * callback = callback to call when the request is satisfied. [scope async] 550 * userData = the data to pass to callback function. [closure] 551 */ 552 public void readUntilAsync(string stopChars, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 553 { 554 // void g_data_input_stream_read_until_async (GDataInputStream *stream, const gchar *stop_chars, gint io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); 555 g_data_input_stream_read_until_async(gDataInputStream, Str.toStringz(stopChars), ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 556 } 557 558 /** 559 * Finish an asynchronous call started by 560 * g_data_input_stream_read_until_async(). 561 * Since 2.20 562 * Params: 563 * result = the GAsyncResult that was provided to the callback. 564 * Returns: a string with the data that was read before encountering any of the stop characters. Set length to a gsize to get the length of the string. This function will return NULL on an error. [transfer full] 565 * Throws: GException on failure. 566 */ 567 public string readUntilFinish(out GAsyncResult result) 568 { 569 // char * g_data_input_stream_read_until_finish (GDataInputStream *stream, GAsyncResult *result, gsize *length, GError **error); 570 gsize length; 571 GError* err = null; 572 573 auto p = g_data_input_stream_read_until_finish(gDataInputStream, &result, &length, &err); 574 575 if (err !is null) 576 { 577 throw new GException( new ErrorG(err) ); 578 } 579 580 return Str.toString(p, length); 581 } 582 }