net.kuujo.alleycat.io.SwappedBuffer Maven / Gradle / Ivy
/*
* Copyright 2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.kuujo.alleycat.io;
import net.kuujo.alleycat.util.ReferenceManager;
import java.nio.ByteOrder;
/**
* Byte order swapped buffer.
*
* @author Jordan Halterman
*/
public class SwappedBuffer extends AbstractBuffer {
private final Buffer root;
SwappedBuffer(Buffer root, Bytes bytes, ReferenceManager referenceManager) {
super(bytes, referenceManager);
this.root = root;
}
public SwappedBuffer(Buffer buffer, long offset, long initialCapacity, long maxCapacity, ReferenceManager referenceManager) {
super(buffer.bytes().order(buffer.order() == ByteOrder.BIG_ENDIAN ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN), offset, initialCapacity, maxCapacity, referenceManager);
this.root = buffer instanceof SwappedBuffer ? ((SwappedBuffer) buffer).root : buffer;
root.acquire();
}
/**
* Returns the root buffer.
*
* @return The root buffer.
*/
public Buffer root() {
return root;
}
@Override
public boolean isDirect() {
return root.isDirect();
}
@Override
public boolean isFile() {
return root.isFile();
}
@Override
public boolean isReadOnly() {
return root.isReadOnly();
}
@Override
public Buffer compact() {
root.compact();
return this;
}
@Override
protected void compact(long from, long to, long length) {
if (root instanceof AbstractBuffer) {
((AbstractBuffer) root).compact(from, to, length);
}
}
@Override
public Buffer acquire() {
root.acquire();
return this;
}
@Override
public void release() {
root.release();
}
@Override
public void close() {
root.release();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy