input-stream

Clojure loop reads one extra.

When length is 4 following loop executes 5 times. Reading 5 characters from the stream. (loop [i (.read stream) result "" counter length] (let [c (char i)] (println "=>" c) (if (zero? counter) result (recur (.read stream) (str result c) (dec counter))))) ...

SHA-1 Hashes Mixed with Strings

I have to parse something like the following "some text <40 byte hash>" can i read this whole thing in to a string without corrupting 40 byte hash part? The thing is hash is not going to be there so i don't want to process it while reading. EDIT: I forgot to mention that the 40 byte hash is 2x20 byte hashes no encoding raw bytes. ...

Clojure function reading from stream locks

I have a function that reads one token from an input stream that is called (get-next-indicator stream indicator) and returns it. I am trying to use it to construct a map. But, when I run it, it locks up. If I remove one of the get-next-indicator function, it does work. Does both functions try to read the stream at the same time is this...

how to read using InputStreamReader without blocking

Is there a simple way to turn the standard code: in = new InputStreamReader(socket.getInputStream()); String message = ""; while ((size = in.read(buf)) != -1){ message += new String(buf, 0, size); } so that read() won't block. I tried doing: if (!in.ready()) //throw exception but this throws an exception all the time. Maybe...

Better data stream reading in Haskell

I am trying to parse an input stream where the first line tells me how many lines of data there are. I'm ending up with the following code, and it works, but I think there is a better way. Is there? main = do numCases <- getLine proc $ read numCases proc :: Integer -> IO () proc numCases | numCases == 0 = return () ...