浏览代码

HttpStreamFetcher: reduce nesting in loadData

Make detekt happy

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
Álvaro Brey 3 年之前
父节点
当前提交
9cff9725fc
共有 1 个文件被更改,包括 12 次插入8 次删除
  1. 12 8
      app/src/main/java/com/owncloud/android/utils/glide/HttpStreamFetcher.kt

+ 12 - 8
app/src/main/java/com/owncloud/android/utils/glide/HttpStreamFetcher.kt

@@ -54,14 +54,7 @@ class HttpStreamFetcher internal constructor(
                 get.setRequestHeader(RemoteOperation.OCS_API_HEADER, RemoteOperation.OCS_API_HEADER_VALUE)
                 val status = client.executeMethod(get)
                 if (status == HttpStatus.SC_OK) {
-                    val byteOutputStream = ByteArrayOutputStream()
-                    get.responseBodyAsStream.use { input ->
-                        byteOutputStream.use { output ->
-                            input.copyTo(output)
-                        }
-                    }
-
-                    return ByteArrayInputStream(byteOutputStream.toByteArray())
+                    return getResponseAsInputStream(get)
                 } else {
                     client.exhaustResponse(get.responseBodyAsStream)
                 }
@@ -74,6 +67,17 @@ class HttpStreamFetcher internal constructor(
         return null
     }
 
+    private fun getResponseAsInputStream(getMethod: GetMethod): ByteArrayInputStream {
+        val byteOutputStream = ByteArrayOutputStream()
+        getMethod.responseBodyAsStream.use { input ->
+            byteOutputStream.use { output ->
+                input.copyTo(output)
+            }
+        }
+
+        return ByteArrayInputStream(byteOutputStream.toByteArray())
+    }
+
     override fun cleanup() {
         Log_OC.i(TAG, "Cleanup")
     }