#10226 - handle review comments
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
This commit is contained in:
parent
5b93435358
commit
1fff9787bd
|
@ -151,13 +151,13 @@ public class MultiPartByteRanges
|
|||
}
|
||||
|
||||
@Override
|
||||
protected int fillBufferFromInputStream(InputStream inputStream, ByteBuffer buffer) throws IOException
|
||||
protected int fillBufferFromInputStream(InputStream inputStream, byte[] buffer) throws IOException
|
||||
{
|
||||
if (toRead == 0)
|
||||
return -1;
|
||||
int toReadInt = (int)Math.min(Integer.MAX_VALUE, toRead);
|
||||
int len = Math.min(toReadInt, buffer.capacity());
|
||||
int read = inputStream.read(buffer.array(), buffer.arrayOffset(), len);
|
||||
int len = Math.min(toReadInt, buffer.length);
|
||||
int read = inputStream.read(buffer, 0, len);
|
||||
toRead -= read;
|
||||
return read;
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ public class MultiPartByteRanges
|
|||
}
|
||||
|
||||
/**
|
||||
* <p>A {@link MultiPart.Part} whose content is a byte range of a file.</p>
|
||||
* <p>A {@link MultiPart.Part} whose content is a byte range of a {@link Resource}.</p>
|
||||
*/
|
||||
public static class Part extends MultiPart.Part
|
||||
{
|
||||
|
|
|
@ -81,7 +81,7 @@ public class InputStreamContentSource implements Content.Source
|
|||
try
|
||||
{
|
||||
ByteBuffer buffer = streamBuffer.getByteBuffer();
|
||||
int read = fillBufferFromInputStream(inputStream, buffer);
|
||||
int read = fillBufferFromInputStream(inputStream, buffer.array());
|
||||
if (read < 0)
|
||||
{
|
||||
streamBuffer.release();
|
||||
|
@ -101,9 +101,9 @@ public class InputStreamContentSource implements Content.Source
|
|||
}
|
||||
}
|
||||
|
||||
protected int fillBufferFromInputStream(InputStream inputStream, ByteBuffer buffer) throws IOException
|
||||
protected int fillBufferFromInputStream(InputStream inputStream, byte[] buffer) throws IOException
|
||||
{
|
||||
return inputStream.read(buffer.array(), buffer.arrayOffset(), buffer.capacity());
|
||||
return inputStream.read(buffer, 0, buffer.length);
|
||||
}
|
||||
|
||||
private void close()
|
||||
|
|
|
@ -91,7 +91,7 @@ public class MultiPartByteRangesTest
|
|||
String boundary = "boundary";
|
||||
try (MultiPartByteRanges.ContentSource content = new MultiPartByteRanges.ContentSource(boundary))
|
||||
{
|
||||
ranges.forEach(range -> content.addPart(new MultiPartByteRanges.Part("text/plain", ResourceFactory.root().newResource(resourcePath), range, content.getLength())));
|
||||
ranges.forEach(range -> content.addPart(new MultiPartByteRanges.Part("text/plain", ResourceFactory.of(this).newResource(resourcePath), range, content.getLength())));
|
||||
content.close();
|
||||
|
||||
response.setStatus(HttpStatus.PARTIAL_CONTENT_206);
|
||||
|
|
|
@ -75,7 +75,7 @@ public class ResourceHandlerByteRangesTest
|
|||
Files.writeString(rangeFile, rangeChars);
|
||||
|
||||
ResourceHandler handler = new ResourceHandler();
|
||||
handler.setBaseResource(ResourceFactory.root().newResource(dir));
|
||||
handler.setBaseResource(ResourceFactory.of(handler).newResource(dir));
|
||||
server.setHandler(handler);
|
||||
server.start();
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ public class ResourceHandlerByteRangesTest
|
|||
{
|
||||
changeHandler(new ResourceHandler()
|
||||
{
|
||||
final Resource memResource = ResourceFactory.root().newMemoryResource(getClass().getResource("/simple/big.txt"));
|
||||
final Resource memResource = ResourceFactory.of(this).newMemoryResource(getClass().getResource("/simple/big.txt"));
|
||||
|
||||
@Override
|
||||
protected HttpContent.Factory newHttpContentFactory()
|
||||
|
@ -131,7 +131,7 @@ public class ResourceHandlerByteRangesTest
|
|||
{
|
||||
changeHandler(new ResourceHandler()
|
||||
{
|
||||
final Resource memResource = ResourceFactory.root().newMemoryResource(getClass().getResource("/simple/big.txt"));
|
||||
final Resource memResource = ResourceFactory.of(this).newMemoryResource(getClass().getResource("/simple/big.txt"));
|
||||
|
||||
@Override
|
||||
protected HttpContent.Factory newHttpContentFactory()
|
||||
|
@ -165,7 +165,7 @@ public class ResourceHandlerByteRangesTest
|
|||
{
|
||||
changeHandler(new ResourceHandler()
|
||||
{
|
||||
final Resource memResource = ResourceFactory.root().newMemoryResource(getClass().getResource("/simple/big.txt"));
|
||||
final Resource memResource = ResourceFactory.of(this).newMemoryResource(getClass().getResource("/simple/big.txt"));
|
||||
|
||||
@Override
|
||||
protected HttpContent.Factory newHttpContentFactory()
|
||||
|
@ -206,7 +206,7 @@ public class ResourceHandlerByteRangesTest
|
|||
{
|
||||
changeHandler(new ResourceHandler()
|
||||
{
|
||||
final Resource memResource = ResourceFactory.root().newMemoryResource(getClass().getResource("/simple/big.txt"));
|
||||
final Resource memResource = ResourceFactory.of(this).newMemoryResource(getClass().getResource("/simple/big.txt"));
|
||||
|
||||
@Override
|
||||
protected HttpContent.Factory newHttpContentFactory()
|
||||
|
@ -249,7 +249,7 @@ public class ResourceHandlerByteRangesTest
|
|||
{
|
||||
changeHandler(new ResourceHandler()
|
||||
{
|
||||
final Resource memResource = ResourceFactory.root().newMemoryResource(getClass().getResource("/simple/big.txt"));
|
||||
final Resource memResource = ResourceFactory.of(this).newMemoryResource(getClass().getResource("/simple/big.txt"));
|
||||
|
||||
@Override
|
||||
protected HttpContent.Factory newHttpContentFactory()
|
||||
|
|
|
@ -3452,7 +3452,7 @@ public class DefaultServletTest
|
|||
@Test
|
||||
public void testMemoryResourceRange() throws Exception
|
||||
{
|
||||
Resource memResource = ResourceFactory.root().newMemoryResource(getClass().getResource("/contextResources/test.txt"));
|
||||
Resource memResource = ResourceFactory.of(context).newMemoryResource(getClass().getResource("/contextResources/test.txt"));
|
||||
DefaultServlet defaultServlet = new DefaultServlet();
|
||||
context.addServlet(new ServletHolder(defaultServlet), "/");
|
||||
defaultServlet.getResourceService().setHttpContentFactory(path -> new ResourceHttpContent(memResource, "text/plain"));
|
||||
|
@ -3473,7 +3473,7 @@ public class DefaultServletTest
|
|||
@Test
|
||||
public void testMemoryResourceRangeUsingBufferedHttpContent() throws Exception
|
||||
{
|
||||
Resource memResource = ResourceFactory.root().newMemoryResource(getClass().getResource("/contextResources/test.txt"));
|
||||
Resource memResource = ResourceFactory.of(context).newMemoryResource(getClass().getResource("/contextResources/test.txt"));
|
||||
DefaultServlet defaultServlet = new DefaultServlet();
|
||||
context.addServlet(new ServletHolder(defaultServlet), "/");
|
||||
defaultServlet.getResourceService().setHttpContentFactory(path -> new ResourceHttpContent(memResource, "text/plain")
|
||||
|
@ -3503,7 +3503,7 @@ public class DefaultServletTest
|
|||
@Test
|
||||
public void testMemoryResourceMultipleRanges() throws Exception
|
||||
{
|
||||
Resource memResource = ResourceFactory.root().newMemoryResource(getClass().getResource("/contextResources/test.txt"));
|
||||
Resource memResource = ResourceFactory.of(context).newMemoryResource(getClass().getResource("/contextResources/test.txt"));
|
||||
DefaultServlet defaultServlet = new DefaultServlet();
|
||||
context.addServlet(new ServletHolder(defaultServlet), "/");
|
||||
defaultServlet.getResourceService().setHttpContentFactory(path -> new ResourceHttpContent(memResource, "text/plain"));
|
||||
|
@ -3527,7 +3527,7 @@ public class DefaultServletTest
|
|||
@Test
|
||||
public void testMemoryResourceMultipleRangesUsingBufferedHttpContent() throws Exception
|
||||
{
|
||||
Resource memResource = ResourceFactory.root().newMemoryResource(getClass().getResource("/contextResources/test.txt"));
|
||||
Resource memResource = ResourceFactory.of(context).newMemoryResource(getClass().getResource("/contextResources/test.txt"));
|
||||
DefaultServlet defaultServlet = new DefaultServlet();
|
||||
context.addServlet(new ServletHolder(defaultServlet), "/");
|
||||
defaultServlet.getResourceService().setHttpContentFactory(path -> new ResourceHttpContent(memResource, "text/plain")
|
||||
|
@ -3560,7 +3560,7 @@ public class DefaultServletTest
|
|||
@Test
|
||||
public void testNotAcceptRanges() throws Exception
|
||||
{
|
||||
Resource memResource = ResourceFactory.root().newMemoryResource(getClass().getResource("/contextResources/test.txt"));
|
||||
Resource memResource = ResourceFactory.of(context).newMemoryResource(getClass().getResource("/contextResources/test.txt"));
|
||||
DefaultServlet defaultServlet = new DefaultServlet();
|
||||
context.addServlet(new ServletHolder(defaultServlet), "/");
|
||||
defaultServlet.getResourceService().setHttpContentFactory(path -> new ResourceHttpContent(memResource, "text/plain"));
|
||||
|
|
|
@ -123,7 +123,7 @@ public class DefaultServletTest
|
|||
URLClassLoader extraClassLoader = new URLClassLoader(urls, parentClassLoader);
|
||||
|
||||
context = new ServletContextHandler();
|
||||
context.setBaseResource(ResourceFactory.root().newResource(docRoot));
|
||||
context.setBaseResource(ResourceFactory.of(context).newResource(docRoot));
|
||||
context.setContextPath("/context");
|
||||
context.setWelcomeFiles(new String[]{"index.html", "index.jsp", "index.htm"});
|
||||
context.setClassLoader(extraClassLoader);
|
||||
|
@ -2275,7 +2275,7 @@ public class DefaultServletTest
|
|||
@Test
|
||||
public void testMemoryResourceRange() throws Exception
|
||||
{
|
||||
Resource memResource = ResourceFactory.root().newMemoryResource(getClass().getResource("/contextResources/test.txt"));
|
||||
Resource memResource = ResourceFactory.of(context).newMemoryResource(getClass().getResource("/contextResources/test.txt"));
|
||||
ResourceService resourceService = new ResourceService();
|
||||
resourceService.setHttpContentFactory(path -> new ResourceHttpContent(memResource, "text/plain"));
|
||||
DefaultServlet defaultServlet = new DefaultServlet(resourceService);
|
||||
|
@ -2297,7 +2297,7 @@ public class DefaultServletTest
|
|||
@Test
|
||||
public void testMemoryResourceMultipleRanges() throws Exception
|
||||
{
|
||||
Resource memResource = ResourceFactory.root().newMemoryResource(getClass().getResource("/contextResources/test.txt"));
|
||||
Resource memResource = ResourceFactory.of(context).newMemoryResource(getClass().getResource("/contextResources/test.txt"));
|
||||
ResourceService resourceService = new ResourceService();
|
||||
resourceService.setHttpContentFactory(path -> new ResourceHttpContent(memResource, "text/plain"));
|
||||
DefaultServlet defaultServlet = new DefaultServlet(resourceService);
|
||||
|
@ -2322,7 +2322,7 @@ public class DefaultServletTest
|
|||
@Test
|
||||
public void testMemoryResourceRangeUsingBufferedHttpContent() throws Exception
|
||||
{
|
||||
Resource memResource = ResourceFactory.root().newMemoryResource(getClass().getResource("/contextResources/test.txt"));
|
||||
Resource memResource = ResourceFactory.of(context).newMemoryResource(getClass().getResource("/contextResources/test.txt"));
|
||||
ResourceService resourceService = new ResourceService();
|
||||
resourceService.setHttpContentFactory(path -> new ResourceHttpContent(memResource, "text/plain")
|
||||
{
|
||||
|
@ -2353,7 +2353,7 @@ public class DefaultServletTest
|
|||
@Test
|
||||
public void testMemoryResourceMultipleRangesUsingBufferedHttpContent() throws Exception
|
||||
{
|
||||
Resource memResource = ResourceFactory.root().newMemoryResource(getClass().getResource("/contextResources/test.txt"));
|
||||
Resource memResource = ResourceFactory.of(context).newMemoryResource(getClass().getResource("/contextResources/test.txt"));
|
||||
ResourceService resourceService = new ResourceService();
|
||||
resourceService.setHttpContentFactory(path -> new ResourceHttpContent(memResource, "text/plain")
|
||||
{
|
||||
|
@ -2387,7 +2387,7 @@ public class DefaultServletTest
|
|||
@Test
|
||||
public void testNotAcceptRanges() throws Exception
|
||||
{
|
||||
Resource memResource = ResourceFactory.root().newMemoryResource(getClass().getResource("/contextResources/test.txt"));
|
||||
Resource memResource = ResourceFactory.of(context).newMemoryResource(getClass().getResource("/contextResources/test.txt"));
|
||||
ResourceService resourceService = new ResourceService();
|
||||
resourceService.setHttpContentFactory(path -> new ResourceHttpContent(memResource, "text/plain"));
|
||||
resourceService.setAcceptRanges(false);
|
||||
|
|
Loading…
Reference in New Issue