/* * Copyright 2021 The Netty Project * * The Netty Project licenses this file to you 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: * * https://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 io.net5.buffer.api; import java.nio.ByteBuffer; /** * A stub of a {@link Buffer} implementation that implements all buffer methods by delegating them to a wrapped buffer * instance. *
* This can be used when writing automated tests for code that integrates with {@link Buffer}, but should not be used in
* production code.
*/
public class BufferStub implements Buffer {
protected final Buffer delegate;
/**
* Create a new buffer stub that delegates all calls to the given instance.
*
* @param delegate The buffer instance to delegate all method calls to.
*/
public BufferStub(Buffer delegate) {
this.delegate = delegate;
}
@Override
public int capacity() {
return delegate.capacity();
}
@Override
public int readerOffset() {
return delegate.readerOffset();
}
@Override
public Buffer readerOffset(int offset) {
return delegate.readerOffset(offset);
}
@Override
public int writerOffset() {
return delegate.writerOffset();
}
@Override
public Buffer writerOffset(int offset) {
return delegate.writerOffset(offset);
}
@Override
public int readableBytes() {
return delegate.readableBytes();
}
@Override
public int writableBytes() {
return delegate.writableBytes();
}
@Override
public Buffer fill(byte value) {
return delegate.fill(value);
}
@Override
public Buffer makeReadOnly() {
return delegate.makeReadOnly();
}
@Override
public boolean readOnly() {
return delegate.readOnly();
}
@Override
public void copyInto(int srcPos, byte[] dest, int destPos, int length) {
delegate.copyInto(srcPos, dest, destPos, length);
}
@Override
public void copyInto(int srcPos, ByteBuffer dest, int destPos, int length) {
delegate.copyInto(srcPos, dest, destPos, length);
}
@Override
public void copyInto(int srcPos, Buffer dest, int destPos, int length) {
delegate.copyInto(srcPos, dest, destPos, length);
}
@Override
public Buffer writeBytes(Buffer source) {
return delegate.writeBytes(source);
}
@Override
public Buffer writeBytes(byte[] source) {
return delegate.writeBytes(source);
}
@Override
public Buffer resetOffsets() {
return delegate.resetOffsets();
}
@Override
public ByteCursor openCursor() {
return delegate.openCursor();
}
@Override
public ByteCursor openCursor(int fromOffset, int length) {
return delegate.openCursor(fromOffset, length);
}
@Override
public ByteCursor openReverseCursor() {
return delegate.openReverseCursor();
}
@Override
public ByteCursor openReverseCursor(int fromOffset, int length) {
return delegate.openReverseCursor(fromOffset, length);
}
@Override
public Buffer ensureWritable(int size) {
return delegate.ensureWritable(size);
}
@Override
public Buffer ensureWritable(int size, int minimumGrowth, boolean allowCompaction) {
return delegate.ensureWritable(size, minimumGrowth, allowCompaction);
}
@Override
public Buffer copy() {
return delegate.copy();
}
@Override
public Buffer copy(int offset, int length) {
return delegate.copy(offset, length);
}
@Override
public Buffer split() {
return delegate.split();
}
@Override
public Buffer split(int splitOffset) {
return delegate.split(splitOffset);
}
@Override
public Buffer compact() {
return delegate.compact();
}
@Override
public int countComponents() {
return delegate.countComponents();
}
@Override
public int countReadableComponents() {
return delegate.countReadableComponents();
}
@Override
public int countWritableComponents() {
return delegate.countWritableComponents();
}
@Override
public