|
22 | 22 | import org.apache.hadoop.fs.FSInputStream; |
23 | 23 | import org.apache.hadoop.fs.FileSystem; |
24 | 24 | import org.apache.hadoop.fs.FilterFileSystem; |
| 25 | +import org.apache.hadoop.fs.FutureDataInputStreamBuilder; |
25 | 26 | import org.apache.hadoop.fs.Path; |
| 27 | +import org.apache.hadoop.fs.PathHandle; |
| 28 | +import org.apache.hadoop.fs.impl.OpenFileParameters; |
| 29 | +import org.jetbrains.annotations.NotNull; |
26 | 30 | import org.slf4j.Logger; |
27 | 31 | import org.slf4j.LoggerFactory; |
28 | 32 |
|
|
32 | 36 | import java.nio.channels.Channels; |
33 | 37 | import java.nio.channels.SeekableByteChannel; |
34 | 38 | import java.util.Map; |
| 39 | +import java.util.concurrent.CompletableFuture; |
| 40 | +import java.util.concurrent.CompletionException; |
35 | 41 |
|
36 | 42 | /** |
37 | 43 | * A hadoop {@link FileSystem} that support files decryption (encryption is currently not supported). |
@@ -103,6 +109,57 @@ public FSDataInputStream open(Path path, int bufferSize) throws IOException { |
103 | 109 | return new FSDataInputStream(new SeekableByteChannelFSInputStream(decryptor.open(fs, path, bufferSize))); |
104 | 110 | } |
105 | 111 |
|
| 112 | + @Override |
| 113 | + public FutureDataInputStreamBuilder openFile(Path path) throws UnsupportedOperationException { |
| 114 | + return new FutureDataInputStreamBuilder() { |
| 115 | + @Override |
| 116 | + public CompletableFuture<FSDataInputStream> build() |
| 117 | + throws IllegalArgumentException, UnsupportedOperationException { |
| 118 | + return CompletableFuture.supplyAsync(() -> { |
| 119 | + try { |
| 120 | + return new FSDataInputStream( |
| 121 | + new SeekableByteChannelFSInputStream(decryptor.open(fs, path, 4096))); |
| 122 | + } catch (Exception e) { |
| 123 | + throw new CompletionException(e); |
| 124 | + } |
| 125 | + }); |
| 126 | + } |
| 127 | + |
| 128 | + @Override |
| 129 | + public FutureDataInputStreamBuilder opt(@NotNull String s, @NotNull String s1) { |
| 130 | + return null; |
| 131 | + } |
| 132 | + |
| 133 | + @Override |
| 134 | + public FutureDataInputStreamBuilder opt(@NotNull String s, @NotNull String... strings) { |
| 135 | + return null; |
| 136 | + } |
| 137 | + |
| 138 | + @Override |
| 139 | + public FutureDataInputStreamBuilder must(@NotNull String s, @NotNull String s1) { |
| 140 | + return null; |
| 141 | + } |
| 142 | + |
| 143 | + @Override |
| 144 | + public FutureDataInputStreamBuilder must(@NotNull String s, @NotNull String... strings) { |
| 145 | + return null; |
| 146 | + } |
| 147 | + }; |
| 148 | + } |
| 149 | + |
| 150 | + @Override |
| 151 | + protected CompletableFuture<FSDataInputStream> openFileWithOptions(Path path, OpenFileParameters parameters) { |
| 152 | + return CompletableFuture.supplyAsync(() -> { |
| 153 | + try { |
| 154 | + int bufferSize = parameters.getBufferSize() > 0 ? parameters.getBufferSize() : 4096; |
| 155 | + return new FSDataInputStream( |
| 156 | + new SeekableByteChannelFSInputStream(decryptor.open(fs, path, bufferSize))); |
| 157 | + } catch (Exception e) { |
| 158 | + throw new CompletionException(e); |
| 159 | + } |
| 160 | + }); |
| 161 | + } |
| 162 | + |
106 | 163 | /** |
107 | 164 | * A {@link FSInputStream} implementation backed by a {@link SeekableByteChannel}. |
108 | 165 | */ |
|
0 commit comments