簡體   English   中英

BufferedInputStream讀取與IOUtils toByteArray

[英]BufferedInputStream read vs IOUtils toByteArray

我最近嘗試從inputStream讀取數據。

int length = getHeader("Content-Length");
byte[] buffer = new byte [length];    
BufferedInputStream stream = new BufferedInputStream (servletRequest.getInputStream());    
stream.read(buffer);

它以某種方式截斷了我的數據。 當我嘗試跟隨

buffer = IOUtils.toByteArray(servletRequest.getInputStream());

效果很好。

誰能給我關於可能是什么問題的見解?

@Gaurav_Joshi

帶有一個參數InputStream的BufferedInputStream構造函數使用DEFAULT_BUFFER_SIZE,它可能小於輸入流的實際大小。

public BufferedInputStream(InputStream in) {
    this(in, DEFAULT_BUFFER_SIZE);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM