|
|
@ -21,6 +21,7 @@ import java.util.* |
|
|
|
|
|
|
|
|
|
|
|
class WebDav @Throws(MalformedURLException::class) |
|
|
|
class WebDav @Throws(MalformedURLException::class) |
|
|
|
constructor(url: String) { |
|
|
|
constructor(url: String) { |
|
|
|
|
|
|
|
private val okHttpClient = HttpHelper.client |
|
|
|
private val url: URL = URL(null, url, Handler) |
|
|
|
private val url: URL = URL(null, url, Handler) |
|
|
|
private var httpUrl: String? = null |
|
|
|
private var httpUrl: String? = null |
|
|
|
|
|
|
|
|
|
|
@ -36,10 +37,9 @@ constructor(url: String) { |
|
|
|
return field |
|
|
|
return field |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private val okHttpClient = HttpHelper.client |
|
|
|
fun getPath() = url.toString() |
|
|
|
|
|
|
|
|
|
|
|
val path: String |
|
|
|
fun getHost() = url.host |
|
|
|
get() = url.toString() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private val inputStream: InputStream? |
|
|
|
private val inputStream: InputStream? |
|
|
|
get() = getUrl()?.let { url -> |
|
|
|
get() = getUrl()?.let { url -> |
|
|
@ -56,9 +56,6 @@ constructor(url: String) { |
|
|
|
return null |
|
|
|
return null |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
val host: String |
|
|
|
|
|
|
|
get() = url.host |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun getUrl(): String? { |
|
|
|
private fun getUrl(): String? { |
|
|
|
if (httpUrl == null) { |
|
|
|
if (httpUrl == null) { |
|
|
|
val raw = url.toString().replace("davs://", "https://").replace("dav://", "http://") |
|
|
|
val raw = url.toString().replace("davs://", "https://").replace("dav://", "http://") |
|
|
@ -111,7 +108,6 @@ constructor(url: String) { |
|
|
|
return parseDir(body.string()) |
|
|
|
return parseDir(body.string()) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return ArrayList() |
|
|
|
return ArrayList() |
|
|
|
} |
|
|
|
} |
|
|
@ -194,9 +190,7 @@ constructor(url: String) { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
fun downloadTo(savedPath: String, replaceExisting: Boolean): Boolean { |
|
|
|
fun downloadTo(savedPath: String, replaceExisting: Boolean): Boolean { |
|
|
|
if (File(savedPath).exists()) { |
|
|
|
if (File(savedPath).exists()) { |
|
|
|
if (!replaceExisting) { |
|
|
|
if (!replaceExisting) return false |
|
|
|
return false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
val inputS = inputStream ?: return false |
|
|
|
val inputS = inputStream ?: return false |
|
|
|
File(savedPath).writeBytes(inputS.readBytes()) |
|
|
|
File(savedPath).writeBytes(inputS.readBytes()) |
|
|
@ -225,7 +219,6 @@ constructor(url: String) { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 执行请求,获取响应结果 |
|
|
|
* 执行请求,获取响应结果 |
|
|
|
* |
|
|
|
|
|
|
|
* @param requestBuilder 因为还需要追加验证信息,所以此处传递Request.Builder的对象,而不是Request的对象 |
|
|
|
* @param requestBuilder 因为还需要追加验证信息,所以此处传递Request.Builder的对象,而不是Request的对象 |
|
|
|
* @return 请求执行的结果 |
|
|
|
* @return 请求执行的结果 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|