From 76f2d91bc9f612d4e98fe7d8099dffd36c47ff85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Mej=C3=ADa?= Date: Tue, 22 Aug 2017 14:50:12 +0200 Subject: [PATCH] [BEAM-2790] Use byte[] instead of ByteBuffer to read from Hadoop FS --- .../org/apache/beam/sdk/io/hdfs/HadoopFileSystem.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sdks/java/io/hadoop-file-system/src/main/java/org/apache/beam/sdk/io/hdfs/HadoopFileSystem.java b/sdks/java/io/hadoop-file-system/src/main/java/org/apache/beam/sdk/io/hdfs/HadoopFileSystem.java index 803ddb6c1ec3..d4306e77303f 100644 --- a/sdks/java/io/hadoop-file-system/src/main/java/org/apache/beam/sdk/io/hdfs/HadoopFileSystem.java +++ b/sdks/java/io/hadoop-file-system/src/main/java/org/apache/beam/sdk/io/hdfs/HadoopFileSystem.java @@ -189,7 +189,14 @@ public int read(ByteBuffer dst) throws IOException { if (closed) { throw new IOException("Channel is closed"); } - return inputStream.read(dst); + // We avoid using the ByteBuffer based read for Hadoop because some FSInputStream + // implementations are not ByteBufferReadable, + // See https://issues.apache.org/jira/browse/HADOOP-14603 + int read = inputStream.read(dst.array()); + if (read > 0) { + dst.position(dst.position() + read); + } + return read; } @Override