diff --git a/java/memory/src/main/java/io/netty/buffer/ArrowBuf.java b/java/memory/src/main/java/io/netty/buffer/ArrowBuf.java index 2a1746fa60f..c3b34b6fc5c 100644 --- a/java/memory/src/main/java/io/netty/buffer/ArrowBuf.java +++ b/java/memory/src/main/java/io/netty/buffer/ArrowBuf.java @@ -77,7 +77,7 @@ public final class ArrowBuf implements AutoCloseable { private int readerIndex; private int writerIndex; private final HistoricalLog historicalLog = BaseAllocator.DEBUG ? - new HistoricalLog(BaseAllocator.DEBUG_LOG_LENGTH, "ArrowBuf[%d]", id) : null; + new HistoricalLog(BaseAllocator.DEBUG_LOG_LENGTH, "ArrowBuf[%d]", id) : null; private volatile int length; /** @@ -1204,4 +1204,51 @@ public ArrowBuf reallocIfNeeded(final int size) { "Realloc is only available in the context of operator's UDFs"); } } + + /** + * Following are wrapper methods to keep this backward compatible. + */ + @Deprecated + public void release() { + referenceManager.release(); + } + + @Deprecated + public void release(int decrement) { + referenceManager.release(decrement); + } + + @Deprecated + public void retain() { + referenceManager.retain(); + } + + @Deprecated + public void retain(int increment) { + referenceManager.retain(increment); + } + + @Deprecated + public ArrowBuf clear() { + this.readerIndex = this.writerIndex = 0; + return this; + } + + /** + * Initialize the reader and writer index. + * @param readerIndex index to read from + * @param writerIndex index to write to + * @return this + */ + @Deprecated + public ArrowBuf setIndex(int readerIndex, int writerIndex) { + if (readerIndex >= 0 && readerIndex <= writerIndex && writerIndex <= this.capacity()) { + this.readerIndex = readerIndex; + this.writerIndex = writerIndex; + return this; + } else { + throw new IndexOutOfBoundsException(String.format("readerIndex: %d, writerIndex: %d " + + "(expected:0 <= readerIndex <= writerIndex <= capacity(%d))", readerIndex, writerIndex, this.capacity())); + } + } } diff --git a/java/memory/src/main/java/io/netty/buffer/NettyArrowBuf.java b/java/memory/src/main/java/io/netty/buffer/NettyArrowBuf.java index 766b2b13e19..3c6bd5e4d08 100644 --- a/java/memory/src/main/java/io/netty/buffer/NettyArrowBuf.java +++ b/java/memory/src/main/java/io/netty/buffer/NettyArrowBuf.java @@ -76,6 +76,10 @@ public ByteBuf retain() { return this; } + public ArrowBuf arrowBuf() { + return arrowBuf; + } + @Override public ByteBuf retain(final int increment) { arrowBuf.getReferenceManager().retain(increment); @@ -351,12 +355,12 @@ public int getBytes(int index, FileChannel out, long position, int length) throw @Override public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException { - throw new UnsupportedOperationException("Operation not supported"); + return (int) in.read(nioBuffers(index, length)); } @Override public int setBytes(int index, FileChannel in, long position, int length) throws IOException { - throw new UnsupportedOperationException("Operation not supported"); + return (int) in.read(nioBuffers(index, length)); } @Override