@@ -48,6 +48,7 @@ public class EncryptedFileSystem extends FilterFileSystem {
48
48
private static final String FS_SCHEME = CONF_PREFIX + "scheme" ;
49
49
private static final String FS_IMPL = CONF_PREFIX + "impl" ;
50
50
private static final String DECRYPTOR_IMPL = CONF_PREFIX + "decryptor.impl" ;
51
+ private static final int DEFAULT_BUFFER_SIZE = 4096 ;
51
52
52
53
private static final Logger LOG = LoggerFactory .getLogger (EncryptedFileSystem .class );
53
54
@@ -109,6 +110,18 @@ public FSDataInputStream open(Path path, int bufferSize) throws IOException {
109
110
return new FSDataInputStream (new SeekableByteChannelFSInputStream (decryptor .open (fs , path , bufferSize )));
110
111
}
111
112
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
+ */
112
125
@ Override
113
126
public FutureDataInputStreamBuilder openFile (Path path ) throws UnsupportedOperationException {
114
127
return new FutureDataInputStreamBuilder () {
@@ -118,7 +131,7 @@ public CompletableFuture<FSDataInputStream> build()
118
131
return CompletableFuture .supplyAsync (() -> {
119
132
try {
120
133
return new FSDataInputStream (
121
- new SeekableByteChannelFSInputStream (decryptor .open (fs , path , 4096 )));
134
+ new SeekableByteChannelFSInputStream (decryptor .open (fs , path , DEFAULT_BUFFER_SIZE )));
122
135
} catch (Exception e ) {
123
136
throw new CompletionException (e );
124
137
}
@@ -127,26 +140,39 @@ public CompletableFuture<FSDataInputStream> build()
127
140
128
141
@ Override
129
142
public FutureDataInputStreamBuilder opt (@ NotNull String s , @ NotNull String s1 ) {
130
- return null ;
143
+ return this ;
131
144
}
132
145
133
146
@ Override
134
147
public FutureDataInputStreamBuilder opt (@ NotNull String s , @ NotNull String ... strings ) {
135
- return null ;
148
+ return this ;
136
149
}
137
150
138
151
@ Override
139
152
public FutureDataInputStreamBuilder must (@ NotNull String s , @ NotNull String s1 ) {
140
- return null ;
153
+ return this ;
141
154
}
142
155
143
156
@ Override
144
157
public FutureDataInputStreamBuilder must (@ NotNull String s , @ NotNull String ... strings ) {
145
- return null ;
158
+ return this ;
146
159
}
147
160
};
148
161
}
149
162
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
+ */
150
176
@ Override
151
177
protected CompletableFuture <FSDataInputStream > openFileWithOptions (Path path , OpenFileParameters parameters ) {
152
178
return CompletableFuture .supplyAsync (() -> {
0 commit comments