我正在尝试实现一个从url读取InputStream的servlet。 输入流的内容类型是video / mp4。
现在,我希望将包含mp4视频的InputStream提供给iOS设备。 我跟随了Bauke Scholtz的article执行类似的任务,它从File对象中读取内容。 我按照这篇文章进行了一些更改以实现我的方案。
我在问题中添加了更多细节。
我试图通过对Bauke Scholtz的代码进行细微修改来测试我的场景。 我的servlet首先使用
从URL中读取内容URLConnection openConnection = url.openConnection();
然后我重写他的copy()函数,如下所示:
private static void copy(URLConnection openConnection, OutputStream output,
long start, long length) throws IOException {
InputStream input = openConnection.getInputStream();
byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
int read;
if (openConnection.getContentLength() == length) {
while ((read = input.read(buffer)) > 0) {
output.write(buffer, 0, read);
}
} else {
input.skip(start);
long toRead = length;
while ((read = input.read(buffer)) > 0) {
if ((toRead -= read) > 0) {
output.write(buffer, 0, read);
} else {
output.write(buffer, 0, (int) toRead + read);
break;
}
}
}
}
我使用了这个复制功能而不是原始功能。
但我无法实现我的目标。 任何经历过相同或熟悉解决方案的人都请分享您的想法。
谢谢,
Vaibhav Gupta。
P.S。对于原始问题中提供的较少信息,我深表歉意。我是stackoverflow的新手,它需要一些时间和学习来适应它的文化。