Skip to content

Commit a9eb743

Browse files
committed
Added the javadoc for openFile and openFileWithOptions method
1 parent 69d7230 commit a9eb743

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

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

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public class EncryptedFileSystem extends FilterFileSystem {
4848
private static final String FS_SCHEME = CONF_PREFIX + "scheme";
4949
private static final String FS_IMPL = CONF_PREFIX + "impl";
5050
private static final String DECRYPTOR_IMPL = CONF_PREFIX + "decryptor.impl";
51+
private static final int DEFAULT_BUFFER_SIZE = 4096;
5152

5253
private static final Logger LOG = LoggerFactory.getLogger(EncryptedFileSystem.class);
5354

@@ -109,6 +110,18 @@ public FSDataInputStream open(Path path, int bufferSize) throws IOException {
109110
return new FSDataInputStream(new SeekableByteChannelFSInputStream(decryptor.open(fs, path, bufferSize)));
110111
}
111112

113+
/**
114+
* Opens a file asynchronously and returns a {@link FutureDataInputStreamBuilder}
115+
* to build a {@link FSDataInputStream} for the specified {@link Path}.
116+
*
117+
* <p>This implementation returns a builder that constructs an input stream by using a decryptor
118+
* to open the file through a {@link SeekableByteChannelFSInputStream}. The file is read
119+
* with a buffer size of 4096 bytes.</p>
120+
*
121+
* @param path the {@link Path} of the file to open
122+
* @return a {@link FutureDataInputStreamBuilder} that asynchronously builds a {@link FSDataInputStream}
123+
* @throws UnsupportedOperationException if the operation is not supported
124+
*/
112125
@Override
113126
public FutureDataInputStreamBuilder openFile(Path path) throws UnsupportedOperationException {
114127
return new FutureDataInputStreamBuilder() {
@@ -118,7 +131,7 @@ public CompletableFuture<FSDataInputStream> build()
118131
return CompletableFuture.supplyAsync(() -> {
119132
try {
120133
return new FSDataInputStream(
121-
new SeekableByteChannelFSInputStream(decryptor.open(fs, path, 4096)));
134+
new SeekableByteChannelFSInputStream(decryptor.open(fs, path, DEFAULT_BUFFER_SIZE)));
122135
} catch (Exception e) {
123136
throw new CompletionException(e);
124137
}
@@ -127,26 +140,39 @@ public CompletableFuture<FSDataInputStream> build()
127140

128141
@Override
129142
public FutureDataInputStreamBuilder opt(@NotNull String s, @NotNull String s1) {
130-
return null;
143+
return this;
131144
}
132145

133146
@Override
134147
public FutureDataInputStreamBuilder opt(@NotNull String s, @NotNull String... strings) {
135-
return null;
148+
return this;
136149
}
137150

138151
@Override
139152
public FutureDataInputStreamBuilder must(@NotNull String s, @NotNull String s1) {
140-
return null;
153+
return this;
141154
}
142155

143156
@Override
144157
public FutureDataInputStreamBuilder must(@NotNull String s, @NotNull String... strings) {
145-
return null;
158+
return this;
146159
}
147160
};
148161
}
149162

163+
/**
164+
* Opens a file asynchronously using the provided {@link Path}, and returns
165+
* a {@link CompletableFuture} that supplies a {@link FSDataInputStream}.
166+
*
167+
* <p>This method uses a decryptor to open the file and wraps it in a {@link SeekableByteChannelFSInputStream}.
168+
* It uses the buffer size specified in the {@code parameters}; if the buffer size is not greater than zero,
169+
* a default of 4096 bytes is used.</p>
170+
*
171+
* @param path the {@link Path} to the file to open
172+
* @param parameters the {@link OpenFileParameters} containing optional configuration, such as buffer size
173+
* @return a {@link CompletableFuture} that will complete with the {@link FSDataInputStream}
174+
* @throws CompletionException if an exception occurs during file opening
175+
*/
150176
@Override
151177
protected CompletableFuture<FSDataInputStream> openFileWithOptions(Path path, OpenFileParameters parameters) {
152178
return CompletableFuture.supplyAsync(() -> {

0 commit comments

Comments
 (0)