Permalink
Browse files

use java.nio in do-copy method for Files

NIO Channels reduce CPU/Disk load when copying Files (by using
syscalls like sendfile internally on Linux/Solaris).
  • Loading branch information...
1 parent 5fc75df commit 2b5ab103cbcfe6c49236ac6966c032d3c922233d @juergenhoetzel committed Oct 6, 2010
Showing with 4 additions and 3 deletions.
  1. +4 −3 src/clj/clojure/java/io.clj
@@ -334,9 +334,10 @@
(do-copy in output opts)))
(defmethod do-copy [File File] [#^File input #^File output opts]
- (with-open [in (FileInputStream. input)
- out (FileOutputStream. output)]
- (do-copy in out opts)))
+ (with-open [in (-> input FileInputStream. .getChannel)
+ out (-> output FileOutputStream. .getChannel)]
+ (.transferTo in 0 (.size in) out))
+ nil)
(defmethod do-copy [String OutputStream] [#^String input #^OutputStream output opts]
(do-copy (StringReader. input) output opts))

0 comments on commit 2b5ab10

Please sign in to comment.