Atitit webdav util新特性
C:\0wkspc\webdavclient\src\webdavclient\webdavclientUtil.java
webdavclient
类webdavclientUtil
[if !supportLists]· [endif]java.lang.Object
[if !supportLists]· [endif]
[if !supportLists]· [endif]webdavclient.webdavclientUtil
[if !supportLists]· [endif]
[if !supportLists]· [endif]
public class webdavclientUtil
extends java.lang.Object
[if !supportLists]· [endif]
[if !supportLists]· [endif]
构造器概要
[if !supportLists]· [endif]
构造器
构造器和说明
webdavclientUtil()
[if !supportLists]· [endif]
方法概要
[if !supportLists]· [endif]
方法
限定符和类型方法和说明
static voiddown(java.lang.String url, java.lang.String outputstream1File)
static voidmain(java.lang.String[] args)
voidtest_diwn()
voidtest_upload()
static org.apache.jackrabbit.webdav.client.methods.PutMethodupload(java.lang.String source, java.lang.String destinationUri)
[if !supportLists]· [endif]
从类继承的方法java.lang.Object
[if !supportLists]· [endif]clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
[if !supportLists]· [endif]
构造器详细资料
[if !supportLists]· [endif]
webdavclientUtil
[if !supportLists]· [endif]
public webdavclientUtil()
[if !supportLists]· [endif]
package webdavclient;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URI;
import java.util.Map;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.StatusLine;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.io.FileUtils;
import org.apache.jackrabbit.commons.json.JsonUtil;
import org.apache.jackrabbit.webdav.client.methods.CopyMethod;
import org.apache.jackrabbit.webdav.client.methods.DavMethod;
import org.apache.jackrabbit.webdav.client.methods.MkColMethod;
import org.apache.jackrabbit.webdav.client.methods.PutMethod;
import org.junit.Test;
import com.alibaba.fastjson.JSON;
import com.attilax.net.HttpClientUtil4_0_1;
import com.attilax.net.urlUtils;
import com.google.common.collect.Maps;
// /webdavclient/src/webdavclient/webdavclientUtil.java
public class webdavclientUtil {
public static void main(String[] args) throws HttpException, IOException {
// jackrabbit ver 2.6.10
HttpClient HttpClient1 = new HttpClient(); // HttpClient 3.1 jar
Credentials creds = new UsernamePasswordCredentials("admin", "password");
// client.getState().setCredentials(AuthScope.ANY, creds);
// MKCOL method mk dir foler
DavMethod mkCol = new MkColMethod("http://192.168.1.77:1316/webdavapp/webdavurl/tests67");
HttpClient1.executeMethod(mkCol);
int statusCode = mkCol.getStatusCode();
String statusText = mkCol.getStatusText();
StatusLine statusLine = mkCol.getStatusLine();
System.out.println("d");
String rar = "C:\\d\\dockbase\\jdk1.8.0_131.rar";
URI uri = new File(rar).toURI();
String destinationUri = "http://192.168.1.77:1316/webdavapp/webdavurl/tests67/jdk1.8.0_131.rar.zip";
// copyMethod:复制一个资源从服务器上的一个位置到另一个位置
// CopyMethod CopyMethod1= new CopyMethod(uri.toString(),
// destinationUri, true); // unsupported protocol: 'file'
// upload(HttpClient1, rar, destinationUri);
System.out.println("d2");
}
@Test
public void test_upload() throws FileNotFoundException, HttpException, IOException {
String source = "C:\\Users\\attilax\\Documents\\s6 doc compc\\Atitit 应用程序容器化总结 v2 s66.docx";
String destinationUri = "http://192.168.1.77:1316/webdavapp/webdavurl/tests67/aa容器化总结.docx";
destinationUri=urlUtils.encodeURI (destinationUri);
PutMethod putMethod1= webdavclientUtil.upload(source, destinationUri);
Map m=Maps.newLinkedHashMap();
m.put("statusCode", putMethod1.getStatusCode());
m.put("statusText", putMethod1.getStatusText());
m.put("StatusLine", putMethod1.getStatusLine());
System.out.println( JSON.toJSONString(m));
System.out.println("--f");
}
@Test
public void test_diwn() throws FileNotFoundException, HttpException, IOException {
String source = "C:\\Users\\attilax\\Documents\\s6 doc compc\\Atitit 应用程序容器化总结 v2 s66.docx";
// String destinationUri = "http://192.168.1.77:1316/webdavapp/webdavurl/tests67/aa容器化总结.docx";
String destinationUri = "http://192.168.1.77:1316/webdavapp/webdavurl/tests67/jdk1.8.0_131.rar.zip";
destinationUri=urlUtils.encodeURI (destinationUri);
down( destinationUri,"C:\\tmps67\\jdk1.8.0_131.rar.zip");
System.out.println("--f");
}
public static void down( String url,String outputstream1File) throws IOException
{
FileUtils.forceMkdir(new File(outputstream1File).getParentFile());
HttpClientUtil4_0_1.httpget(url, outputstream1File);
}
public static PutMethod upload(String source, String destinationUri)
throws FileNotFoundException, IOException, HttpException {
HttpClient HttpClient1 = new HttpClient(); // HttpClient 3.1 jar
PutMethod putMethod1 = new PutMethod(destinationUri.toString());
RequestEntity requestEntity = new InputStreamRequestEntity(new FileInputStream(source));
putMethod1.setRequestEntity(requestEntity);
HttpClient1.executeMethod(putMethod1);
int statusCode = putMethod1.getStatusCode();
String statusText = putMethod1.getStatusText();
StatusLine statusLine_CopyMethod1 = putMethod1.getStatusLine();
return putMethod1;
}
}
������7�