title: why can I only read 2048 bytes at a time from an okhttp.Response InputStream?
body: <p>I am downloading a file using an OkHttp GET request:</p>
  
  <pre><code>import com.squareup.okhttp.OkHttpClient;
  import com.squareup.okhttp.Request;
  import com.squareup.okhttp.Response;
  ...
  OkHttpClient okClient = new OkHttpClient();
  Request request = Request.Builder().url(url).get();
  Response response = okClient.newCall(request).execute();
  </code></pre>
  
  <p>I read from the response body and decorating it with a <code>BufferedInputStream</code>, with a buffer size of 4096:</p>
  
  <pre><code>BufferedInputStream in = new BufferedInputStream(response.body().byteStream(), 4096);
  </code></pre>
  
  <p>However, when I try to read from the buffer, the first read returns 1179 bytes. After that, I am only able to read 2048 bytes at a time:</p>
  
  <pre><code>byte[] buffer = new byte[4096];
  while (true) {
      int bytesRead = in.read(buffer); //bytesRead is always 2048, except the first read
      if (bytesRead == -1) break;
  }
  </code></pre>
  
  <p>Several related questions:</p>
  
  <ol>
  <li>What could be causing the first read to return 1179 bytes? Some sort of file header?</li>
  <li>Why are reads from the <code>InputStream</code> being paged to a size of 2048 bytes, instead of the value specified by the <code>BufferedInputStream</code> wrapper?</li>
  <li>Is there a way to configure the <code>OkHttpClient</code> to read more than 2048 bytes from the buffer?</li>
  </ol>