/** @return an excerpt from the data copied. */ @SuppressWarnings("resource") public static byte[] copyAll(InputStream from, OutputStream into) throws IOException { final ExcerptInputStream ex = new ExcerptInputStream(from); ex.copyAll(into); return ex.getExcerpt(); }
HttpEntityEnclosingRequestBase entityEnclosingMethod = isPost ? new HttpPost(url) : new HttpPut(url); if (body != null) { ExcerptInputStream e = new ExcerptInputStream(body); excerpt = e.getExcerpt(); String length = request.removeHeaders(HttpMessage.CONTENT_LENGTH); entityEnclosingMethod
public final InputStream getBody() throws IOException { if (body == null) { InputStream raw = openBody(); if (raw != null) { body = new ExcerptInputStream(raw); } } return body; }
response.append(new String(((ExcerptInputStream) body).getExcerpt(), getContentCharset()));
@Override public int read(byte[] b) throws IOException { return read(b, 0, b.length); }
/** Copy all the data from this stream to the given output stream. */ private void copyAll(OutputStream into) throws IOException { byte[] b = new byte[1024]; for (int n; 0 < (n = read(b));) { into.write(b, 0, n); } }
/** The first few bytes of data, plus ELLIPSIS if there are more bytes. */ public byte[] getExcerpt() throws IOException { if (taken < excerpt.length) { final int mark = Math.min(given, taken); given = Integer.MAX_VALUE; while (taken < excerpt.length) { read(excerpt, taken, LIMIT - taken); } given = mark; } return excerpt; }