Skip to content

Commit c569332

Browse files
prince-cspsainics
authored andcommitted
Added implementation for openFile and openFileWithOptions
1 parent 0f7bab8 commit c569332

2 files changed

Lines changed: 58 additions & 1 deletion

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
<google.tink.version>1.3.0-rc3</google.tink.version>
9090
<guava.version>27.0.1-jre</guava.version>
9191
<hadoop.version>3.3.6</hadoop.version>
92-
<hbase-shaded-client.version>1.4.13</hbase-shaded-client.version>
92+
<hbase-shaded-client.version>2.6.2-hadoop3</hbase-shaded-client.version>
9393
<hbase-shaded-server.version>1.4.13</hbase-shaded-server.version>
9494
<httpclient.version>4.5.13</httpclient.version>
9595
<jackson.core.version>2.13.4.2</jackson.core.version>

src/main/java/io/cdap/plugin/gcp/crypto/EncryptedFileSystem.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@
2222
import org.apache.hadoop.fs.FSInputStream;
2323
import org.apache.hadoop.fs.FileSystem;
2424
import org.apache.hadoop.fs.FilterFileSystem;
25+
import org.apache.hadoop.fs.FutureDataInputStreamBuilder;
2526
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;
2630
import org.slf4j.Logger;
2731
import org.slf4j.LoggerFactory;
2832

@@ -32,6 +36,8 @@
3236
import java.nio.channels.Channels;
3337
import java.nio.channels.SeekableByteChannel;
3438
import java.util.Map;
39+
import java.util.concurrent.CompletableFuture;
40+
import java.util.concurrent.CompletionException;
3541

3642
/**
3743
* 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 {
103109
return new FSDataInputStream(new SeekableByteChannelFSInputStream(decryptor.open(fs, path, bufferSize)));
104110
}
105111

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+
106163
/**
107164
* A {@link FSInputStream} implementation backed by a {@link SeekableByteChannel}.
108165
*/

0 commit comments

Comments
 (0)