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 2525import java .util .Map ;
2626import java .util .Set ;
2727
28+ import org .apache .commons .io .IOUtils ;
2829import org .apache .commons .lang3 .ArrayUtils ;
2930import org .apache .commons .vfs2 .FileContent ;
3031import org .apache .commons .vfs2 .FileContentInfo ;
@@ -848,29 +849,18 @@ public long write(final OutputStream output) throws IOException {
848849 }
849850
850851 /**
851- * Writes this content to an OutputStream.
852+ * Copies this content to an OutputStream.
852853 *
853854 * @param output The target OutputStream.
854855 * @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.
856857 * @throws IOException if an error occurs writing the file.
857858 * @since 2.1
858859 */
859860 @ Override
860861 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 ]);
873864 }
874- return count ;
875865 }
876866}
You can’t perform that action at this time.
0 commit comments