> But it turns out that this is rather slow. What would be some methods > to speed this up?
You could also wrap your input and output stream's with java.util.zip.GZIPInputStream and GZIPOutputStream to compress/decompress the data either side. They allow you to specify buffer sizes, so you could experiment to find optimum buffer sizes. Check out the java.util.zip package in the javadocs. Rgds, Adrian. On Fri, May 15, 2009 at 5:10 PM, Christopher Wilson <christopher.j.wil...@gmail.com> wrote: > > Hi there, > > I'm working on a project that involves transferring large files over > the network (100+MB) and wondering what would work better. I'm newer > to Java than I am to lisp, so I've just grabbed the most obvious > things from the API that I thought could possibly work: > > (ns misc-ports > (:import (java.io BufferedReader InputStreamReader BufferedOutputStream > PrintWriter FileInputStream BufferedOutputStream > FileOutputStream) > (java.net Socket ServerSocket))) > > (defn net-to-file > "Listen on a port, when accepted dump data to named incoming file." > [port filename] > (with-open [sock (.accept (ServerSocket. port)) > ins (BufferedReader. (InputStreamReader. (.getInputStream sock))) > outf (FileOutputStream. filename)] > (loop [c (.read ins)] > (when-not (== -1 c) > (.write outf c) > (recur (.read ins)))))) > > (defn file-to-net > "Take the name of a file and a waiting ip and port, send named file > on socket." > [filename ipaddr port] > (with-open [sock (Socket. ipaddr port) > outs (BufferedOutputStream. (.getOutputStream sock)) > ins (FileInputStream. filename)] > (loop [c (.read ins)] > (when-not (== -1 c) > (.write outs c) > (recur (.read ins)))))) > > But it turns out that this is rather slow. What would be some methods > to speed this up? > > Thanks! > > -- > Chris > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---