fix bugs in CachingHttpContentFactory, ResourceService and FileMappedHttpContentFactory

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2022-10-21 11:42:03 +11:00
parent 0e1bae4059
commit 98c6675159
3 changed files with 5 additions and 5 deletions

View File

@ -217,7 +217,7 @@ public class CachingHttpContentFactory implements HttpContent.Factory
if (wasAdded.get())
shrinkCache();
return cachingHttpContent;
return (cachingHttpContent instanceof NotFoundHttpContent) ? null : cachingHttpContent;
}
return httpContent;
}

View File

@ -37,7 +37,7 @@ public class FileMappedHttpContentFactory implements HttpContent.Factory
public HttpContent getContent(String path) throws IOException
{
HttpContent content = _factory.getContent(path);
if (content.getContentLengthValue() > 16 * 1024)
if (content != null && content.getContentLengthValue() > 16 * 1024)
return new FileMappedContent(content);
return content;
}

View File

@ -868,10 +868,10 @@ public class ResourceService
@Override
protected Action process() throws Throwable
{
// TODO: use BufferUtil
if (!source.isOpen())
return Action.SUCCEEDED;
byteBuffer.clear();
BufferUtil.clearToFill(byteBuffer.getBuffer());
int read = source.read(byteBuffer.getBuffer());
if (read == -1)
{
@ -879,7 +879,7 @@ public class ResourceService
sink.write(true, BufferUtil.EMPTY_BUFFER, this);
return Action.SCHEDULED;
}
byteBuffer.getBuffer().flip();
BufferUtil.flipToFlush(byteBuffer.getBuffer(), 0);
sink.write(false, byteBuffer.getBuffer(), this);
return Action.SCHEDULED;
}