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