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