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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---