Repository: arrow Updated Branches: refs/heads/master 6b3ae2aec -> f7f915d90
ARROW-615: [Java] Moved ByteArrayReadableSeekableByteChannel to src main o.a.a.vector.util The ByteArrayReadableSeekableByteChannel is useful when reading an ArrowRecordBatch from a byte array with ArrowReader. Currently it is vector.file test package, this change moves the class to src/main/java/o.a.a.vector.util. Updated test usage. Author: Bryan Cutler <cutl...@gmail.com> Closes #370 from BryanCutler/move-ByteArrayReadableSeekableByteChannel-ARROW-615 and squashes the following commits: 46f32a3 [Bryan Cutler] moved ByteArrayReadableSeekableByteChannel to src main o.a.a.vector.util Project: http://git-wip-us.apache.org/repos/asf/arrow/repo Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/f7f915d9 Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/f7f915d9 Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/f7f915d9 Branch: refs/heads/master Commit: f7f915d90aee8affb40616bc14877afde9b32898 Parents: 6b3ae2a Author: Bryan Cutler <cutl...@gmail.com> Authored: Fri Mar 10 19:39:35 2017 -0500 Committer: Wes McKinney <wes.mckin...@twosigma.com> Committed: Fri Mar 10 19:39:35 2017 -0500 ---------------------------------------------------------------------- .../ByteArrayReadableSeekableByteChannel.java | 80 ++++++++++++++++++++ .../ByteArrayReadableSeekableByteChannel.java | 80 -------------------- .../vector/file/TestArrowReaderWriter.java | 1 + 3 files changed, 81 insertions(+), 80 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/arrow/blob/f7f915d9/java/vector/src/main/java/org/apache/arrow/vector/util/ByteArrayReadableSeekableByteChannel.java ---------------------------------------------------------------------- diff --git a/java/vector/src/main/java/org/apache/arrow/vector/util/ByteArrayReadableSeekableByteChannel.java b/java/vector/src/main/java/org/apache/arrow/vector/util/ByteArrayReadableSeekableByteChannel.java new file mode 100644 index 0000000..69840fe --- /dev/null +++ b/java/vector/src/main/java/org/apache/arrow/vector/util/ByteArrayReadableSeekableByteChannel.java @@ -0,0 +1,80 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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 + * + * 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 org.apache.arrow.vector.util; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.SeekableByteChannel; + +public class ByteArrayReadableSeekableByteChannel implements SeekableByteChannel { + private byte[] byteArray; + private int position = 0; + + public ByteArrayReadableSeekableByteChannel(byte[] byteArray) { + if (byteArray == null) { + throw new NullPointerException(); + } + this.byteArray = byteArray; + } + + @Override + public boolean isOpen() { + return byteArray != null; + } + + @Override + public void close() throws IOException { + byteArray = null; + } + + @Override + public int read(final ByteBuffer dst) throws IOException { + int remainingInBuf = byteArray.length - this.position; + int length = Math.min(dst.remaining(), remainingInBuf); + dst.put(this.byteArray, this.position, length); + this.position += length; + return length; + } + + @Override + public long position() throws IOException { + return this.position; + } + + @Override + public SeekableByteChannel position(final long newPosition) throws IOException { + this.position = (int)newPosition; + return this; + } + + @Override + public long size() throws IOException { + return this.byteArray.length; + } + + @Override + public int write(final ByteBuffer src) throws IOException { + throw new UnsupportedOperationException("Read only"); + } + + @Override + public SeekableByteChannel truncate(final long size) throws IOException { + throw new UnsupportedOperationException("Read only"); + } + +} http://git-wip-us.apache.org/repos/asf/arrow/blob/f7f915d9/java/vector/src/test/java/org/apache/arrow/vector/file/ByteArrayReadableSeekableByteChannel.java ---------------------------------------------------------------------- diff --git a/java/vector/src/test/java/org/apache/arrow/vector/file/ByteArrayReadableSeekableByteChannel.java b/java/vector/src/test/java/org/apache/arrow/vector/file/ByteArrayReadableSeekableByteChannel.java deleted file mode 100644 index 7c423d5..0000000 --- a/java/vector/src/test/java/org/apache/arrow/vector/file/ByteArrayReadableSeekableByteChannel.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF 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 - * - * 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 org.apache.arrow.vector.file; - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.channels.SeekableByteChannel; - -public class ByteArrayReadableSeekableByteChannel implements SeekableByteChannel { - private byte[] byteArray; - private int position = 0; - - public ByteArrayReadableSeekableByteChannel(byte[] byteArray) { - if (byteArray == null) { - throw new NullPointerException(); - } - this.byteArray = byteArray; - } - - @Override - public boolean isOpen() { - return byteArray != null; - } - - @Override - public void close() throws IOException { - byteArray = null; - } - - @Override - public int read(final ByteBuffer dst) throws IOException { - int remainingInBuf = byteArray.length - this.position; - int length = Math.min(dst.remaining(), remainingInBuf); - dst.put(this.byteArray, this.position, length); - this.position += length; - return length; - } - - @Override - public long position() throws IOException { - return this.position; - } - - @Override - public SeekableByteChannel position(final long newPosition) throws IOException { - this.position = (int)newPosition; - return this; - } - - @Override - public long size() throws IOException { - return this.byteArray.length; - } - - @Override - public int write(final ByteBuffer src) throws IOException { - throw new UnsupportedOperationException("Read only"); - } - - @Override - public SeekableByteChannel truncate(final long size) throws IOException { - throw new UnsupportedOperationException("Read only"); - } - -} http://git-wip-us.apache.org/repos/asf/arrow/blob/f7f915d9/java/vector/src/test/java/org/apache/arrow/vector/file/TestArrowReaderWriter.java ---------------------------------------------------------------------- diff --git a/java/vector/src/test/java/org/apache/arrow/vector/file/TestArrowReaderWriter.java b/java/vector/src/test/java/org/apache/arrow/vector/file/TestArrowReaderWriter.java index 96bcbb1..13b04de 100644 --- a/java/vector/src/test/java/org/apache/arrow/vector/file/TestArrowReaderWriter.java +++ b/java/vector/src/test/java/org/apache/arrow/vector/file/TestArrowReaderWriter.java @@ -39,6 +39,7 @@ import org.apache.arrow.vector.schema.ArrowRecordBatch; import org.apache.arrow.vector.types.pojo.ArrowType; import org.apache.arrow.vector.types.pojo.Field; import org.apache.arrow.vector.types.pojo.Schema; +import org.apache.arrow.vector.util.ByteArrayReadableSeekableByteChannel; import org.junit.Before; import org.junit.Test;