On Sat, 2011-12-10 at 23:13 -0800, Simone Mosciatti wrote: > Anyway, i'm looking for read a file byte by byte, perfect would be get > a lazy-seq of every byte in the file, it's looks, for me, very weird > that there isn't a built-in or some easy way to do that
The tradeoffs aren't universal enough to justify "one true" way to do that. You might be willing to pay the overhead of one LazySeq, function, lock, and Byte per byte, but many can't afford it. > To be honest, I need to read N byte at time (where I know N before to > read) so I can built anytime a bite-array and put in the necessary > byte which (def stream (new java.io.FileInputStream filename)) > (def vettore (byte-array N)) > (.read stream vettore) > > But i really don't like this way, the (.read ) is horrible, I guess... It's not Clojure style to replace absolutely everything you might do with Java interop with a standard Clojure-style library. Else, there would be no motivation to make interop so easy. It is Clojure style, though, to use those Clojure libraries that do exist, when appropriate. In this case, see `reader' in the clojure.java.io module included with the standard library, as a replacement for your `new' call. As for the reading part itself, I suggest careful usage of `iterate' and `take-while' (or `lazy-seq' and `cons') from the standard library, with appropriate .read calls. Byte-by-byte reading can be accomplished by writing a single iterate, a single take-while, and a single .read call. -- Stephen Compall ^aCollection allSatisfy: [:each|aCondition]: less is better -- 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 Note that posts from new members are moderated - please be patient with your first post. 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