org.urbanstew.soundcloudapi
Class ProgressFileBody

java.lang.Object
  extended by org.apache.james.mime4j.message.SingleBody
      extended by org.apache.http.entity.mime.content.AbstractContentBody
          extended by org.apache.http.entity.mime.content.FileBody
              extended by org.urbanstew.soundcloudapi.ProgressFileBody
All Implemented Interfaces:
org.apache.http.entity.mime.content.ContentBody, org.apache.james.mime4j.descriptor.ContentDescriptor, org.apache.james.mime4j.message.Body, org.apache.james.mime4j.message.Disposable

public class ProgressFileBody
extends org.apache.http.entity.mime.content.FileBody

This FileBody can be used to monitor the progress of a file upload.

 File file = new File("audio.wav");
  
  final List<NameValuePair> params = new java.util.ArrayList<NameValuePair>();
  params.add(new BasicNameValuePair("track[title]", "This is a test upload"));
  params.add(new BasicNameValuePair("track[sharing]", "private"));
  
  final ProgressFileBody fileBody = new ProgressFileBody(file);
  
  Thread progressThread = new Thread(new Runnable()
  {
  	public void run()
 		{
 			try
 			{
 				mApi.upload(fileBody, params);
 			} catch (Exception e)
 			{
 				e.printStackTrace();
 			}
 		}
 	});
  
  progressThread.start();
  while(progressThread.isAlive())
  	System.out.println(fileBody.getBytesTransferred());
  
 

Since:
0.9.2

Constructor Summary
ProgressFileBody(java.io.File file)
           
 
Method Summary
 long getBytesTransferred()
           
 void writeTo(java.io.OutputStream out)
           
 
Methods inherited from class org.apache.http.entity.mime.content.FileBody
getCharset, getContentLength, getFile, getFilename, getInputStream, getTransferEncoding, writeTo
 
Methods inherited from class org.apache.http.entity.mime.content.AbstractContentBody
dispose, getContentTypeParameters, getMediaType, getMimeType, getParent, getSubType, setParent
 
Methods inherited from class org.apache.james.mime4j.message.SingleBody
copy
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProgressFileBody

public ProgressFileBody(java.io.File file)
Method Detail

writeTo

public void writeTo(java.io.OutputStream out)
             throws java.io.IOException
Overrides:
writeTo in class org.apache.http.entity.mime.content.FileBody
Throws:
java.io.IOException

getBytesTransferred

public long getBytesTransferred()