Skip to content
Snippets Groups Projects
Commit 8438fe76 authored by srosse's avatar srosse
Browse files

OO-4627: respect preferred buffer size to deliver ranged content (video)

parent 9bf3013e
No related branches found
No related tags found
No related merge requests found
...@@ -229,7 +229,9 @@ public class IFrameDeliveryMapper implements Mapper { ...@@ -229,7 +229,9 @@ public class IFrameDeliveryMapper implements Mapper {
String containerPath = path.substring(0, lastSlash); String containerPath = path.substring(0, lastSlash);
String filename = path.substring(lastSlash + 1); String filename = path.substring(lastSlash + 1);
VFSItem parentItem = rootDir.resolve(containerPath); VFSItem parentItem = rootDir.resolve(containerPath);
items = ((VFSContainer)parentItem).getItems(new ByNameCaseInsensitive(filename)); if(parentItem != null) {
items = ((VFSContainer)parentItem).getItems(new ByNameCaseInsensitive(filename));
}
} else { } else {
items = ((VFSContainer)rootDir).getItems(new ByNameCaseInsensitive(path)); items = ((VFSContainer)rootDir).getItems(new ByNameCaseInsensitive(path));
} }
......
...@@ -210,12 +210,9 @@ public class ServletUtil { ...@@ -210,12 +210,9 @@ public class ServletUtil {
httpResp.setHeader("content-length", "" + length); httpResp.setHeader("content-length", "" + length);
} }
httpResp.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT); httpResp.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
try {
httpResp.setBufferSize(2048); int bufferSize = httpResp.getBufferSize();
} catch (IllegalStateException e) { copy(out, in, range, bufferSize);
// Silent catch
}
copy(out, in, range);
} else { } else {
if (size != null) { if (size != null) {
httpResp.setContentLengthLong(size.longValue()); httpResp.setContentLengthLong(size.longValue());
...@@ -247,12 +244,12 @@ public class ServletUtil { ...@@ -247,12 +244,12 @@ public class ServletUtil {
} }
} }
//fxdiff FXOLAT-118: accept range to deliver videos for iPad protected static void copy(OutputStream ostream, InputStream resourceInputStream, Range range, int bufferSize) throws IOException {
protected static void copy(OutputStream ostream, InputStream resourceInputStream, Range range) throws IOException {
IOException exception = null; IOException exception = null;
InputStream istream = new BufferedInputStream(resourceInputStream, 2048); InputStream istream = (resourceInputStream instanceof BufferedInputStream)
exception = copyRange(istream, ostream, range.start, range.end); ? resourceInputStream : new BufferedInputStream(resourceInputStream, bufferSize);
exception = copyRange(istream, ostream, range.start, range.end, bufferSize);
// Clean up the input stream // Clean up the input stream
istream.close(); istream.close();
...@@ -261,8 +258,7 @@ public class ServletUtil { ...@@ -261,8 +258,7 @@ public class ServletUtil {
if (exception != null) throw exception; if (exception != null) throw exception;
} }
//fxdiff FXOLAT-118: accept range to deliver videos for iPad protected static IOException copyRange(InputStream istream, OutputStream ostream, long start, long end, int bufferSize) {
protected static IOException copyRange(InputStream istream, OutputStream ostream, long start, long end) {
try { try {
istream.skip(start); istream.skip(start);
} catch (IOException e) { } catch (IOException e) {
...@@ -272,7 +268,7 @@ public class ServletUtil { ...@@ -272,7 +268,7 @@ public class ServletUtil {
IOException exception = null; IOException exception = null;
long bytesToRead = end - start + 1; long bytesToRead = end - start + 1;
byte buffer[] = new byte[2048]; byte[] buffer = new byte[bufferSize];
int len = buffer.length; int len = buffer.length;
while ((bytesToRead > 0) && (len >= buffer.length)) { while ((bytesToRead > 0) && (len >= buffer.length)) {
try { try {
...@@ -294,7 +290,6 @@ public class ServletUtil { ...@@ -294,7 +290,6 @@ public class ServletUtil {
return exception; return exception;
} }
//fxdiff FXOLAT-118: accept range to deliver videos for iPad
protected static List<Range> parseRange(HttpServletRequest request, HttpServletResponse response, long lastModified, long fileLength) protected static List<Range> parseRange(HttpServletRequest request, HttpServletResponse response, long lastModified, long fileLength)
throws IOException { throws IOException {
...@@ -580,7 +575,6 @@ public class ServletUtil { ...@@ -580,7 +575,6 @@ public class ServletUtil {
setNoCacheHeaders(response); setNoCacheHeaders(response);
} else { } else {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
//res being the HttpServletResponse of the request
response.addHeader("Cache-Control", "max-age=" + duration); response.addHeader("Cache-Control", "max-age=" + duration);
response.setDateHeader("Expires", now + duration); response.setDateHeader("Expires", now + duration);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment