aboutsummaryrefslogtreecommitdiff
path: root/other/java/hdfs3
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2020-12-02 23:45:39 -0800
committerChris Lu <chris.lu@gmail.com>2020-12-02 23:45:39 -0800
commit3857f9c8404c6f251135268e42c79bb83c13b2b0 (patch)
treec656c40a9dc9ec47b05eadb3ed0f90005bfd9ef6 /other/java/hdfs3
parent003b6245e701bfb6b7f118552a2b4e82d1d7de67 (diff)
downloadseaweedfs-3857f9c8404c6f251135268e42c79bb83c13b2b0.tar.xz
seaweedfs-3857f9c8404c6f251135268e42c79bb83c13b2b0.zip
Hadoop: switch to ByteBuffer
fix https://github.com/chrislusf/seaweedfs/issues/1645
Diffstat (limited to 'other/java/hdfs3')
-rw-r--r--other/java/hdfs3/src/main/java/seaweed/hdfs/SeaweedFileSystemStore.java2
-rw-r--r--other/java/hdfs3/src/main/java/seaweed/hdfs/SeaweedInputStream.java31
2 files changed, 22 insertions, 11 deletions
diff --git a/other/java/hdfs3/src/main/java/seaweed/hdfs/SeaweedFileSystemStore.java b/other/java/hdfs3/src/main/java/seaweed/hdfs/SeaweedFileSystemStore.java
index 2ef1a7468..14b32528e 100644
--- a/other/java/hdfs3/src/main/java/seaweed/hdfs/SeaweedFileSystemStore.java
+++ b/other/java/hdfs3/src/main/java/seaweed/hdfs/SeaweedFileSystemStore.java
@@ -288,4 +288,4 @@ public class SeaweedFileSystemStore {
}
-} \ No newline at end of file
+}
diff --git a/other/java/hdfs3/src/main/java/seaweed/hdfs/SeaweedInputStream.java b/other/java/hdfs3/src/main/java/seaweed/hdfs/SeaweedInputStream.java
index 2cf544162..752f06374 100644
--- a/other/java/hdfs3/src/main/java/seaweed/hdfs/SeaweedInputStream.java
+++ b/other/java/hdfs3/src/main/java/seaweed/hdfs/SeaweedInputStream.java
@@ -86,11 +86,29 @@ public class SeaweedInputStream extends FSInputStream implements ByteBufferReada
throw new IllegalArgumentException("requested read length is more than will fit after requested offset in buffer");
}
+ ByteBuffer buf = ByteBuffer.wrap(b, off, len);
+ return read(buf);
+
+ }
+
+ // implement ByteBufferReadable
+ @Override
+ public synchronized int read(ByteBuffer buf) throws IOException {
+
+ if (position < 0) {
+ throw new IllegalArgumentException("attempting to read from negative offset");
+ }
+ if (position >= contentLength) {
+ return -1; // Hadoop prefers -1 to EOFException
+ }
+
long bytesRead = 0;
- if (position+len <= entry.getContent().size()) {
- entry.getContent().copyTo(b, (int) position, (int) off, len);
+ int len = buf.remaining();
+ int start = (int) this.position;
+ if (start+len <= entry.getContent().size()) {
+ entry.getContent().substring(start, start+len).copyTo(buf);
} else {
- bytesRead = SeaweedRead.read(this.filerGrpcClient, this.visibleIntervalList, this.position, b, off, len, SeaweedRead.fileSize(entry));
+ bytesRead = SeaweedRead.read(this.filerGrpcClient, this.visibleIntervalList, this.position, buf, SeaweedRead.fileSize(entry));
}
if (bytesRead > Integer.MAX_VALUE) {
@@ -105,13 +123,6 @@ public class SeaweedInputStream extends FSInputStream implements ByteBufferReada
}
return (int) bytesRead;
-
- }
-
- // implement ByteBufferReadable
- @Override
- public synchronized int read(ByteBuffer buf) throws IOException {
- return read(buf.array(), buf.position(), buf.remaining());
}
/**