Don't slurp twice. Slurp mutates the stream by reading bytes off of it.

Also, slurping an xml stream isn't a good idea, because the xml header can
change the character encoding like so

<?xml version="1.0" encoding="ISO-8859-1"?>

Try

(let [bufstream (doto (java.io.ByteArrayOutputStream. content-length)
                  (clojure.java.io/copy body bufstream))
      buffer (.toByteArray bufstream)]
  (parse-1 (java.io.ByteArrayInputStream. buffer))
  (parse-2 (java.io.ByteArrayInputStream. buffer)))

This way, your parse functions that take an input stream work unchanged.
Be aware, that this allocates memory in the size of the body.


2014-03-02 18:23 GMT+01:00 action <actioncao2...@gmail.com>:

> how to use slurp?
> first:
> (slurp body)
> and second reuse:
>  (slurp body)
>
> 在 2014年3月3日星期一UTC+8上午12时44分09秒,James Reeves写道:
>>
>> Depending on how large the input is, you could either read it all into
>> memory (e.g. with slurp or similar), or dump it to a temporary file.
>>
>> - James
>>
>>
>> On 2 March 2014 16:18, action <action...@gmail.com> wrote:
>>
>>>  I want to parse the POST body twice,
>>> but in the second place:
>>> org.xml.sax.SAXParseException: Premature end of file.
>>> How should I clone the body render for the second parse?
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Clojure" group.
>>> To post to this group, send email to clo...@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+u...@googlegroups.com
>>>
>>> For more options, visit this group at
>>> http://groups.google.com/group/clojure?hl=en
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "Clojure" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to clojure+u...@googlegroups.com.
>>>
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>
>>  --
> 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
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to