List of usage examples for org.apache.http.impl.io DefaultHttpResponseWriter DefaultHttpResponseWriter
public DefaultHttpResponseWriter(SessionOutputBuffer sessionOutputBuffer)
From source file:it.tidalwave.bluemarine2.downloader.impl.SimpleHttpCacheStorage.java
/******************************************************************************************************************* * * {@inheritDoc}//w w w .j a v a 2 s . c o m * ******************************************************************************************************************/ @Override public void putEntry(final @Nonnull String key, final @Nonnull HttpCacheEntry entry) throws IOException { try { log.debug("putEntry({}, {})", key, entry); final Path cachePath = getCacheItemPath(new URL(key)); createDirectories(cachePath); final Path cacheHeadersPath = cachePath.resolve(PATH_HEADERS); final Path cacheContentPath = cachePath.resolve(PATH_CONTENT); @Cleanup final OutputStream os = newOutputStream(cacheHeadersPath, CREATE); final SessionOutputBufferImpl sob = sessionOutputBufferFrom(os); final DefaultHttpResponseWriter writer = new DefaultHttpResponseWriter(sob); writer.write(responseFrom(entry)); sob.flush(); if (entry.getResource().length() > 0) { copy(entry.getResource().getInputStream(), cacheContentPath, REPLACE_EXISTING); } } catch (HttpException e) { throw new IOException(e); } }