Hi Oleg, Mike,

Thanks a lot for your reponse. I think I got the basic idea about your suggestion, but 
more questions :-)

1. I'm actually using putmethod, not postmethod, but I assume your suggest applies to 
putmethod too, is it correct?

2. Since my "put" will put (upload) a local file onto server, so I think 
ProgressInputStream will take a FileInputStream as parameter in its constructor, is it 
right?

3. The callListeners in ProgressInputStream has following line:
            this.listeners.callListeners( new ProgressEvent( this, this.current, 
this.total ) );
did you mean:
            this.listeners.invokeListeners?

Thanks,
Yong Chen

-----Original Message-----
From: Kalnichevski, Oleg [mailto:[EMAIL PROTECTED]
Sent: Tuesday, November 11, 2003 12:46 AM
To: Commons HttpClient Project
Subject: RE: file upload (PUT method) progress report


Yong,
You should be using PostMethod.setRequestBody(InputStream) method to provide the 
request content body (as Mike pointed out) and wrap the source InputStream with a 
FilterInputStream. Exactly what you choose to do in the FilterInputStream is up to 
you. One possibility is to file events containing progress details. Here's a code 
snippet that should give you a pointer in that direction. Hope this helps

Oleg


==============================================================================

import java.util.EventObject;

public class ProgressEvent extends EventObject {

    private int current;    
    private int total;    
                
        public ProgressEvent( Object source, int current, int total ) {
        super( source );
        this.current = current;
        this.total = total;
        }
    
    public int getCurrent()
    {
        return this.current;
    }
    
    
    public int getTotal()
    {
        return this.total;
    }
    
}
==============================================================================
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import xxx.ProgressEvent; 
import xxx.ProgressListenerList; 

public class ProgressInputStream extends FilterInputStream
{
    private ProgressListenerList listeners = null;
    private int current;
    private int total;

        public ProgressInputStream( InputStream in, ProgressListenerList listeners, 
int total )
        {
        super( in );
        this.listeners = listeners;
        this.current = 0;
        this.total = total;
        }
        
        public int read(byte[] b, int off, int len) throws IOException
        {
                int result = super.read(b, off, len);
        if ( result != -1 )
        {
            this.current += result;
            callListeners();            
        }
        return result;
        }

        public int read(byte[] b) throws IOException
        {
                int result = super.read(b);
        if ( result != -1 )
        {
            this.current += result;
            callListeners();            
        }
        return result;
        }

    private void callListeners()
    {
        if ( this.listeners != null )
        {
            this.listeners.callListeners( new ProgressEvent( this, this.current, 
this.total ) );
        }
    }
}
==============================================================================

import java.util.EventListener;

public interface ProgressListener extends EventListener
{
    public void progressNotification( ProgressEvent event );
}

==============================================================================

import java.util.Vector; 

public class ProgressListenerList {

    // I have to use Vector here because of Java 1.1.8 compatibiliy requirements
    private Vector v = null;


    public ProgressListenerList()
    {
       super();
    }


    public synchronized void addListner( ProgressListener listnener )
    {
        if ( listnener == null )
        {
            return;
        }
        if ( this.v == null )
        {
            this.v = new Vector( 1 );
        }
        int i = this.v.indexOf( listnener );
        if ( i == -1 )
        {
            this.v.addElement( listnener );
        }       
    }


    public synchronized void removeListner( ProgressListener listnener )
    {
        if ( listnener == null )
        {
            return;
        }
        if ( this.v == null )
        {
            return;
        }
        int i = this.v.indexOf( listnener );
        if ( i != -1 )
        {
            this.v.removeElementAt( i );
        }       
        if ( this.v.size() == 0 )
        {
            this.v = null;
        }
    }


    public synchronized void clear()
    {
        if ( this.v != null )
        {
            this.v.removeAllElements();
            this.v = null;
        }
    }


    public synchronized void invokeListeners( ProgressEvent event )
    {
        if ( this.v == null )
        {
            return;
        }
        for ( int i = 0; i < this.v.size(); i++ )
        {
            ( ( ProgressListener )this.v.elementAt( i ) ).progressNotification( event 
);
        }
    }

    public synchronized int size()
    {
        if ( this.v == null )
        {
            return 0;
        }
        else
        {
            return this.v.size();
        }
    }

}
==============================================================================

-----Original Message-----
From: Yong Chen [mailto:[EMAIL PROTECTED]
Sent: Tuesday, November 11, 2003 01:03
To: [EMAIL PROTECTED]
Subject: file upload (PUT method) progress report




Hi,

I'm using putmethod to put (large size) file on server. After calling executeMethod(), 
I want to know the progress or the percentage of file uploaded so I can report it to 
UI.

1. Is there any to do it now?
2. If not, are there any plans for adding it to the future release?

Thanks,
Yong Chen

SPECIAL NOTICE 

All information transmitted hereby is intended only for the use of the 
addressee(s) named  above and may contain confidential and privileged 
information. Any unauthorized  review, use, disclosure or distribution
of confidential and privileged information is prohibited. If the reader of
this message is not the intended recipient(s) or the employee or agent 
responsible for delivering the message to the intended recipient, you
are herby notified that you must not read this transmission and that
disclosure, copying, printing, distribution or use of any of the
information contained in or attached to this transmission is STRICTLY 
PROHIBITED.

Anyone who receives confidential and privileged information in error should 
notify us immediately by telephone and mail the original message to us at the
above address and destroy all copies.  To the extent any portion of this
communication contains public information, no such restrictions 
apply to that information. (gate01)

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to