package greenfoot.export.mygame;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.http.entity.mime.FormBodyPart;
import org.apache.http.entity.mime.content.FileBody;
| A FormBodyPart which tracks upload progress.
|
| @author Davin McCall
|
public class ProgressTrackingPart
extends FormBodyPart{
public ProgressTrackingPart(String partName, File file, MyGameClient listener)
throws FileNotFoundException
{
super(partName, new ProgressTrackingFileBody(file, listener));
}
private static class ProgressTrackingFileBody
extends FileBody
{
private MyGameClient listener;
public ProgressTrackingFileBody(File file, MyGameClient listener)
{
super(file);
this.listener = listener;
}
@Override
public void writeTo(OutputStream output) throws IOException
{
if (getContentLength() == 0) {
return;
}
byte [] buf = new byte[4096];
InputStream istream = getInputStream();
try {
int len = istream.read(buf);
while (len != -1){
output.write(buf, 0, len);
listener.progress(len);
len = istream.read(buf);
}
}
finally {
istream.close();
}
}
}
}
top,
use,
map,
class ProgressTrackingPart
. ProgressTrackingPart
top,
use,
map,
class ProgressTrackingPart . ProgressTrackingFileBody
. ProgressTrackingFileBody
. writeTo
64 neLoCode
+ 2 LoComm