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 module gio.DataInputStream; 26 27 private import gio.AsyncResultIF; 28 private import gio.BufferedInputStream; 29 private import gio.Cancellable; 30 private import gio.InputStream; 31 private import glib.ConstructionException; 32 private import glib.ErrorG; 33 private import glib.GException; 34 private import glib.Str; 35 private import gobject.ObjectG; 36 private import gtkc.gio; 37 public import gtkc.giotypes; 38 39 40 /** 41 * Data input stream implements #GInputStream and includes functions for 42 * reading structured data directly from a binary input stream. 43 */ 44 public class DataInputStream : BufferedInputStream 45 { 46 /** the main Gtk struct */ 47 protected GDataInputStream* gDataInputStream; 48 49 /** Get the main Gtk struct */ 50 public GDataInputStream* getDataInputStreamStruct() 51 { 52 return gDataInputStream; 53 } 54 55 /** the main Gtk struct as a void* */ 56 protected override void* getStruct() 57 { 58 return cast(void*)gDataInputStream; 59 } 60 61 protected override void setStruct(GObject* obj) 62 { 63 gDataInputStream = cast(GDataInputStream*)obj; 64 super.setStruct(obj); 65 } 66 67 /** 68 * Sets our main struct and passes it to the parent class. 69 */ 70 public this (GDataInputStream* gDataInputStream, bool ownedRef = false) 71 { 72 this.gDataInputStream = gDataInputStream; 73 super(cast(GBufferedInputStream*)gDataInputStream, ownedRef); 74 } 75 76 77 /** */ 78 public static GType getType() 79 { 80 return g_data_input_stream_get_type(); 81 } 82 83 /** 84 * Creates a new data input stream for the @base_stream. 85 * 86 * Params: 87 * baseStream = a #GInputStream. 88 * 89 * Return: a new #GDataInputStream. 90 * 91 * Throws: ConstructionException GTK+ fails to create the object. 92 */ 93 public this(InputStream baseStream) 94 { 95 auto p = g_data_input_stream_new((baseStream is null) ? null : baseStream.getInputStreamStruct()); 96 97 if(p is null) 98 { 99 throw new ConstructionException("null returned by new"); 100 } 101 102 this(cast(GDataInputStream*) p, true); 103 } 104 105 /** 106 * Gets the byte order for the data input stream. 107 * 108 * Return: the @stream's current #GDataStreamByteOrder. 109 */ 110 public GDataStreamByteOrder getByteOrder() 111 { 112 return g_data_input_stream_get_byte_order(gDataInputStream); 113 } 114 115 /** 116 * Gets the current newline type for the @stream. 117 * 118 * Return: #GDataStreamNewlineType for the given @stream. 119 */ 120 public GDataStreamNewlineType getNewlineType() 121 { 122 return g_data_input_stream_get_newline_type(gDataInputStream); 123 } 124 125 /** 126 * Reads a 16-bit/2-byte value from @stream. 127 * 128 * In order to get the correct byte order for this read operation, 129 * see g_data_input_stream_get_byte_order() and g_data_input_stream_set_byte_order(). 130 * 131 * Params: 132 * cancellable = optional #GCancellable object, %NULL to ignore. 133 * 134 * Return: a signed 16-bit/2-byte value read from @stream or %0 if 135 * an error occurred. 136 * 137 * Throws: GException on failure. 138 */ 139 public short readInt16(Cancellable cancellable) 140 { 141 GError* err = null; 142 143 auto p = g_data_input_stream_read_int16(gDataInputStream, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 144 145 if (err !is null) 146 { 147 throw new GException( new ErrorG(err) ); 148 } 149 150 return p; 151 } 152 153 /** 154 * Reads a signed 32-bit/4-byte value from @stream. 155 * 156 * In order to get the correct byte order for this read operation, 157 * see g_data_input_stream_get_byte_order() and g_data_input_stream_set_byte_order(). 158 * 159 * If @cancellable is not %NULL, then the operation can be cancelled by 160 * triggering the cancellable object from another thread. If the operation 161 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 162 * 163 * Params: 164 * cancellable = optional #GCancellable object, %NULL to ignore. 165 * 166 * Return: a signed 32-bit/4-byte value read from the @stream or %0 if 167 * an error occurred. 168 * 169 * Throws: GException on failure. 170 */ 171 public int readInt32(Cancellable cancellable) 172 { 173 GError* err = null; 174 175 auto p = g_data_input_stream_read_int32(gDataInputStream, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 176 177 if (err !is null) 178 { 179 throw new GException( new ErrorG(err) ); 180 } 181 182 return p; 183 } 184 185 /** 186 * Reads a 64-bit/8-byte value from @stream. 187 * 188 * In order to get the correct byte order for this read operation, 189 * see g_data_input_stream_get_byte_order() and g_data_input_stream_set_byte_order(). 190 * 191 * If @cancellable is not %NULL, then the operation can be cancelled by 192 * triggering the cancellable object from another thread. If the operation 193 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 194 * 195 * Params: 196 * cancellable = optional #GCancellable object, %NULL to ignore. 197 * 198 * Return: a signed 64-bit/8-byte value read from @stream or %0 if 199 * an error occurred. 200 * 201 * Throws: GException on failure. 202 */ 203 public long readInt64(Cancellable cancellable) 204 { 205 GError* err = null; 206 207 auto p = g_data_input_stream_read_int64(gDataInputStream, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 208 209 if (err !is null) 210 { 211 throw new GException( new ErrorG(err) ); 212 } 213 214 return p; 215 } 216 217 /** 218 * Reads a line from the data input stream. Note that no encoding 219 * checks or conversion is performed; the input is not guaranteed to 220 * be UTF-8, and may in fact have embedded NUL characters. 221 * 222 * If @cancellable is not %NULL, then the operation can be cancelled by 223 * triggering the cancellable object from another thread. If the operation 224 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 225 * 226 * Params: 227 * length = a #gsize to get the length of the data read in. 228 * cancellable = optional #GCancellable object, %NULL to ignore. 229 * 230 * Return: a NUL terminated byte array with the line that was read in 231 * (without the newlines). Set @length to a #gsize to get the length 232 * of the read line. On an error, it will return %NULL and @error 233 * will be set. If there's no content to read, it will still return 234 * %NULL, but @error won't be set. 235 * 236 * Throws: GException on failure. 237 */ 238 public string readLine(out size_t length, Cancellable cancellable) 239 { 240 GError* err = null; 241 242 auto p = g_data_input_stream_read_line(gDataInputStream, &length, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 243 244 if (err !is null) 245 { 246 throw new GException( new ErrorG(err) ); 247 } 248 249 return Str.toString(p); 250 } 251 252 /** 253 * The asynchronous version of g_data_input_stream_read_line(). It is 254 * an error to have two outstanding calls to this function. 255 * 256 * When the operation is finished, @callback will be called. You 257 * can then call g_data_input_stream_read_line_finish() to get 258 * the result of the operation. 259 * 260 * Params: 261 * ioPriority = the [I/O priority][io-priority] of the request 262 * cancellable = optional #GCancellable object, %NULL to ignore. 263 * callback = callback to call when the request is satisfied. 264 * userData = the data to pass to callback function. 265 * 266 * Since: 2.20 267 */ 268 public void readLineAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 269 { 270 g_data_input_stream_read_line_async(gDataInputStream, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 271 } 272 273 /** 274 * Finish an asynchronous call started by 275 * g_data_input_stream_read_line_async(). Note the warning about 276 * string encoding in g_data_input_stream_read_line() applies here as 277 * well. 278 * 279 * Params: 280 * result = the #GAsyncResult that was provided to the callback. 281 * length = a #gsize to get the length of the data read in. 282 * 283 * Return: a NUL-terminated byte array with the line that was read in 284 * (without the newlines). Set @length to a #gsize to get the length 285 * of the read line. On an error, it will return %NULL and @error 286 * will be set. If there's no content to read, it will still return 287 * %NULL, but @error won't be set. 288 * 289 * Since: 2.20 290 * 291 * Throws: GException on failure. 292 */ 293 public string readLineFinish(AsyncResultIF result, out size_t length) 294 { 295 GError* err = null; 296 297 auto p = g_data_input_stream_read_line_finish(gDataInputStream, (result is null) ? null : result.getAsyncResultStruct(), &length, &err); 298 299 if (err !is null) 300 { 301 throw new GException( new ErrorG(err) ); 302 } 303 304 return Str.toString(p); 305 } 306 307 /** 308 * Finish an asynchronous call started by 309 * g_data_input_stream_read_line_async(). 310 * 311 * Params: 312 * result = the #GAsyncResult that was provided to the callback. 313 * length = a #gsize to get the length of the data read in. 314 * 315 * Return: a string with the line that 316 * was read in (without the newlines). Set @length to a #gsize to 317 * get the length of the read line. On an error, it will return 318 * %NULL and @error will be set. For UTF-8 conversion errors, the set 319 * error domain is %G_CONVERT_ERROR. If there's no content to read, 320 * it will still return %NULL, but @error won't be set. 321 * 322 * Since: 2.30 323 * 324 * Throws: GException on failure. 325 */ 326 public string readLineFinishUtf8(AsyncResultIF result, out size_t length) 327 { 328 GError* err = null; 329 330 auto p = g_data_input_stream_read_line_finish_utf8(gDataInputStream, (result is null) ? null : result.getAsyncResultStruct(), &length, &err); 331 332 if (err !is null) 333 { 334 throw new GException( new ErrorG(err) ); 335 } 336 337 return Str.toString(p); 338 } 339 340 /** 341 * Reads a UTF-8 encoded line from the data input stream. 342 * 343 * If @cancellable is not %NULL, then the operation can be cancelled by 344 * triggering the cancellable object from another thread. If the operation 345 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 346 * 347 * Params: 348 * length = a #gsize to get the length of the data read in. 349 * cancellable = optional #GCancellable object, %NULL to ignore. 350 * 351 * Return: a NUL terminated UTF-8 string 352 * with the line that was read in (without the newlines). Set 353 * @length to a #gsize to get the length of the read line. On an 354 * error, it will return %NULL and @error will be set. For UTF-8 355 * conversion errors, the set error domain is %G_CONVERT_ERROR. If 356 * there's no content to read, it will still return %NULL, but @error 357 * won't be set. 358 * 359 * Since: 2.30 360 * 361 * Throws: GException on failure. 362 */ 363 public string readLineUtf8(out size_t length, Cancellable cancellable) 364 { 365 GError* err = null; 366 367 auto p = g_data_input_stream_read_line_utf8(gDataInputStream, &length, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 368 369 if (err !is null) 370 { 371 throw new GException( new ErrorG(err) ); 372 } 373 374 return Str.toString(p); 375 } 376 377 /** 378 * Reads an unsigned 16-bit/2-byte value from @stream. 379 * 380 * In order to get the correct byte order for this read operation, 381 * see g_data_input_stream_get_byte_order() and g_data_input_stream_set_byte_order(). 382 * 383 * Params: 384 * cancellable = optional #GCancellable object, %NULL to ignore. 385 * 386 * Return: an unsigned 16-bit/2-byte value read from the @stream or %0 if 387 * an error occurred. 388 * 389 * Throws: GException on failure. 390 */ 391 public ushort readUint16(Cancellable cancellable) 392 { 393 GError* err = null; 394 395 auto p = g_data_input_stream_read_uint16(gDataInputStream, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 396 397 if (err !is null) 398 { 399 throw new GException( new ErrorG(err) ); 400 } 401 402 return p; 403 } 404 405 /** 406 * Reads an unsigned 32-bit/4-byte value from @stream. 407 * 408 * In order to get the correct byte order for this read operation, 409 * see g_data_input_stream_get_byte_order() and g_data_input_stream_set_byte_order(). 410 * 411 * If @cancellable is not %NULL, then the operation can be cancelled by 412 * triggering the cancellable object from another thread. If the operation 413 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 414 * 415 * Params: 416 * cancellable = optional #GCancellable object, %NULL to ignore. 417 * 418 * Return: an unsigned 32-bit/4-byte value read from the @stream or %0 if 419 * an error occurred. 420 * 421 * Throws: GException on failure. 422 */ 423 public uint readUint32(Cancellable cancellable) 424 { 425 GError* err = null; 426 427 auto p = g_data_input_stream_read_uint32(gDataInputStream, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 428 429 if (err !is null) 430 { 431 throw new GException( new ErrorG(err) ); 432 } 433 434 return p; 435 } 436 437 /** 438 * Reads an unsigned 64-bit/8-byte value from @stream. 439 * 440 * In order to get the correct byte order for this read operation, 441 * see g_data_input_stream_get_byte_order(). 442 * 443 * If @cancellable is not %NULL, then the operation can be cancelled by 444 * triggering the cancellable object from another thread. If the operation 445 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 446 * 447 * Params: 448 * cancellable = optional #GCancellable object, %NULL to ignore. 449 * 450 * Return: an unsigned 64-bit/8-byte read from @stream or %0 if 451 * an error occurred. 452 * 453 * Throws: GException on failure. 454 */ 455 public ulong readUint64(Cancellable cancellable) 456 { 457 GError* err = null; 458 459 auto p = g_data_input_stream_read_uint64(gDataInputStream, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 460 461 if (err !is null) 462 { 463 throw new GException( new ErrorG(err) ); 464 } 465 466 return p; 467 } 468 469 /** 470 * Reads a string from the data input stream, up to the first 471 * occurrence of any of the stop characters. 472 * 473 * Note that, in contrast to g_data_input_stream_read_until_async(), 474 * this function consumes the stop character that it finds. 475 * 476 * Don't use this function in new code. Its functionality is 477 * inconsistent with g_data_input_stream_read_until_async(). Both 478 * functions will be marked as deprecated in a future release. Use 479 * g_data_input_stream_read_upto() instead, but note that that function 480 * does not consume the stop character. 481 * 482 * Params: 483 * stopChars = characters to terminate the read. 484 * length = a #gsize to get the length of the data read in. 485 * cancellable = optional #GCancellable object, %NULL to ignore. 486 * 487 * Return: a string with the data that was read 488 * before encountering any of the stop characters. Set @length to 489 * a #gsize to get the length of the string. This function will 490 * return %NULL on an error. 491 * 492 * Throws: GException on failure. 493 */ 494 public string readUntil(string stopChars, out size_t length, Cancellable cancellable) 495 { 496 GError* err = null; 497 498 auto p = g_data_input_stream_read_until(gDataInputStream, Str.toStringz(stopChars), &length, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 499 500 if (err !is null) 501 { 502 throw new GException( new ErrorG(err) ); 503 } 504 505 return Str.toString(p); 506 } 507 508 /** 509 * The asynchronous version of g_data_input_stream_read_until(). 510 * It is an error to have two outstanding calls to this function. 511 * 512 * Note that, in contrast to g_data_input_stream_read_until(), 513 * this function does not consume the stop character that it finds. You 514 * must read it for yourself. 515 * 516 * When the operation is finished, @callback will be called. You 517 * can then call g_data_input_stream_read_until_finish() to get 518 * the result of the operation. 519 * 520 * Don't use this function in new code. Its functionality is 521 * inconsistent with g_data_input_stream_read_until(). Both functions 522 * will be marked as deprecated in a future release. Use 523 * g_data_input_stream_read_upto_async() instead. 524 * 525 * Params: 526 * stopChars = characters to terminate the read. 527 * ioPriority = the [I/O priority][io-priority] of the request 528 * cancellable = optional #GCancellable object, %NULL to ignore. 529 * callback = callback to call when the request is satisfied. 530 * userData = the data to pass to callback function. 531 * 532 * Since: 2.20 533 */ 534 public void readUntilAsync(string stopChars, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 535 { 536 g_data_input_stream_read_until_async(gDataInputStream, Str.toStringz(stopChars), ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 537 } 538 539 /** 540 * Finish an asynchronous call started by 541 * g_data_input_stream_read_until_async(). 542 * 543 * Params: 544 * result = the #GAsyncResult that was provided to the callback. 545 * length = a #gsize to get the length of the data read in. 546 * 547 * Return: a string with the data that was read 548 * before encountering any of the stop characters. Set @length to 549 * a #gsize to get the length of the string. This function will 550 * return %NULL on an error. 551 * 552 * Since: 2.20 553 * 554 * Throws: GException on failure. 555 */ 556 public string readUntilFinish(AsyncResultIF result, out size_t length) 557 { 558 GError* err = null; 559 560 auto p = g_data_input_stream_read_until_finish(gDataInputStream, (result is null) ? null : result.getAsyncResultStruct(), &length, &err); 561 562 if (err !is null) 563 { 564 throw new GException( new ErrorG(err) ); 565 } 566 567 return Str.toString(p); 568 } 569 570 /** 571 * Reads a string from the data input stream, up to the first 572 * occurrence of any of the stop characters. 573 * 574 * In contrast to g_data_input_stream_read_until(), this function 575 * does not consume the stop character. You have to use 576 * g_data_input_stream_read_byte() to get it before calling 577 * g_data_input_stream_read_upto() again. 578 * 579 * Note that @stop_chars may contain '\0' if @stop_chars_len is 580 * specified. 581 * 582 * Params: 583 * stopChars = characters to terminate the read 584 * stopCharsLen = length of @stop_chars. May be -1 if @stop_chars is 585 * nul-terminated 586 * length = a #gsize to get the length of the data read in 587 * cancellable = optional #GCancellable object, %NULL to ignore 588 * 589 * Return: a string with the data that was read 590 * before encountering any of the stop characters. Set @length to 591 * a #gsize to get the length of the string. This function will 592 * return %NULL on an error 593 * 594 * Since: 2.26 595 * 596 * Throws: GException on failure. 597 */ 598 public string readUpto(string stopChars, ptrdiff_t stopCharsLen, out size_t length, Cancellable cancellable) 599 { 600 GError* err = null; 601 602 auto p = g_data_input_stream_read_upto(gDataInputStream, Str.toStringz(stopChars), stopCharsLen, &length, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 603 604 if (err !is null) 605 { 606 throw new GException( new ErrorG(err) ); 607 } 608 609 return Str.toString(p); 610 } 611 612 /** 613 * The asynchronous version of g_data_input_stream_read_upto(). 614 * It is an error to have two outstanding calls to this function. 615 * 616 * In contrast to g_data_input_stream_read_until(), this function 617 * does not consume the stop character. You have to use 618 * g_data_input_stream_read_byte() to get it before calling 619 * g_data_input_stream_read_upto() again. 620 * 621 * Note that @stop_chars may contain '\0' if @stop_chars_len is 622 * specified. 623 * 624 * When the operation is finished, @callback will be called. You 625 * can then call g_data_input_stream_read_upto_finish() to get 626 * the result of the operation. 627 * 628 * Params: 629 * stopChars = characters to terminate the read 630 * stopCharsLen = length of @stop_chars. May be -1 if @stop_chars is 631 * nul-terminated 632 * ioPriority = the [I/O priority][io-priority] of the request 633 * cancellable = optional #GCancellable object, %NULL to ignore 634 * callback = callback to call when the request is satisfied 635 * userData = the data to pass to callback function 636 * 637 * Since: 2.26 638 */ 639 public void readUptoAsync(string stopChars, ptrdiff_t stopCharsLen, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 640 { 641 g_data_input_stream_read_upto_async(gDataInputStream, Str.toStringz(stopChars), stopCharsLen, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 642 } 643 644 /** 645 * Finish an asynchronous call started by 646 * g_data_input_stream_read_upto_async(). 647 * 648 * Note that this function does not consume the stop character. You 649 * have to use g_data_input_stream_read_byte() to get it before calling 650 * g_data_input_stream_read_upto_async() again. 651 * 652 * Params: 653 * result = the #GAsyncResult that was provided to the callback 654 * length = a #gsize to get the length of the data read in 655 * 656 * Return: a string with the data that was read 657 * before encountering any of the stop characters. Set @length to 658 * a #gsize to get the length of the string. This function will 659 * return %NULL on an error. 660 * 661 * Since: 2.24 662 * 663 * Throws: GException on failure. 664 */ 665 public string readUptoFinish(AsyncResultIF result, out size_t length) 666 { 667 GError* err = null; 668 669 auto p = g_data_input_stream_read_upto_finish(gDataInputStream, (result is null) ? null : result.getAsyncResultStruct(), &length, &err); 670 671 if (err !is null) 672 { 673 throw new GException( new ErrorG(err) ); 674 } 675 676 return Str.toString(p); 677 } 678 679 /** 680 * This function sets the byte order for the given @stream. All subsequent 681 * reads from the @stream will be read in the given @order. 682 * 683 * Params: 684 * order = a #GDataStreamByteOrder to set. 685 */ 686 public void setByteOrder(GDataStreamByteOrder order) 687 { 688 g_data_input_stream_set_byte_order(gDataInputStream, order); 689 } 690 691 /** 692 * Sets the newline type for the @stream. 693 * 694 * Note that using G_DATA_STREAM_NEWLINE_TYPE_ANY is slightly unsafe. If a read 695 * chunk ends in "CR" we must read an additional byte to know if this is "CR" or 696 * "CR LF", and this might block if there is no more data available. 697 * 698 * Params: 699 * type = the type of new line return as #GDataStreamNewlineType. 700 */ 701 public void setNewlineType(GDataStreamNewlineType type) 702 { 703 g_data_input_stream_set_newline_type(gDataInputStream, type); 704 } 705 }