gpt4 book ai didi

android - Webdav 与 jackrabbit lib 在 android 上

转载 作者:行者123 更新时间:2023-11-30 03:15:19 24 4
gpt4 key购买 nike

我用 Jackrabbit 库实现了 webdav。
我使用下面的代码通过 webdav 扫描文件夹中的所有文件:

public void ListWebDav() {
String FullPath = Webdav Path;
try {
DavMethod davMethod = new PropFindMethod(FullPath, DavConstants.PROPFIND_ALL_PROP, DavConstants.DEPTH_1);
WebDavClient.executeMethod(davMethod);

MultiStatus multiStatus = davMethod.getResponseBodyAsMultiStatus();
MultiStatusResponse[] responses = multiStatus.getResponses();
MultiStatusResponse currResponse;

for(int i = 0; i < responses.length; i++) {
currResponse = responses[i];
if(getContentType(currResponse) != null) {
if(((String)getContentType(currResponse)).contains("directory")) { //Folder
System.out.println("Folder " + URLDecoder.decode(currResponse.getHref()));
}
else { //File
System.out.println("File " + URLDecoder.decode(currResponse.getHref()));
}
}
else {
System.out.println(URLDecoder.decode(currResponse.getHref()));
}
}
}
catch(Exception e) {
e.printStackTrace();
}
}

public Object getContentType(MultiStatusResponse msr) {
try {
Status[] statusa = msr.getStatus();
Status status = statusa[0];

int n = status.getStatusCode();
DavPropertySet propSet = msr.getProperties(n);
DavProperty davProp = propSet.get(DavPropertyName.PROPERTY_GETCONTENTTYPE);
return davProp.getValue();
}
catch(Exception e) {
return null;
}
}

getContentType函数是判断是文件夹还是文件。
我第一次运行 ListWebDav 方法是正常的。
但是如果第二次运行。
它将崩溃并在 Status[] statusa = msr.getStatus(); 行显示以下错误代码:

11-27 10:08:29.331: E/StrictMode(26469): A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
11-27 10:08:29.331: E/StrictMode(26469): java.lang.Throwable: Explicit termination method 'end' not called
11-27 10:08:29.331: E/StrictMode(26469): at dalvik.system.CloseGuard.open(CloseGuard.java:184)
11-27 10:08:29.331: E/StrictMode(26469): at java.util.zip.Inflater.<init>(Inflater.java:82)
11-27 10:08:29.331: E/StrictMode(26469): at java.util.zip.ZipFile.getInputStream(ZipFile.java:310)
11-27 10:08:29.331: E/StrictMode(26469): at java.util.jar.JarFile.getInputStream(JarFile.java:389)
11-27 10:08:29.331: E/StrictMode(26469): at libcore.net.url.JarURLConnectionImpl.getInputStream(JarURLConnectionImpl.java:222)
11-27 10:08:29.331: E/StrictMode(26469): at java.net.URL.openStream(URL.java:470)
11-27 10:08:29.331: E/StrictMode(26469): at java.lang.ClassLoader.getResourceAsStream(ClassLoader.java:432)
11-27 10:08:29.331: E/StrictMode(26469): at java.lang.Class.getResourceAsStream(Class.java:1037)
11-27 10:08:29.331: E/StrictMode(26469): at org.apache.jackrabbit.webdav.DavException.<clinit>(DavException.java:41)
11-27 10:08:29.331: E/StrictMode(26469): at org.apache.jackrabbit.webdav.Status.<init>(Status.java:42)
11-27 10:08:29.331: E/StrictMode(26469): at org.apache.jackrabbit.webdav.MultiStatusResponse.getStatus(MultiStatusResponse.java:253)
11-27 10:08:29.331: E/StrictMode(26469): at com.wd.wifi.cable.GlobalData.getContentType(GlobalData.java:313)
11-27 10:08:29.331: E/StrictMode(26469): at com.wd.wifi.cable.GlobalData.ListWebDav(GlobalData.java:277)
11-27 10:08:29.331: E/StrictMode(26469): at com.wd.wifi.cable.GlobalData.ConnectWebDav(GlobalData.java:258)
11-27 10:08:29.331: E/StrictMode(26469): at com.wd.wifi.cable.HDDDevicesListViewFragment$3.onItemClick(HDDDevicesListViewFragment.java:81)
11-27 10:08:29.331: E/StrictMode(26469): at android.widget.AdapterView.performItemClick(AdapterView.java:299)
11-27 10:08:29.331: E/StrictMode(26469): at android.widget.AbsListView.performItemClick(AbsListView.java:1113)
11-27 10:08:29.331: E/StrictMode(26469): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2904)
11-27 10:08:29.331: E/StrictMode(26469): at android.widget.AbsListView$3.run(AbsListView.java:3638)
11-27 10:08:29.331: E/StrictMode(26469): at android.os.Handler.handleCallback(Handler.java:733)
11-27 10:08:29.331: E/StrictMode(26469): at android.os.Handler.dispatchMessage(Handler.java:95)
11-27 10:08:29.331: E/StrictMode(26469): at android.os.Looper.loop(Looper.java:137)
11-27 10:08:29.331: E/StrictMode(26469): at android.app.ActivityThread.main(ActivityThread.java:4998)
11-27 10:08:29.331: E/StrictMode(26469): at java.lang.reflect.Method.invokeNative(Native Method)
11-27 10:08:29.331: E/StrictMode(26469): at java.lang.reflect.Method.invoke(Method.java:515)
11-27 10:08:29.331: E/StrictMode(26469): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
11-27 10:08:29.331: E/StrictMode(26469): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
11-27 10:08:29.331: E/StrictMode(26469): at dalvik.system.NativeStart.main(Native Method)

我该如何解决?

最佳答案

a) 为此使用 DAV:getcontenttype 是不正确的;它是可选的(这可能会导致此处出现 NullPointerException)。b) 您确实需要检查 DAV:resourcetype 属性。

关于android - Webdav 与 jackrabbit lib 在 android 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20232731/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com