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;
21 * The sliced buffer provides a view of a subset of an underlying buffer. This buffer operates directly on the {@link Bytes}
22 * underlying the child {@link Buffer} instance.
24 * @author <a href="http://github.com/kuujo">Jordan Halterman</a>
26 public class SlicedBuffer extends AbstractBuffer {
27 private final Buffer root;
29 public SlicedBuffer(Buffer root, Bytes bytes, int offset, int initialCapacity, int maxCapacity) {
30 super(bytes, offset, initialCapacity, maxCapacity, null);
36 * Returns the root buffer.
38 * @return The root buffer.
40 public Buffer root() {
45 public boolean isDirect() {
46 return root.isDirect();
50 protected void compact(int from, int to, int length) {
51 if (root instanceof AbstractBuffer) {
52 ((AbstractBuffer) root).compact(from, to, length);
57 public boolean isFile() {
62 public boolean isReadOnly() {
63 return root.isReadOnly();
67 public Buffer compact() {
72 public Buffer duplicate() {
73 return new SlicedBuffer(root, bytes, offset(), capacity(), maxCapacity());
77 public Buffer acquire() {
83 public boolean release() {
84 return root.release();