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.BufferedOutputStream;
26 
27 private import gio.FilterOutputStream;
28 private import gio.OutputStream;
29 private import gio.SeekableIF;
30 private import gio.SeekableT;
31 private import gio.c.functions;
32 public  import gio.c.types;
33 private import glib.ConstructionException;
34 private import gobject.ObjectG;
35 public  import gtkc.giotypes;
36 
37 
38 /**
39  * Buffered output stream implements #GFilterOutputStream and provides
40  * for buffered writes.
41  * 
42  * By default, #GBufferedOutputStream's buffer size is set at 4 kilobytes.
43  * 
44  * To create a buffered output stream, use g_buffered_output_stream_new(),
45  * or g_buffered_output_stream_new_sized() to specify the buffer's size
46  * at construction.
47  * 
48  * To get the size of a buffer within a buffered input stream, use
49  * g_buffered_output_stream_get_buffer_size(). To change the size of a
50  * buffered output stream's buffer, use
51  * g_buffered_output_stream_set_buffer_size(). Note that the buffer's
52  * size cannot be reduced below the size of the data within the buffer.
53  */
54 public class BufferedOutputStream : FilterOutputStream, SeekableIF
55 {
56 	/** the main Gtk struct */
57 	protected GBufferedOutputStream* gBufferedOutputStream;
58 
59 	/** Get the main Gtk struct */
60 	public GBufferedOutputStream* getBufferedOutputStreamStruct(bool transferOwnership = false)
61 	{
62 		if (transferOwnership)
63 			ownedRef = false;
64 		return gBufferedOutputStream;
65 	}
66 
67 	/** the main Gtk struct as a void* */
68 	protected override void* getStruct()
69 	{
70 		return cast(void*)gBufferedOutputStream;
71 	}
72 
73 	protected override void setStruct(GObject* obj)
74 	{
75 		gBufferedOutputStream = cast(GBufferedOutputStream*)obj;
76 		super.setStruct(obj);
77 	}
78 
79 	/**
80 	 * Sets our main struct and passes it to the parent class.
81 	 */
82 	public this (GBufferedOutputStream* gBufferedOutputStream, bool ownedRef = false)
83 	{
84 		this.gBufferedOutputStream = gBufferedOutputStream;
85 		super(cast(GFilterOutputStream*)gBufferedOutputStream, ownedRef);
86 	}
87 
88 	// add the Seekable capabilities
89 	mixin SeekableT!(GBufferedOutputStream);
90 
91 
92 	/** */
93 	public static GType getType()
94 	{
95 		return g_buffered_output_stream_get_type();
96 	}
97 
98 	/**
99 	 * Creates a new buffered output stream for a base stream.
100 	 *
101 	 * Params:
102 	 *     baseStream = a #GOutputStream.
103 	 *
104 	 * Returns: a #GOutputStream for the given @base_stream.
105 	 *
106 	 * Throws: ConstructionException GTK+ fails to create the object.
107 	 */
108 	public this(OutputStream baseStream)
109 	{
110 		auto p = g_buffered_output_stream_new((baseStream is null) ? null : baseStream.getOutputStreamStruct());
111 
112 		if(p is null)
113 		{
114 			throw new ConstructionException("null returned by new");
115 		}
116 
117 		this(cast(GBufferedOutputStream*) p, true);
118 	}
119 
120 	/**
121 	 * Creates a new buffered output stream with a given buffer size.
122 	 *
123 	 * Params:
124 	 *     baseStream = a #GOutputStream.
125 	 *     size = a #gsize.
126 	 *
127 	 * Returns: a #GOutputStream with an internal buffer set to @size.
128 	 *
129 	 * Throws: ConstructionException GTK+ fails to create the object.
130 	 */
131 	public this(OutputStream baseStream, size_t size)
132 	{
133 		auto p = g_buffered_output_stream_new_sized((baseStream is null) ? null : baseStream.getOutputStreamStruct(), size);
134 
135 		if(p is null)
136 		{
137 			throw new ConstructionException("null returned by new_sized");
138 		}
139 
140 		this(cast(GBufferedOutputStream*) p, true);
141 	}
142 
143 	/**
144 	 * Checks if the buffer automatically grows as data is added.
145 	 *
146 	 * Returns: %TRUE if the @stream's buffer automatically grows,
147 	 *     %FALSE otherwise.
148 	 */
149 	public bool getAutoGrow()
150 	{
151 		return g_buffered_output_stream_get_auto_grow(gBufferedOutputStream) != 0;
152 	}
153 
154 	/**
155 	 * Gets the size of the buffer in the @stream.
156 	 *
157 	 * Returns: the current size of the buffer.
158 	 */
159 	public size_t getBufferSize()
160 	{
161 		return g_buffered_output_stream_get_buffer_size(gBufferedOutputStream);
162 	}
163 
164 	/**
165 	 * Sets whether or not the @stream's buffer should automatically grow.
166 	 * If @auto_grow is true, then each write will just make the buffer
167 	 * larger, and you must manually flush the buffer to actually write out
168 	 * the data to the underlying stream.
169 	 *
170 	 * Params:
171 	 *     autoGrow = a #gboolean.
172 	 */
173 	public void setAutoGrow(bool autoGrow)
174 	{
175 		g_buffered_output_stream_set_auto_grow(gBufferedOutputStream, autoGrow);
176 	}
177 
178 	/**
179 	 * Sets the size of the internal buffer to @size.
180 	 *
181 	 * Params:
182 	 *     size = a #gsize.
183 	 */
184 	public void setBufferSize(size_t size)
185 	{
186 		g_buffered_output_stream_set_buffer_size(gBufferedOutputStream, size);
187 	}
188 }