<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: WebDav Client in Java</title>
	<atom:link href="http://indiwiz.com/2009/02/11/webdav-client-in-java/feed/" rel="self" type="application/rss+xml" />
	<link>http://indiwiz.com/2009/02/11/webdav-client-in-java/</link>
	<description>Subhash&#039;s Tech Log</description>
	<lastBuildDate>Fri, 30 Mar 2012 07:23:11 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: svr</title>
		<link>http://indiwiz.com/2009/02/11/webdav-client-in-java/comment-page-1/#comment-6426</link>
		<dc:creator>svr</dc:creator>
		<pubDate>Fri, 30 Mar 2012 07:23:11 +0000</pubDate>
		<guid isPermaLink="false">http://indiwiz.com/?p=199#comment-6426</guid>
		<description>Hi,

Using the above code I am able to upload Files to WEBDAV server.I need to upload the folders and files . How  to upload folders and files under folders.Could you please help.

one more question how to download folders and files from WEBDAV server to local File system.</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>Using the above code I am able to upload Files to WEBDAV server.I need to upload the folders and files . How  to upload folders and files under folders.Could you please help.</p>
<p>one more question how to download folders and files from WEBDAV server to local File system.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: German</title>
		<link>http://indiwiz.com/2009/02/11/webdav-client-in-java/comment-page-1/#comment-463</link>
		<dc:creator>German</dc:creator>
		<pubDate>Thu, 22 Jul 2010 16:19:13 +0000</pubDate>
		<guid isPermaLink="false">http://indiwiz.com/?p=199#comment-463</guid>
		<description>Hello, how can we create a filedownload with jackrabbit??</description>
		<content:encoded><![CDATA[<p>Hello, how can we create a filedownload with jackrabbit??</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Parvez Ahmad Hakim</title>
		<link>http://indiwiz.com/2009/02/11/webdav-client-in-java/comment-page-1/#comment-394</link>
		<dc:creator>Parvez Ahmad Hakim</dc:creator>
		<pubDate>Wed, 16 Jun 2010 15:36:27 +0000</pubDate>
		<guid isPermaLink="false">http://indiwiz.com/?p=199#comment-394</guid>
		<description>How to add progress bar to it for download. Can you put the entire buffer based approach using progress bar.
I used other way, but can&#039;t prevent double calling of uploadFile method..
 
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.net.URLConnection;
import org.apache.commons.httpclient.methods.RequestEntity;  
import org.apache.jackrabbit.webdav.client.methods.PutMethod;
import org.cord.client.shared.fileship.constants.FileshipConstants;
import org.eclipse.core.runtime.IProgressMonitor;  
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.swt.widgets.Display;
 
public class FileUploadRequestEntity implements RequestEntity { 
	public String remotePath;
	public String relativePath;
    private File file = null; 
    PutMethod putMethod;
    public FileUploadRequestEntity(String s_relativePath,String s_RemotePath, String localFileName){
        super();
        this.file = new File(localFileName);  
        this.relativePath =s_relativePath; 
        this.remotePath =s_RemotePath; 
    } 
     
    public String getContentType() {
    	String mimeType = URLConnection.guessContentTypeFromName(file.getName());

		if (mimeType == null) {
			mimeType = &quot;application/octet-stream&quot;;
		}
		return mimeType;
        //return &quot;text/plain; charset=UTF-8&quot;;
    }
    /**
     * writeRequest gets executed for every upload..
     * means when the HTTP client executes put method, below method actually passes
     * the data to server
     */
    public void writeRequest( OutputStream out) throws IOException {
    	try {
			uploadFile(out);
			
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		} catch (InterruptedException e) { 
			e.printStackTrace();
		} 
    }
     
     void uploadFile( final OutputStream out) throws IOException, InvocationTargetException, InterruptedException { 
     	final Display display = new Display();// this statement may throw error, since we do not know the activeshell and we need it below
		ProgressMonitorDialog dialog = new ProgressMonitorDialog(display.getActiveShell());
		final int fileSize = getFileSize(); 
		final MD5 md5 = new MD5(); // for hash 
		dialog.run(true, true, new IRunnableWithProgress() { 
			@Override
			public void run(IProgressMonitor monitor) { 
		        monitor.beginTask(&quot;Upload status ...&quot;, fileSize);// note very large size may return more length .. need to see that    	        
		        InputStream fsInput;
        	   try { 
        		   fsInput = new FileInputStream(file);
        		   int data;
                    byte[] buffer = new byte[1024]; 
                    long kbTransfered = 0;// number of kb transferred in 1 go 
                    
					while ((data = fsInput.read(buffer)) != -1) {
						if(monitor.isCanceled()) {
				                monitor.done();
				                return;
				        }
						++kbTransfered;
						monitor.subTask(getStatusMessage(kbTransfered));
					    out.write(buffer, 0, data);
					    monitor.worked(1); 
					    md5.update(buffer, data);
					}
					
					// adding hash value to uploaded file on jackrabbit server
					fsInput.close(); 
					out.flush(); /// very important  
					
					monitor.subTask(&quot;File uploaded successfully. Generating Hash&quot;);
					WebDavEngine  engine = WebDavEngine.getInstance();
					String s_FileHash = md5.getHashString();
					monitor.subTask(&quot;File uploaded successfully. Now updating hash on server&quot;);
					//engine.addProperties(relativePath, FileshipConstants.FILE_HASH_Key, s_FileHash); 
					System.out.println(&quot;File transferred successfully&quot;);
            } catch (Exception e) { 
            	e.printStackTrace(); 
            }finally{ 
            	monitor.done();
            	}
            }
		}); 
		if (display!=null)display.dispose();
    }
    

    public long getContentLength() {
        return file.length();
    }

    // Handy methods that have no relation(or not required) for the methods to be implemented while subclassing RequestEntity
    /*************************     
     */
     int getFileSize() {
        return (int) (file.length()/1024);// in KB
    }
    
    private void sleep(Integer waitTime) {
    	try {
    		Thread.sleep(waitTime);
    	} catch (Throwable t) {
    		System.out.println(&quot;Wait time interrupted&quot;);
    	}
    }
    String getStatusMessage(long kbTransfered){
    	long bytesTransfered = kbTransfered* 1024;
    	long totalBytes = getContentLength();
    	int percentUploaded = 0;
    	if(totalBytes&gt;0){
    		percentUploaded = (int) (bytesTransfered * 100/ totalBytes); 
    	}
    	
    	return &quot;Bytes uploaded: &quot;+ bytesTransfered +&quot;  (&quot; +percentUploaded + &quot;%).    Total Bytes : &quot; + totalBytes + 
    	&quot;          Remaining: &quot; +(totalBytes - bytesTransfered) + &quot; Bytes&quot; ; 
    }

	@Override
	public boolean isRepeatable() {
		// TODO Auto-generated method stub
		return true;
	}
    
    // add more ...
    
    /*************************     
     */ 
}

Parvez Ahmad Hakim
Srinagar Kashmir India</description>
		<content:encoded><![CDATA[<p>How to add progress bar to it for download. Can you put the entire buffer based approach using progress bar.<br />
I used other way, but can&#8217;t prevent double calling of uploadFile method..</p>
<p>import java.io.File;<br />
import java.io.FileInputStream;<br />
import java.io.IOException;<br />
import java.io.InputStream;<br />
import java.io.OutputStream;<br />
import java.lang.reflect.InvocationTargetException;<br />
import java.net.URLConnection;<br />
import org.apache.commons.httpclient.methods.RequestEntity;<br />
import org.apache.jackrabbit.webdav.client.methods.PutMethod;<br />
import org.cord.client.shared.fileship.constants.FileshipConstants;<br />
import org.eclipse.core.runtime.IProgressMonitor;<br />
import org.eclipse.jface.dialogs.ProgressMonitorDialog;<br />
import org.eclipse.jface.operation.IRunnableWithProgress;<br />
import org.eclipse.swt.widgets.Display;</p>
<p>public class FileUploadRequestEntity implements RequestEntity {<br />
	public String remotePath;<br />
	public String relativePath;<br />
    private File file = null;<br />
    PutMethod putMethod;<br />
    public FileUploadRequestEntity(String s_relativePath,String s_RemotePath, String localFileName){<br />
        super();<br />
        this.file = new File(localFileName);<br />
        this.relativePath =s_relativePath;<br />
        this.remotePath =s_RemotePath;<br />
    } </p>
<p>    public String getContentType() {<br />
    	String mimeType = URLConnection.guessContentTypeFromName(file.getName());</p>
<p>		if (mimeType == null) {<br />
			mimeType = &#8220;application/octet-stream&#8221;;<br />
		}<br />
		return mimeType;<br />
        //return &#8220;text/plain; charset=UTF-8&#8243;;<br />
    }<br />
    /**<br />
     * writeRequest gets executed for every upload..<br />
     * means when the HTTP client executes put method, below method actually passes<br />
     * the data to server<br />
     */<br />
    public void writeRequest( OutputStream out) throws IOException {<br />
    	try {<br />
			uploadFile(out);</p>
<p>		} catch (InvocationTargetException e) {<br />
			e.printStackTrace();<br />
		} catch (InterruptedException e) {<br />
			e.printStackTrace();<br />
		}<br />
    }</p>
<p>     void uploadFile( final OutputStream out) throws IOException, InvocationTargetException, InterruptedException {<br />
     	final Display display = new Display();// this statement may throw error, since we do not know the activeshell and we need it below<br />
		ProgressMonitorDialog dialog = new ProgressMonitorDialog(display.getActiveShell());<br />
		final int fileSize = getFileSize();<br />
		final MD5 md5 = new MD5(); // for hash<br />
		dialog.run(true, true, new IRunnableWithProgress() {<br />
			@Override<br />
			public void run(IProgressMonitor monitor) {<br />
		        monitor.beginTask(&#8220;Upload status &#8230;&#8221;, fileSize);// note very large size may return more length .. need to see that<br />
		        InputStream fsInput;<br />
        	   try {<br />
        		   fsInput = new FileInputStream(file);<br />
        		   int data;<br />
                    byte[] buffer = new byte[1024];<br />
                    long kbTransfered = 0;// number of kb transferred in 1 go </p>
<p>					while ((data = fsInput.read(buffer)) != -1) {<br />
						if(monitor.isCanceled()) {<br />
				                monitor.done();<br />
				                return;<br />
				        }<br />
						++kbTransfered;<br />
						monitor.subTask(getStatusMessage(kbTransfered));<br />
					    out.write(buffer, 0, data);<br />
					    monitor.worked(1);<br />
					    md5.update(buffer, data);<br />
					}</p>
<p>					// adding hash value to uploaded file on jackrabbit server<br />
					fsInput.close();<br />
					out.flush(); /// very important  </p>
<p>					monitor.subTask(&#8220;File uploaded successfully. Generating Hash&#8221;);<br />
					WebDavEngine  engine = WebDavEngine.getInstance();<br />
					String s_FileHash = md5.getHashString();<br />
					monitor.subTask(&#8220;File uploaded successfully. Now updating hash on server&#8221;);<br />
					//engine.addProperties(relativePath, FileshipConstants.FILE_HASH_Key, s_FileHash);<br />
					System.out.println(&#8220;File transferred successfully&#8221;);<br />
            } catch (Exception e) {<br />
            	e.printStackTrace();<br />
            }finally{<br />
            	monitor.done();<br />
            	}<br />
            }<br />
		});<br />
		if (display!=null)display.dispose();<br />
    }</p>
<p>    public long getContentLength() {<br />
        return file.length();<br />
    }</p>
<p>    // Handy methods that have no relation(or not required) for the methods to be implemented while subclassing RequestEntity<br />
    /*************************<br />
     */<br />
     int getFileSize() {<br />
        return (int) (file.length()/1024);// in KB<br />
    }</p>
<p>    private void sleep(Integer waitTime) {<br />
    	try {<br />
    		Thread.sleep(waitTime);<br />
    	} catch (Throwable t) {<br />
    		System.out.println(&#8220;Wait time interrupted&#8221;);<br />
    	}<br />
    }<br />
    String getStatusMessage(long kbTransfered){<br />
    	long bytesTransfered = kbTransfered* 1024;<br />
    	long totalBytes = getContentLength();<br />
    	int percentUploaded = 0;<br />
    	if(totalBytes&gt;0){<br />
    		percentUploaded = (int) (bytesTransfered * 100/ totalBytes);<br />
    	}</p>
<p>    	return &#8220;Bytes uploaded: &#8220;+ bytesTransfered +&#8221;  (&#8221; +percentUploaded + &#8220;%).    Total Bytes : &#8221; + totalBytes +<br />
    	&#8221;          Remaining: &#8221; +(totalBytes &#8211; bytesTransfered) + &#8221; Bytes&#8221; ;<br />
    }</p>
<p>	@Override<br />
	public boolean isRepeatable() {<br />
		// TODO Auto-generated method stub<br />
		return true;<br />
	}</p>
<p>    // add more &#8230;</p>
<p>    /*************************<br />
     */<br />
}</p>
<p>Parvez Ahmad Hakim<br />
Srinagar Kashmir India</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon Stevens</title>
		<link>http://indiwiz.com/2009/02/11/webdav-client-in-java/comment-page-1/#comment-276</link>
		<dc:creator>Jon Stevens</dc:creator>
		<pubDate>Thu, 07 Jan 2010 00:44:35 +0000</pubDate>
		<guid isPermaLink="false">http://indiwiz.com/?p=199#comment-276</guid>
		<description>I&#039;ve created a new webdav client for Java that is quite a bit easier to use than jackrabbit. Basically, I&#039;ve abstracted all the HttpClient stuff away and just expose a few easy to use methods for common use cases.

It is called sardine and lives up on google code:

http://code.google.com/p/sardine/</description>
		<content:encoded><![CDATA[<p>I&#8217;ve created a new webdav client for Java that is quite a bit easier to use than jackrabbit. Basically, I&#8217;ve abstracted all the HttpClient stuff away and just expose a few easy to use methods for common use cases.</p>
<p>It is called sardine and lives up on google code:</p>
<p><a href="http://code.google.com/p/sardine/" rel="nofollow">http://code.google.com/p/sardine/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dilip</title>
		<link>http://indiwiz.com/2009/02/11/webdav-client-in-java/comment-page-1/#comment-77</link>
		<dc:creator>Dilip</dc:creator>
		<pubDate>Fri, 12 Jun 2009 09:00:41 +0000</pubDate>
		<guid isPermaLink="false">http://indiwiz.com/?p=199#comment-77</guid>
		<description>Good example to upload a file. Could you please share an example to import a file also. I followed Jacakrabbit webdav wiki site and could able to get only the file list. How to get each file downloaded?</description>
		<content:encoded><![CDATA[<p>Good example to upload a file. Could you please share an example to import a file also. I followed Jacakrabbit webdav wiki site and could able to get only the file list. How to get each file downloaded?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

