2323import java .nio .channels .FileChannel ;
2424import java .nio .file .Path ;
2525import java .nio .file .StandardOpenOption ;
26- import java .util .Objects ;
2726
2827import org .apache .commons .io .IOUtils ;
2928import org .apache .commons .io .build .AbstractStreamBuilder ;
@@ -106,8 +105,7 @@ public Builder() {
106105 */
107106 @ Override
108107 public BufferedFileChannelInputStream get () throws IOException {
109- return fileChannel != null ? new BufferedFileChannelInputStream (fileChannel , getBufferSize ())
110- : new BufferedFileChannelInputStream (getPath (), getBufferSize ());
108+ return new BufferedFileChannelInputStream (this );
111109 }
112110
113111 /**
@@ -141,6 +139,13 @@ public static Builder builder() {
141139
142140 private final FileChannel fileChannel ;
143141
142+ @ SuppressWarnings ("resource" )
143+ private BufferedFileChannelInputStream (final Builder builder ) throws IOException {
144+ this .fileChannel = builder .fileChannel != null ? builder .fileChannel : FileChannel .open (builder .getPath (), StandardOpenOption .READ );
145+ this .byteBuffer = ByteBuffer .allocateDirect (builder .getBufferSize ());
146+ this .byteBuffer .flip ();
147+ }
148+
144149 /**
145150 * Constructs a new instance for the given File.
146151 *
@@ -166,12 +171,6 @@ public BufferedFileChannelInputStream(final File file, final int bufferSize) thr
166171 this (file .toPath (), bufferSize );
167172 }
168173
169- private BufferedFileChannelInputStream (final FileChannel fileChannel , final int bufferSize ) {
170- this .fileChannel = Objects .requireNonNull (fileChannel , "path" );
171- byteBuffer = ByteBuffer .allocateDirect (bufferSize );
172- byteBuffer .flip ();
173- }
174-
175174 /**
176175 * Constructs a new instance for the given Path.
177176 *
@@ -192,10 +191,9 @@ public BufferedFileChannelInputStream(final Path path) throws IOException {
192191 * @throws IOException If an I/O error occurs
193192 * @deprecated Use {@link #builder()}, {@link Builder}, and {@link Builder#get()}
194193 */
195- @ SuppressWarnings ("resource" )
196194 @ Deprecated
197195 public BufferedFileChannelInputStream (final Path path , final int bufferSize ) throws IOException {
198- this (FileChannel . open (path , StandardOpenOption . READ ), bufferSize );
196+ this (builder (). setPath (path ). setBufferSize ( bufferSize ) );
199197 }
200198
201199 @ Override
0 commit comments