Various code clean-up. No functional changes.

This commit is contained in:
Harald Kuhr 2011-03-02 17:26:17 +01:00
parent e75741ccd3
commit af7d5fa94a
8 changed files with 36 additions and 35 deletions

View File

@ -568,6 +568,7 @@ public final class FileUtil {
if (!pFile.exists()) {
throw new FileNotFoundException(pFile.toString());
}
byte[] bytes = new byte[(int) pFile.length()];
InputStream in = null;
@ -586,6 +587,7 @@ public final class FileUtil {
finally {
close(in);
}
return bytes;
}

View File

@ -46,8 +46,8 @@ import java.util.zip.Deflater;
*/
final class DeflateEncoder implements Encoder {
private final Deflater mDeflater;
private final byte[] mBuffer = new byte[1024];
private final Deflater deflater;
private final byte[] buffer = new byte[1024];
public DeflateEncoder() {
// this(new Deflater());
@ -59,32 +59,32 @@ final class DeflateEncoder implements Encoder {
throw new IllegalArgumentException("deflater == null");
}
mDeflater = pDeflater;
deflater = pDeflater;
}
public void encode(final OutputStream pStream, final byte[] pBuffer, final int pOffset, final int pLength)
throws IOException
{
System.out.println("DeflateEncoder.encode");
mDeflater.setInput(pBuffer, pOffset, pLength);
deflater.setInput(pBuffer, pOffset, pLength);
flushInputToStream(pStream);
}
private void flushInputToStream(final OutputStream pStream) throws IOException {
System.out.println("DeflateEncoder.flushInputToStream");
if (mDeflater.needsInput()) {
if (deflater.needsInput()) {
System.out.println("Foo");
}
while (!mDeflater.needsInput()) {
int deflated = mDeflater.deflate(mBuffer, 0, mBuffer.length);
pStream.write(mBuffer, 0, deflated);
while (!deflater.needsInput()) {
int deflated = deflater.deflate(buffer, 0, buffer.length);
pStream.write(buffer, 0, deflated);
System.out.println("flushed " + deflated);
}
}
// public void flush() {
// mDeflater.finish();
// deflater.finish();
// }
}

View File

@ -49,9 +49,9 @@ import java.util.zip.Inflater;
*/
final class InflateDecoder implements Decoder {
private final Inflater mInflater;
private final Inflater inflater;
private final byte[] mBuffer;
private final byte[] buffer;
/**
* Creates an {@code InflateDecoder}
@ -71,20 +71,20 @@ final class InflateDecoder implements Decoder {
throw new IllegalArgumentException("inflater == null");
}
mInflater = pInflater;
mBuffer = new byte[1024];
inflater = pInflater;
buffer = new byte[1024];
}
public int decode(final InputStream pStream, final byte[] pBuffer) throws IOException {
try {
int decoded;
while ((decoded = mInflater.inflate(pBuffer, 0, pBuffer.length)) == 0) {
if (mInflater.finished() || mInflater.needsDictionary()) {
while ((decoded = inflater.inflate(pBuffer, 0, pBuffer.length)) == 0) {
if (inflater.finished() || inflater.needsDictionary()) {
return 0;
}
if (mInflater.needsInput()) {
if (inflater.needsInput()) {
fill(pStream);
}
}
@ -98,12 +98,12 @@ final class InflateDecoder implements Decoder {
}
private void fill(final InputStream pStream) throws IOException {
int available = pStream.read(mBuffer, 0, mBuffer.length);
int available = pStream.read(buffer, 0, buffer.length);
if (available == -1) {
throw new EOFException("Unexpected end of ZLIB stream");
}
mInflater.setInput(mBuffer, 0, available);
inflater.setInput(buffer, 0, available);
}
}

View File

@ -67,7 +67,7 @@ public class CacheFilter extends GenericFilter {
public void init() throws ServletException {
FilterConfig config = getFilterConfig();
// Default don't delete cache files on exit (peristent cache)
// Default don't delete cache files on exit (persistent cache)
boolean deleteCacheOnExit = "TRUE".equalsIgnoreCase(config.getInitParameter("deleteCacheOnExit"));
// Default expiry time 10 minutes
@ -76,6 +76,7 @@ public class CacheFilter extends GenericFilter {
String expiryTimeStr = config.getInitParameter("expiryTime");
if (!StringUtil.isEmpty(expiryTimeStr)) {
try {
// TODO: This is insane.. :-P Let the expiry time be in minutes or seconds..
expiryTime = Integer.parseInt(expiryTimeStr);
}
catch (NumberFormatException e) {
@ -179,21 +180,21 @@ public class CacheFilter extends GenericFilter {
// TODO: Extract, complete and document this class, might be useful in other cases
// Maybe add it to the ServletUtil class
static class ServletContextLoggerAdapter extends Logger {
private final ServletContext mContext;
private final ServletContext context;
public ServletContextLoggerAdapter(String pName, ServletContext pContext) {
super(pName, null);
mContext = pContext;
context = pContext;
}
@Override
public void log(Level pLevel, String pMessage) {
mContext.log(pMessage);
context.log(pMessage);
}
@Override
public void log(Level pLevel, String pMessage, Throwable pThrowable) {
mContext.log(pMessage, pThrowable);
context.log(pMessage, pThrowable);
}
}
}

View File

@ -69,7 +69,7 @@ class CacheResponseWrapper extends HttpServletResponseWrapper {
}
/*
NOTE: This class defers determining if a response is cachable until the
NOTE: This class defers determining if a response is cacheable until the
output stream is needed.
This it the reason for the somewhat complicated logic in the add/setHeader
methods below.
@ -80,7 +80,7 @@ class CacheResponseWrapper extends HttpServletResponseWrapper {
cachedResponse = cached.createCachedResponse();
streamDelegate = new ServletResponseStreamDelegate(this) {
protected OutputStream createOutputStream() throws IOException {
// Test if this request is really cachable, otherwise,
// Test if this request is really cacheable, otherwise,
// just write through to underlying response, and don't cache
if (isCachable()) {
return cachedResponse.getOutputStream();

View File

@ -35,10 +35,7 @@ import com.twelvemonkeys.util.LinkedMap;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
/**
* CachedResponseImpl
@ -53,7 +50,7 @@ class CachedResponseImpl implements CachedResponse {
int status;
protected CachedResponseImpl() {
headers = new LinkedMap<String, List<String>>(); // Keep headers in insertion order
headers = new LinkedHashMap<String, List<String>>(); // Keep headers in insertion order
}
// For use by HTTPCache, when recreating CachedResponses from disk cache
@ -82,7 +79,7 @@ class CachedResponseImpl implements CachedResponse {
continue;
}
// TODO: Replace Last-Modified with X-Cached-At? See CachedEntityImpl, line 50
// TODO: Replace Last-Modified with X-Cached-At? See CachedEntityImpl
String[] headerValues = getHeaderValues(header);
@ -99,7 +96,7 @@ class CachedResponseImpl implements CachedResponse {
}
/**
* Writes the cahced content to the response
* Writes the cached content to the response
*
* @param pStream the response stream
* @throws java.io.IOException
@ -132,6 +129,7 @@ class CachedResponseImpl implements CachedResponse {
*/
public String[] getHeaderValues(final String pHeaderName) {
List<String> values = headers.get(pHeaderName);
if (values == null) {
return null;
}
@ -152,6 +150,7 @@ class CachedResponseImpl implements CachedResponse {
*/
public String getHeaderValue(final String pHeaderName) {
List<String> values = headers.get(pHeaderName);
return (values != null && values.size() > 0) ? values.get(0) : null;
}

View File

@ -12,7 +12,7 @@ import java.io.OutputStream;
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-servlet/src/main/java/com/twelvemonkeys/servlet/cache/ClientCacheResponse.java#2 $
*/
public final class ClientCacheResponse extends AbstractCacheResponse {
// It's quite useless to cahce the data either on disk or in memory, as it already is cached in the client's cache...
// It's quite useless to cache the data either on disk or in memory, as it already is cached in the client's cache...
// It would be nice if we could bypass that...
public OutputStream getOutputStream() throws IOException {

View File

@ -357,8 +357,7 @@ public class HTTPCache {
}
}
// else if (not cached ||<EFBFBD>stale), resolve through wrapped (caching) response
// else if (not cached || stale), resolve through wrapped (caching) response
// else render to response
// TODO: This is a bottleneck for uncachable resources. Should not