2 * Copyright 2015-present Open Networking Foundation
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package io.atomix.storage.buffer;
18 import java.nio.ByteOrder;
23 * @author <a href="http://github.com/kuujo">Jordan Halterman</a>
25 public class WrappedBytes extends AbstractBytes {
26 protected final Bytes bytes;
27 private final Bytes root;
29 public WrappedBytes(Bytes bytes) {
31 throw new NullPointerException("bytes cannot be null");
34 this.root = bytes instanceof WrappedBytes ? ((WrappedBytes) bytes).root : bytes;
38 * Returns the root bytes.
50 public Bytes resize(int newSize) {
51 return bytes.resize(newSize);
55 public ByteOrder order() {
66 public Bytes zero(int offset) {
72 public Bytes zero(int offset, int length) {
73 bytes.zero(offset, length);
78 public Bytes read(int offset, Bytes dst, int dstOffset, int length) {
79 bytes.read(offset, dst, dstOffset, length);
84 public Bytes read(int offset, byte[] dst, int dstOffset, int length) {
85 bytes.read(offset, dst, dstOffset, length);
90 public int readByte(int offset) {
91 return bytes.readByte(offset);
95 public int readUnsignedByte(int offset) {
96 return bytes.readUnsignedByte(offset);
100 public char readChar(int offset) {
101 return bytes.readChar(offset);
105 public short readShort(int offset) {
106 return bytes.readShort(offset);
110 public int readUnsignedShort(int offset) {
111 return bytes.readUnsignedShort(offset);
115 public int readMedium(int offset) {
116 return bytes.readMedium(offset);
120 public int readUnsignedMedium(int offset) {
121 return bytes.readUnsignedMedium(offset);
125 public int readInt(int offset) {
126 return bytes.readInt(offset);
130 public long readUnsignedInt(int offset) {
131 return bytes.readUnsignedInt(offset);
135 public long readLong(int offset) {
136 return bytes.readLong(offset);
140 public float readFloat(int offset) {
141 return bytes.readFloat(offset);
145 public double readDouble(int offset) {
146 return bytes.readDouble(offset);
150 public boolean readBoolean(int offset) {
151 return bytes.readBoolean(offset);
155 public String readString(int offset) {
156 return bytes.readString(offset);
160 public String readUTF8(int offset) {
161 return bytes.readUTF8(offset);
165 public Bytes write(int offset, Bytes src, int srcOffset, int length) {
166 bytes.write(offset, src, srcOffset, length);
171 public Bytes write(int offset, byte[] src, int srcOffset, int length) {
172 bytes.write(offset, src, srcOffset, length);
177 public Bytes writeByte(int offset, int b) {
178 bytes.writeByte(offset, b);
183 public Bytes writeUnsignedByte(int offset, int b) {
184 bytes.writeUnsignedByte(offset, b);
189 public Bytes writeChar(int offset, char c) {
190 bytes.writeChar(offset, c);
195 public Bytes writeShort(int offset, short s) {
196 bytes.writeShort(offset, s);
201 public Bytes writeUnsignedShort(int offset, int s) {
202 bytes.writeUnsignedShort(offset, s);
207 public Bytes writeMedium(int offset, int m) {
208 bytes.writeMedium(offset, m);
213 public Bytes writeUnsignedMedium(int offset, int m) {
214 bytes.writeUnsignedMedium(offset, m);
219 public Bytes writeInt(int offset, int i) {
220 bytes.writeInt(offset, i);
225 public Bytes writeUnsignedInt(int offset, long i) {
226 bytes.writeUnsignedInt(offset, i);
231 public Bytes writeLong(int offset, long l) {
232 bytes.writeLong(offset, l);
237 public Bytes writeFloat(int offset, float f) {
238 bytes.writeFloat(offset, f);
243 public Bytes writeDouble(int offset, double d) {
244 bytes.writeDouble(offset, d);
249 public Bytes writeBoolean(int offset, boolean b) {
250 bytes.writeBoolean(offset, b);
255 public Bytes writeString(int offset, String s) {
256 bytes.writeString(offset, s);
261 public Bytes writeUTF8(int offset, String s) {
262 bytes.writeUTF8(offset, s);
267 public Bytes flush() {
273 public void close() {