Ejemplo n.º 1
0
 @Override
 void writeBody(final BufferedSource in, final BufferedSink out) throws IOException {
   try {
     final ResponseBody data = body();
     if (data != null) {
       final long length = data.contentLength();
       if (length > 0) {
         out.write(data.source(), data.contentLength());
         out.flush();
       } else if (length < 0) {
         final Buffer buffer = new Buffer();
         final long step = 65536;
         long read;
         while ((read = data.source().read(buffer, step)) > -1) {
           buffer.flush();
           out.write(buffer, read);
           out.flush();
         }
       }
     }
   } finally {
     //        try { in.close(); } catch (final IOException ignore) {}
     //        try { out.close(); } catch (final IOException ignore) {}
     //        try { socket.close(); } catch (final IOException ignore) {}
   }
 }
Ejemplo n.º 2
0
 /**
  * Sets the response body.
  *
  * @param body the response body.
  * @return this
  */
 public Builder body(final ResponseBody body) {
   this.mBody = body;
   if (body == null) {
     contentLength(0);
   } else {
     contentType(body.contentType());
     contentLength(body.contentLength());
   }
   return this;
 }
 @Override
 public long contentLength() {
   return mResponseBody.contentLength();
 }