AnilJ
AnilJ

Reputation: 2121

HTTP response attachment download complete notification

In LittleProxy implementation, is there a feature where we can get a notification of the completion of the file download?

Currently I am using below code to save the attachment to the HTTP response message. I am not sure if this chanBuff.getBytes(...) a blocking call or non-blocking.

ChannelBuffer chanBuff = response.getContent();
FileOutputStream outputStream = new FileOutputStream(outputFileName);
chanBuff.getBytes(0, outputStream, chanBuff.readableBytes());
outputStream.close();

When I try to process the saved file right after this code, it throws an exception. If I wait till file is completely downloaded and saved on disk, perhaps the problem might get solved automatically.

java.io.IOException: Channel not open for writing - cannot extend file to required size
    at sun.nio.ch.FileChannelImpl.map(Unknown Source)
    at com.googlecode.mp4parser.AbstractBox.parse(AbstractBox.java:109)
    at com.coremedia.iso.AbstractBoxParser.parseBox(AbstractBoxParser.java:118)
    at com.coremedia.iso.IsoFile.parse(IsoFile.java:85)
    at com.coremedia.iso.IsoFile.<init>(IsoFile.java:54)
    at org.media.processor.LibraryImpl.printFileDetails(LibraryImpl.java:529)

Upvotes: 0

Views: 558

Answers (1)

Jian Jin
Jian Jin

Reputation: 236

ChannelBuffer is just encapsulation around byte[].

chanBuff.getBytes(0, outputStream, chanBuff.readableBytes()) will invoke outputStream.write(byte[], begin, length).

So before you write the content, you should first allocate a corrent length bytes in ChannelBuffer.

Upvotes: 1

Related Questions