Note that there are some explanatory texts on larger screens.

plurals
  1. POJava, MalformedChunkCodingException
    primarykey
    data
    text
    <p>I have an Android Application that gives me this exception:</p> <pre><code>org.apache.http.MalformedChunkCodingException: CRLF expected at end of chunk </code></pre> <p>The exception is thrown from this method: (Purpose is to write out the response received from the server to a file.) </p> <pre><code>public static void getResponseBodyForServerData( final HttpEntity entity) throws IOException, ParseException { if (entity == null) { throw new IllegalArgumentException("HTTP entity may not be null"); } InputStream instream = entity.getContent(); if (instream == null) { return; } File file = new File(Environment.getExternalStorageDirectory() + "/foo/Response.txt"); if (!file.exists()) { file.createNewFile(); } OutputStream out = new FileOutputStream(file); byte buf[] = new byte[1024]; int len; while ((len = instream.read(buf)) &gt; 0) out.write(buf, 0, len); out.flush(); out.close(); } </code></pre> <p>So then I modified the above code to:</p> <pre><code>public static void getResponseBodyForServerData( final HttpEntity entity) throws IOException, ParseException { if (entity == null) { throw new IllegalArgumentException("HTTP entity may not be null"); } InputStream instream = entity.getContent(); InputStreamReader inputStreamReader = new InputStreamReader( instream, "UNICODE") ; if (instream == null) { return; } File file = new File(Environment.getExternalStorageDirectory() + "/foo/Response.txt"); if (!file.exists()) { file.createNewFile(); } BufferedReader bufferedReader = new BufferedReader(inputStreamReader) ; BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(file),"UNICODE")) ; String singleLine = null ; while((singleLine = bufferedReader.readLine()) != null) { bufferedWriter.write(singleLine) ; } bufferedWriter.flush() ; bufferedWriter.close() ; } </code></pre> <p>And then the code works, What causes that error and what is wrong with the original code?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload