使用tomcat下载扩展时出现问题

k7fdbhmy  于 2021-07-03  发布在  Java
关注(0)|答案(0)|浏览(187)
static void copyStream(final InputStream inputStream, final OutputStream outputStream, final Client client) throws IOException {

    if (client.getReqType() == ReqType.STREAMING_PARTIAL || client.getRange() != null) {
        copyPartialStream(inputStream, outputStream, client);
        return;
    }

    Site site = client.getSite(); 
    Qos qos = new Qos(site); 
    String siteId = site.getSiteId();

    byte[] buff = new byte[BUFF_SIZE]; // 1024*32
    int readBytes = 0; 

    try (BufferedInputStream is = new BufferedInputStream(inputStream, BUFF_SIZE)) { 
        try (BufferedOutputStream out = new BufferedOutputStream(outputStream, BUFF_SIZE)) {
            while ((readBytes = is.read(buff)) > -1) { 
                long startChunk = System.currentTimeMillis();

                out.write(buff, 0, readBytes);
                client.addSendSize(readBytes);
                KHttp.increaseTrafficLog(siteId, readBytes);

                long elapsedChunk = System.currentTimeMillis() - startChunk;
                client.addSendMils(elapsedChunk);

                if (qos.pause(client)) {
                    long sleepMillis = qos.getSleepMillis(client, readBytes, elapsedChunk);
                    if (sleepMillis > 0) {
                        qos.sleep(sleepMillis);
                        client.addSendMils(sleepMillis);
                    }
                }
            }
        }
    } catch (IOException e) {
        client.setAbort(true);
    }
}

我正在看一段代码,它提供了一个使用tomcat接收文件的链接。但是,如果附加了扩展名,则会发生错误。不是所有的扩展,但只有当连接mp3扩展时,才会正常下载,当连接其他扩展时,才会发生错误。即使没有扩展,它也能工作。我认为这个代码有问题。我希望你能告诉我是否有任何代码有错误(

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题