English 中文(简体)
1. Java Sonaty Async HTTP客户
原标题:Java Sonatype Async HTTP Client Upload Progress

我正试图以星号为用户——上的进展。

I tried the method suggested in the docs. Using transfer listener. http://sonatype.github.com/async-http-client/transfer-listener.html

我在转让生活器接口(如测试)上实施:

public void onBytesSent(ByteBuffer byteBuffer) {

     System.out.println("Total bytes sent - ");
     System.out.println(byteBuffer.capacity());
}

然后,在另一条read子里(因为我不想阻止 app) 我努力做到以下几点:

TransferCompletionHandler tl = new TransferCompletionHandler();
tl.addTransferListener(listener);

asyncHttpClient.preparePut(getFullUrl(fileWithPath))
      .setBody(new BodyGenerator() {
           public Body createBody() throws IOException {
                return new FileBodyWithOffset(file, offset);
           }
       })
       .addHeader(CONTENT_RANGE, new ContentRange(offset, localSize).toString())
       .execute(handler).get();

一切都属于罚款。 文档是正确和快捷的。 但是,问题在于——我正在从《转让守则》中获取信息。 载荷只有AFTER。 装上载10分钟。 在这10分钟内,我拿不到任何东西。 只有在这之后,所有文件都印在圣殿上。

我可以指出这一法典有什么错误。 我只是想照一下。

我试图在主线上执行上述法典,并且也没有工作。

利用这一客户执行上载进度听众,这是否是错误的?

最佳回答

我将回答这个问题。 我无法与Liberstener公司解决这一问题。 因此,我尝试了另一种方式。

我将进度逻辑放在了机构接口(读法中):

public class FileBodyWithOffset implements Body {

    private final ReadableByteChannel channel;

    private long actualOffset;

    private final long contentLength;

    public FileBodyWithOffset(final File file, final long offset) throws IOException {

        final InputStream stream = new FileInputStream(file);

        this.actualOffset = stream.skip(offset);

        this.contentLength = file.length() - offset;

        this.channel = Channels.newChannel(stream);
    }


    public long getContentLength() {

        return this.contentLength;
    }

    public long read(ByteBuffer byteBuffer) throws IOException {

        System.out.println(new Date());

        actualOffset += byteBuffer.capacity();

        return channel.read(byteBuffer);
    }

    public void close() throws IOException {

        channel.close();
    }

    public long getActualOffset() {

        return actualOffset;
    }
}

也许它是一种 d脏的骗子,但至少是行之有效的。

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签