private byte[] idBufferBlob(final Entry e) { try { final InputStream is = e.openInputStream(); if (is == null) return zeroid; try { state.initializeDigestAndReadBuffer(); final long len = e.getLength(); if (!mightNeedCleaning()) return computeHash(is, len); if (len <= MAXIMUM_FILE_SIZE_TO_READ_FULLY) { ByteBuffer rawbuf = IO.readWholeStream(is, (int) len); byte[] raw = rawbuf.array(); int n = rawbuf.limit(); if (!isBinary(raw, n)) { rawbuf = filterClean(raw, n); raw = rawbuf.array(); n = rawbuf.limit(); } return computeHash(new ByteArrayInputStream(raw, 0, n), n); } if (isBinary(e)) return computeHash(is, len); final long canonLen; final InputStream lenIs = filterClean(e.openInputStream()); try { canonLen = computeLength(lenIs); } finally { safeClose(lenIs); } return computeHash(filterClean(is), canonLen); } finally { safeClose(is); } } catch (IOException err) { // Can't read the file? Don't report the failure either. return zeroid; } }
private ByteBuffer filterClean(byte[] src, int n) throws IOException { InputStream in = new ByteArrayInputStream(src); return IO.readWholeStream(filterClean(in), n); }
public String getEntityContent() throws IOException { Preconditions.checkNotNull(response, "Response is not initialized."); Preconditions.checkNotNull(response.getEntity(), "Response.Entity is not initialized."); ByteBuffer buf = IO.readWholeStream(response.getEntity().getContent(), 1024); return RawParseUtils.decode(buf.array(), buf.arrayOffset(), buf.limit()).trim(); }