Honestly, for this kind of low-level stuff I always use the Apache
Commons libraries, <http://commons.apache.org/>, esp. the Lang and IO
components. They've got every imaginable stream function, all
carefully and efficiently implemented. But if you're determined to do
it in Clojure, loop/recur is the way, as James demonstrated.
-Stuart Sierra
On Nov 23, 1:35 pm, Parth Malwankar <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I am trying to translate the following Java
> snippet into a file copy routine in Clojure.
>
> public static void copy(InputStream in, OutputStream out) throws
> IOException {
> byte[] buffer = new byte[1024];
> while (true) {
> int bytesRead = in.read(buffer);
> if (bytesRead == -1) break;
> out.write(buffer, 0, bytesRead);
> }
> }
>
> I was barely able to start:
>
> (defn copy [iname oname]
> (let [in (new FileInputStream iname)
> out (new FileOutputStream oname)]
> nil))
>
> But now I am totally lost at the "nil". I am not sure how to translate
> the "while" loop.
>
> I would appreciate any pointers on how to do this (or maybe a more
> ideomatic
> way).
>
> Thanks.
> Parth
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---