source: appstream-generator/build/girepo/gio/DataInputStream.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

File size: 22.5 KB
Line 
1/*
2 * Licensed under the GNU Lesser General Public License Version 3
3 *
4 * This library is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the license, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18// generated automatically - do not change
19
20
21module gio.DataInputStream;
22
23private import gi.gio;
24public  import gi.giotypes;
25private import gio.AsyncResultIF;
26private import gio.BufferedInputStream;
27private import gio.Cancellable;
28private import gio.InputStream;
29private import glib.ConstructionException;
30private import glib.ErrorG;
31private import glib.GException;
32private import glib.Str;
33private import gobject.ObjectG;
34
35
36/**
37 * Data input stream implements #GInputStream and includes functions for
38 * reading structured data directly from a binary input stream.
39 */
40public class DataInputStream : BufferedInputStream
41{
42        /** the main Gtk struct */
43        protected GDataInputStream* gDataInputStream;
44
45        /** Get the main Gtk struct */
46        public GDataInputStream* getDataInputStreamStruct()
47        {
48                return gDataInputStream;
49        }
50
51        /** the main Gtk struct as a void* */
52        protected override void* getStruct()
53        {
54                return cast(void*)gDataInputStream;
55        }
56
57        protected override void setStruct(GObject* obj)
58        {
59                gDataInputStream = cast(GDataInputStream*)obj;
60                super.setStruct(obj);
61        }
62
63        /**
64         * Sets our main struct and passes it to the parent class.
65         */
66        public this (GDataInputStream* gDataInputStream, bool ownedRef = false)
67        {
68                this.gDataInputStream = gDataInputStream;
69                super(cast(GBufferedInputStream*)gDataInputStream, ownedRef);
70        }
71
72
73        /** */
74        public static GType getType()
75        {
76                return g_data_input_stream_get_type();
77        }
78
79        /**
80         * Creates a new data input stream for the @base_stream.
81         *
82         * Params:
83         *     baseStream = a #GInputStream.
84         *
85         * Returns: a new #GDataInputStream.
86         *
87         * Throws: ConstructionException GTK+ fails to create the object.
88         */
89        public this(InputStream baseStream)
90        {
91                auto p = g_data_input_stream_new((baseStream is null) ? null : baseStream.getInputStreamStruct());
92               
93                if(p is null)
94                {
95                        throw new ConstructionException("null returned by new");
96                }
97               
98                this(cast(GDataInputStream*) p, true);
99        }
100
101        /**
102         * Gets the byte order for the data input stream.
103         *
104         * Returns: the @stream's current #GDataStreamByteOrder.
105         */
106        public GDataStreamByteOrder getByteOrder()
107        {
108                return g_data_input_stream_get_byte_order(gDataInputStream);
109        }
110
111        /**
112         * Gets the current newline type for the @stream.
113         *
114         * Returns: #GDataStreamNewlineType for the given @stream.
115         */
116        public GDataStreamNewlineType getNewlineType()
117        {
118                return g_data_input_stream_get_newline_type(gDataInputStream);
119        }
120
121        /**
122         * Reads a 16-bit/2-byte value from @stream.
123         *
124         * In order to get the correct byte order for this read operation,
125         * see g_data_input_stream_get_byte_order() and g_data_input_stream_set_byte_order().
126         *
127         * Params:
128         *     cancellable = optional #GCancellable object, %NULL to ignore.
129         *
130         * Returns: a signed 16-bit/2-byte value read from @stream or %0 if
131         *     an error occurred.
132         *
133         * Throws: GException on failure.
134         */
135        public short readInt16(Cancellable cancellable)
136        {
137                GError* err = null;
138               
139                auto p = g_data_input_stream_read_int16(gDataInputStream, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
140               
141                if (err !is null)
142                {
143                        throw new GException( new ErrorG(err) );
144                }
145               
146                return p;
147        }
148
149        /**
150         * Reads a signed 32-bit/4-byte value from @stream.
151         *
152         * In order to get the correct byte order for this read operation,
153         * see g_data_input_stream_get_byte_order() and g_data_input_stream_set_byte_order().
154         *
155         * If @cancellable is not %NULL, then the operation can be cancelled by
156         * triggering the cancellable object from another thread. If the operation
157         * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
158         *
159         * Params:
160         *     cancellable = optional #GCancellable object, %NULL to ignore.
161         *
162         * Returns: a signed 32-bit/4-byte value read from the @stream or %0 if
163         *     an error occurred.
164         *
165         * Throws: GException on failure.
166         */
167        public int readInt32(Cancellable cancellable)
168        {
169                GError* err = null;
170               
171                auto p = g_data_input_stream_read_int32(gDataInputStream, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
172               
173                if (err !is null)
174                {
175                        throw new GException( new ErrorG(err) );
176                }
177               
178                return p;
179        }
180
181        /**
182         * Reads a 64-bit/8-byte value from @stream.
183         *
184         * In order to get the correct byte order for this read operation,
185         * see g_data_input_stream_get_byte_order() and g_data_input_stream_set_byte_order().
186         *
187         * If @cancellable is not %NULL, then the operation can be cancelled by
188         * triggering the cancellable object from another thread. If the operation
189         * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
190         *
191         * Params:
192         *     cancellable = optional #GCancellable object, %NULL to ignore.
193         *
194         * Returns: a signed 64-bit/8-byte value read from @stream or %0 if
195         *     an error occurred.
196         *
197         * Throws: GException on failure.
198         */
199        public long readInt64(Cancellable cancellable)
200        {
201                GError* err = null;
202               
203                auto p = g_data_input_stream_read_int64(gDataInputStream, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
204               
205                if (err !is null)
206                {
207                        throw new GException( new ErrorG(err) );
208                }
209               
210                return p;
211        }
212
213        /**
214         * Reads a line from the data input stream.  Note that no encoding
215         * checks or conversion is performed; the input is not guaranteed to
216         * be UTF-8, and may in fact have embedded NUL characters.
217         *
218         * If @cancellable is not %NULL, then the operation can be cancelled by
219         * triggering the cancellable object from another thread. If the operation
220         * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
221         *
222         * Params:
223         *     length = a #gsize to get the length of the data read in.
224         *     cancellable = optional #GCancellable object, %NULL to ignore.
225         *
226         * Returns: a NUL terminated byte array with the line that was read in
227         *     (without the newlines).  Set @length to a #gsize to get the length
228         *     of the read line.  On an error, it will return %NULL and @error
229         *     will be set. If there's no content to read, it will still return
230         *     %NULL, but @error won't be set.
231         *
232         * Throws: GException on failure.
233         */
234        public string readLine(out size_t length, Cancellable cancellable)
235        {
236                GError* err = null;
237               
238                auto retStr = g_data_input_stream_read_line(gDataInputStream, &length, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
239               
240                if (err !is null)
241                {
242                        throw new GException( new ErrorG(err) );
243                }
244               
245                scope(exit) Str.freeString(retStr);
246                return Str.toString(retStr);
247        }
248
249        /**
250         * The asynchronous version of g_data_input_stream_read_line().  It is
251         * an error to have two outstanding calls to this function.
252         *
253         * When the operation is finished, @callback will be called. You
254         * can then call g_data_input_stream_read_line_finish() to get
255         * the result of the operation.
256         *
257         * Params:
258         *     ioPriority = the [I/O priority][io-priority] of the request
259         *     cancellable = optional #GCancellable object, %NULL to ignore.
260         *     callback = callback to call when the request is satisfied.
261         *     userData = the data to pass to callback function.
262         *
263         * Since: 2.20
264         */
265        public void readLineAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
266        {
267                g_data_input_stream_read_line_async(gDataInputStream, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
268        }
269
270        /**
271         * Finish an asynchronous call started by
272         * g_data_input_stream_read_line_async().  Note the warning about
273         * string encoding in g_data_input_stream_read_line() applies here as
274         * well.
275         *
276         * Params:
277         *     result = the #GAsyncResult that was provided to the callback.
278         *     length = a #gsize to get the length of the data read in.
279         *
280         * Returns: a NUL-terminated byte array with the line that was read in
281         *     (without the newlines).  Set @length to a #gsize to get the length
282         *     of the read line.  On an error, it will return %NULL and @error
283         *     will be set. If there's no content to read, it will still return
284         *     %NULL, but @error won't be set.
285         *
286         * Since: 2.20
287         *
288         * Throws: GException on failure.
289         */
290        public string readLineFinish(AsyncResultIF result, out size_t length)
291        {
292                GError* err = null;
293               
294                auto retStr = g_data_input_stream_read_line_finish(gDataInputStream, (result is null) ? null : result.getAsyncResultStruct(), &length, &err);
295               
296                if (err !is null)
297                {
298                        throw new GException( new ErrorG(err) );
299                }
300               
301                scope(exit) Str.freeString(retStr);
302                return Str.toString(retStr);
303        }
304
305        /**
306         * Finish an asynchronous call started by
307         * g_data_input_stream_read_line_async().
308         *
309         * Params:
310         *     result = the #GAsyncResult that was provided to the callback.
311         *     length = a #gsize to get the length of the data read in.
312         *
313         * Returns: a string with the line that
314         *     was read in (without the newlines).  Set @length to a #gsize to
315         *     get the length of the read line.  On an error, it will return
316         *     %NULL and @error will be set. For UTF-8 conversion errors, the set
317         *     error domain is %G_CONVERT_ERROR.  If there's no content to read,
318         *     it will still return %NULL, but @error won't be set.
319         *
320         * Since: 2.30
321         *
322         * Throws: GException on failure.
323         */
324        public string readLineFinishUtf8(AsyncResultIF result, out size_t length)
325        {
326                GError* err = null;
327               
328                auto retStr = g_data_input_stream_read_line_finish_utf8(gDataInputStream, (result is null) ? null : result.getAsyncResultStruct(), &length, &err);
329               
330                if (err !is null)
331                {
332                        throw new GException( new ErrorG(err) );
333                }
334               
335                scope(exit) Str.freeString(retStr);
336                return Str.toString(retStr);
337        }
338
339        /**
340         * Reads a UTF-8 encoded line from the data input stream.
341         *
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         *
346         * Params:
347         *     length = a #gsize to get the length of the data read in.
348         *     cancellable = optional #GCancellable object, %NULL to ignore.
349         *
350         * Returns: a NUL terminated UTF-8 string
351         *     with the line that was read in (without the newlines).  Set
352         *     @length to a #gsize to get the length of the read line.  On an
353         *     error, it will return %NULL and @error will be set.  For UTF-8
354         *     conversion errors, the set error domain is %G_CONVERT_ERROR.  If
355         *     there's no content to read, it will still return %NULL, but @error
356         *     won't be set.
357         *
358         * Since: 2.30
359         *
360         * Throws: GException on failure.
361         */
362        public string readLineUtf8(out size_t length, Cancellable cancellable)
363        {
364                GError* err = null;
365               
366                auto retStr = g_data_input_stream_read_line_utf8(gDataInputStream, &length, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
367               
368                if (err !is null)
369                {
370                        throw new GException( new ErrorG(err) );
371                }
372               
373                scope(exit) Str.freeString(retStr);
374                return Str.toString(retStr);
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         * Returns: 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         * Returns: 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         * Returns: 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         * Returns: 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 retStr = 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                scope(exit) Str.freeString(retStr);
506                return Str.toString(retStr);
507        }
508
509        /**
510         * The asynchronous version of g_data_input_stream_read_until().
511         * It is an error to have two outstanding calls to this function.
512         *
513         * Note that, in contrast to g_data_input_stream_read_until(),
514         * this function does not consume the stop character that it finds.  You
515         * must read it for yourself.
516         *
517         * When the operation is finished, @callback will be called. You
518         * can then call g_data_input_stream_read_until_finish() to get
519         * the result of the operation.
520         *
521         * Don't use this function in new code.  Its functionality is
522         * inconsistent with g_data_input_stream_read_until().  Both functions
523         * will be marked as deprecated in a future release.  Use
524         * g_data_input_stream_read_upto_async() instead.
525         *
526         * Params:
527         *     stopChars = characters to terminate the read.
528         *     ioPriority = the [I/O priority][io-priority] of the request
529         *     cancellable = optional #GCancellable object, %NULL to ignore.
530         *     callback = callback to call when the request is satisfied.
531         *     userData = the data to pass to callback function.
532         *
533         * Since: 2.20
534         */
535        public void readUntilAsync(string stopChars, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
536        {
537                g_data_input_stream_read_until_async(gDataInputStream, Str.toStringz(stopChars), ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
538        }
539
540        /**
541         * Finish an asynchronous call started by
542         * g_data_input_stream_read_until_async().
543         *
544         * Params:
545         *     result = the #GAsyncResult that was provided to the callback.
546         *     length = a #gsize to get the length of the data read in.
547         *
548         * Returns: a string with the data that was read
549         *     before encountering any of the stop characters. Set @length to
550         *     a #gsize to get the length of the string. This function will
551         *     return %NULL on an error.
552         *
553         * Since: 2.20
554         *
555         * Throws: GException on failure.
556         */
557        public string readUntilFinish(AsyncResultIF result, out size_t length)
558        {
559                GError* err = null;
560               
561                auto retStr = g_data_input_stream_read_until_finish(gDataInputStream, (result is null) ? null : result.getAsyncResultStruct(), &length, &err);
562               
563                if (err !is null)
564                {
565                        throw new GException( new ErrorG(err) );
566                }
567               
568                scope(exit) Str.freeString(retStr);
569                return Str.toString(retStr);
570        }
571
572        /**
573         * Reads a string from the data input stream, up to the first
574         * occurrence of any of the stop characters.
575         *
576         * In contrast to g_data_input_stream_read_until(), this function
577         * does not consume the stop character. You have to use
578         * g_data_input_stream_read_byte() to get it before calling
579         * g_data_input_stream_read_upto() again.
580         *
581         * Note that @stop_chars may contain '\0' if @stop_chars_len is
582         * specified.
583         *
584         * Params:
585         *     stopChars = characters to terminate the read
586         *     stopCharsLen = length of @stop_chars. May be -1 if @stop_chars is
587         *         nul-terminated
588         *     length = a #gsize to get the length of the data read in
589         *     cancellable = optional #GCancellable object, %NULL to ignore
590         *
591         * Returns: a string with the data that was read
592         *     before encountering any of the stop characters. Set @length to
593         *     a #gsize to get the length of the string. This function will
594         *     return %NULL on an error
595         *
596         * Since: 2.26
597         *
598         * Throws: GException on failure.
599         */
600        public string readUpto(string stopChars, ptrdiff_t stopCharsLen, out size_t length, Cancellable cancellable)
601        {
602                GError* err = null;
603               
604                auto retStr = g_data_input_stream_read_upto(gDataInputStream, Str.toStringz(stopChars), stopCharsLen, &length, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
605               
606                if (err !is null)
607                {
608                        throw new GException( new ErrorG(err) );
609                }
610               
611                scope(exit) Str.freeString(retStr);
612                return Str.toString(retStr);
613        }
614
615        /**
616         * The asynchronous version of g_data_input_stream_read_upto().
617         * It is an error to have two outstanding calls to this function.
618         *
619         * In contrast to g_data_input_stream_read_until(), this function
620         * does not consume the stop character. You have to use
621         * g_data_input_stream_read_byte() to get it before calling
622         * g_data_input_stream_read_upto() again.
623         *
624         * Note that @stop_chars may contain '\0' if @stop_chars_len is
625         * specified.
626         *
627         * When the operation is finished, @callback will be called. You
628         * can then call g_data_input_stream_read_upto_finish() to get
629         * the result of the operation.
630         *
631         * Params:
632         *     stopChars = characters to terminate the read
633         *     stopCharsLen = length of @stop_chars. May be -1 if @stop_chars is
634         *         nul-terminated
635         *     ioPriority = the [I/O priority][io-priority] of the request
636         *     cancellable = optional #GCancellable object, %NULL to ignore
637         *     callback = callback to call when the request is satisfied
638         *     userData = the data to pass to callback function
639         *
640         * Since: 2.26
641         */
642        public void readUptoAsync(string stopChars, ptrdiff_t stopCharsLen, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
643        {
644                g_data_input_stream_read_upto_async(gDataInputStream, Str.toStringz(stopChars), stopCharsLen, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
645        }
646
647        /**
648         * Finish an asynchronous call started by
649         * g_data_input_stream_read_upto_async().
650         *
651         * Note that this function does not consume the stop character. You
652         * have to use g_data_input_stream_read_byte() to get it before calling
653         * g_data_input_stream_read_upto_async() again.
654         *
655         * Params:
656         *     result = the #GAsyncResult that was provided to the callback
657         *     length = a #gsize to get the length of the data read in
658         *
659         * Returns: a string with the data that was read
660         *     before encountering any of the stop characters. Set @length to
661         *     a #gsize to get the length of the string. This function will
662         *     return %NULL on an error.
663         *
664         * Since: 2.24
665         *
666         * Throws: GException on failure.
667         */
668        public string readUptoFinish(AsyncResultIF result, out size_t length)
669        {
670                GError* err = null;
671               
672                auto retStr = g_data_input_stream_read_upto_finish(gDataInputStream, (result is null) ? null : result.getAsyncResultStruct(), &length, &err);
673               
674                if (err !is null)
675                {
676                        throw new GException( new ErrorG(err) );
677                }
678               
679                scope(exit) Str.freeString(retStr);
680                return Str.toString(retStr);
681        }
682
683        /**
684         * This function sets the byte order for the given @stream. All subsequent
685         * reads from the @stream will be read in the given @order.
686         *
687         * Params:
688         *     order = a #GDataStreamByteOrder to set.
689         */
690        public void setByteOrder(GDataStreamByteOrder order)
691        {
692                g_data_input_stream_set_byte_order(gDataInputStream, order);
693        }
694
695        /**
696         * Sets the newline type for the @stream.
697         *
698         * Note that using G_DATA_STREAM_NEWLINE_TYPE_ANY is slightly unsafe. If a read
699         * chunk ends in "CR" we must read an additional byte to know if this is "CR" or
700         * "CR LF", and this might block if there is no more data available.
701         *
702         * Params:
703         *     type = the type of new line return as #GDataStreamNewlineType.
704         */
705        public void setNewlineType(GDataStreamNewlineType type)
706        {
707                g_data_input_stream_set_newline_type(gDataInputStream, type);
708        }
709}
Note: See TracBrowser for help on using the repository browser.