Remove atomix.storage.statistics
[controller.git] / third-party / atomix / storage / src / main / java / io / atomix / storage / buffer / BytesOutput.java
1 /*
2  * Copyright 2015-present Open Networking Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package io.atomix.storage.buffer;
17
18 import java.nio.charset.Charset;
19
20 /**
21  * Writable bytes.
22  * <p>
23  * This interface exposes methods for writing bytes to specific positions in a byte array.
24  *
25  * @author <a href="http://github.com/kuujo">Jordan Halterman</a>
26  */
27 public interface BytesOutput<T extends BytesOutput<T>> {
28
29   /**
30    * Zeros out all bytes in the array.
31    *
32    * @return The written bytes.
33    */
34   T zero();
35
36   /**
37    * Zeros out all bytes starting at the given offset in the array.
38    *
39    * @param offset The offset at which to start zeroing out bytes.
40    * @return The written bytes.
41    */
42   T zero(int offset);
43
44   /**
45    * Zeros out bytes starting at the given offset up to the given length.
46    *
47    * @param offset The offset at which to start zeroing out bytes.
48    * @param length THe total number of bytes to zero out.
49    * @return The written bytes.
50    */
51   T zero(int offset, int length);
52
53   /**
54    * Writes an array of bytes to the buffer.
55    *
56    * @param offset    The offset at which to start writing the bytes.
57    * @param src       The array of bytes to write.
58    * @param srcOffset The offset at which to start reading bytes from the given source.
59    * @param length    The number of bytes from the provided byte array to write to the buffer.
60    * @return The written buffer.
61    */
62   T write(int offset, Bytes src, int srcOffset, int length);
63
64   /**
65    * Writes an array of bytes to the buffer.
66    *
67    * @param offset    The offset at which to start writing the bytes.
68    * @param src       The array of bytes to write.
69    * @param srcOffset The offset at which to start reading bytes from the given source.
70    * @param length    The number of bytes from the provided byte array to write to the buffer.
71    * @return The written buffer.
72    */
73   T write(int offset, byte[] src, int srcOffset, int length);
74
75   /**
76    * Writes a byte to the buffer at the given offset.
77    *
78    * @param offset The offset at which to write the byte.
79    * @param b      The byte to write.
80    * @return The written buffer.
81    */
82   T writeByte(int offset, int b);
83
84   /**
85    * Writes an unsigned byte to the buffer at the given position.
86    *
87    * @param offset The offset at which to write the byte.
88    * @param b      The byte to write.
89    * @return The written buffer.
90    */
91   T writeUnsignedByte(int offset, int b);
92
93   /**
94    * Writes a 16-bit character to the buffer at the given offset.
95    *
96    * @param offset The offset at which to write the character.
97    * @param c      The character to write.
98    * @return The written buffer.
99    */
100   T writeChar(int offset, char c);
101
102   /**
103    * Writes a 16-bit signed integer to the buffer at the given offset.
104    *
105    * @param offset The offset at which to write the short.
106    * @param s      The short to write.
107    * @return The written buffer.
108    */
109   T writeShort(int offset, short s);
110
111   /**
112    * Writes a 16-bit unsigned integer to the buffer at the given offset.
113    *
114    * @param offset The offset at which to write the short.
115    * @param s      The short to write.
116    * @return The written buffer.
117    */
118   T writeUnsignedShort(int offset, int s);
119
120   /**
121    * Writes a 24-bit signed integer to the buffer at the given offset.
122    *
123    * @param offset The offset at which to write the short.
124    * @param m      The short to write.
125    * @return The written buffer.
126    */
127   T writeMedium(int offset, int m);
128
129   /**
130    * Writes a 24-bit unsigned integer to the buffer at the given offset.
131    *
132    * @param offset The offset at which to write the short.
133    * @param m      The short to write.
134    * @return The written buffer.
135    */
136   T writeUnsignedMedium(int offset, int m);
137
138   /**
139    * Writes a 32-bit signed integer to the buffer at the given offset.
140    *
141    * @param offset The offset at which to write the integer.
142    * @param i      The integer to write.
143    * @return The written buffer.
144    */
145   T writeInt(int offset, int i);
146
147   /**
148    * Writes a 32-bit unsigned integer to the buffer at the given offset.
149    *
150    * @param offset The offset at which to write the integer.
151    * @param i      The integer to write.
152    * @return The written buffer.
153    */
154   T writeUnsignedInt(int offset, long i);
155
156   /**
157    * Writes a 64-bit signed integer to the buffer at the given offset.
158    *
159    * @param offset The offset at which to write the long.
160    * @param l      The long to write.
161    * @return The written buffer.
162    */
163   T writeLong(int offset, long l);
164
165   /**
166    * Writes a single-precision 32-bit floating point number to the buffer at the given offset.
167    *
168    * @param offset The offset at which to write the float.
169    * @param f      The float to write.
170    * @return The written buffer.
171    */
172   T writeFloat(int offset, float f);
173
174   /**
175    * Writes a double-precision 64-bit floating point number to the buffer at the given offset.
176    *
177    * @param offset The offset at which to write the double.
178    * @param d      The double to write.
179    * @return The written buffer.
180    */
181   T writeDouble(int offset, double d);
182
183   /**
184    * Writes a 1 byte boolean to the buffer at the given offset.
185    *
186    * @param offset The offset at which to write the boolean.
187    * @param b      The boolean to write.
188    * @return The written buffer.
189    */
190   T writeBoolean(int offset, boolean b);
191
192   /**
193    * Writes a string to the buffer at the given offset.
194    *
195    * @param offset The offset at which to write the string.
196    * @param s      The string to write.
197    * @return The written buffer.
198    */
199   T writeString(int offset, String s);
200
201   /**
202    * Writes a string to the buffer at the given offset.
203    *
204    * @param offset  The offset at which to write the string.
205    * @param s       The string to write.
206    * @param charset The character set with which to encode the string.
207    * @return The written buffer.
208    */
209   T writeString(int offset, String s, Charset charset);
210
211   /**
212    * Writes a UTF-8 string to the buffer at the given offset.
213    *
214    * @param offset The offset at which to write the string.
215    * @param s      The string to write.
216    * @return The written buffer.
217    */
218   T writeUTF8(int offset, String s);
219
220   /**
221    * Flushes the bytes to the underlying persistence layer.
222    *
223    * @return The flushed buffer.
224    */
225   T flush();
226
227 }