所以,如何在JavaScript中动态地从http响应中链接字节流块?
我想发送一个字节流到浏览器(例如PDF),以便他可以显示给用户。
if (bytesToRead == -1) {
bytesToRead = (int)fullPathFile.length();}
byte[] buffer = new byte[bytesToRead];
int bytesRead = -1;
if((inputFileInputStream != null) && ((bytesRead = inputFileInputStream.read(buffer)) != -1)){
if (codec.equals("base64")) {
String streamLength = Base64.encodeBytes(buffer, 0, bytesToRead);
response.setContentLength(streamLength.length());
outputFileOutputStream.write(Base64.encodeBytes(buffer, 0, bytesToRead).getBytes());
} else {
outputFileOutputStream.write(buffer, 0, bytesToRead);
}
}
inputFileInputStream.close();
outputFileOutputStream.flush();
outputFileOutputStream.close();
目前它与选项-1一起工作得到一个字节的字节流,但我想发送2kb让我们说。我明白,为此我需要发送多个2kb的回复,我必须在javascript代码中连接它们。但是,我该怎么做?
什么是JavaScript?这是java代码。 – Stultuske 2015-03-13 12:53:31
为什么当浏览器已经具备了这个功能时,你使用javascript来消费PDF的回应? – MadConan 2015-03-13 12:53:40
@Stultuske:这是java代码,但我询问有关JavaScript的实现。 – 2015-03-13 12:54:51