3

有没有一种标准的方法来实现使用 Apache HttpClient 4.x 的可恢复文件上传?我试图覆盖FileBody中的writeTo方法

@Override
public void writeTo(final OutputStream out) throws IOException {
     if (out == null) {
            throw new IllegalArgumentException("Output stream may not be null");
     }

     BufferedInputStream stream = new BufferedInputStream(new FileInputStream(this.file));

     if(pos > 0){
        stream.skip(pos);
     }

刚才我想到可能我需要覆盖getContentLength方法

public long getContentLength() {
    return this.file.length() - pos;
}

或者,也许我可以这样做:

BufferedInputStream stream = new BufferedInputStream(new FileInputStream(file));
if(pos > 0){
   stream.skip(pos);
}
new InputStreamEntity(stream , file.getSize()-pos);

有人有建议吗?

4

0 回答 0