File tree Expand file tree Collapse file tree 1 file changed +5
-15
lines changed
commons-vfs2/src/main/java/org/apache/commons/vfs2/provider Expand file tree Collapse file tree 1 file changed +5
-15
lines changed Original file line number Diff line number Diff line change 25
25
import java .util .Map ;
26
26
import java .util .Set ;
27
27
28
+ import org .apache .commons .io .IOUtils ;
28
29
import org .apache .commons .lang3 .ArrayUtils ;
29
30
import org .apache .commons .vfs2 .FileContent ;
30
31
import org .apache .commons .vfs2 .FileContentInfo ;
@@ -848,29 +849,18 @@ public long write(final OutputStream output) throws IOException {
848
849
}
849
850
850
851
/**
851
- * Writes this content to an OutputStream.
852
+ * Copies this content to an OutputStream.
852
853
*
853
854
* @param output The target OutputStream.
854
855
* @param bufferSize The buffer size to write data chunks.
855
- * @return the total number of bytes written
856
+ * @return the total number of bytes written.
856
857
* @throws IOException if an error occurs writing the file.
857
858
* @since 2.1
858
859
*/
859
860
@ Override
860
861
public long write (final OutputStream output , final int bufferSize ) throws IOException {
861
- final InputStream input = getInputStream ();
862
- long count = 0 ;
863
- try {
864
- // This read/write code from Apache Commons IO
865
- final byte [] buffer = new byte [bufferSize ];
866
- int n ;
867
- while (-1 != (n = input .read (buffer ))) {
868
- output .write (buffer , 0 , n );
869
- count += n ;
870
- }
871
- } finally {
872
- input .close ();
862
+ try (InputStream inputStream = getInputStream ()) {
863
+ return IOUtils .copyLarge (inputStream , output , new byte [bufferSize ]);
873
864
}
874
- return count ;
875
865
}
876
866
}
You can’t perform that action at this time.
0 commit comments