File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
src/main/kotlin/net/servicestack/gistcafe Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -3,8 +3,11 @@ package net.servicestack.gistcafe
3
3
import com.google.gson.Gson
4
4
import com.google.gson.GsonBuilder
5
5
import com.google.gson.reflect.TypeToken
6
+ import java.io.BufferedReader
6
7
import java.io.FileWriter
8
+ import java.io.InputStreamReader
7
9
import java.lang.StringBuilder
10
+ import java.net.URL
8
11
import java.nio.file.Files
9
12
import java.nio.file.Paths
10
13
import kotlin.math.abs
@@ -204,6 +207,21 @@ class Inspect {
204
207
val json = gson.toJson(obj)
205
208
return gson.fromJson(json, object : TypeToken <Map <String , Any ?>>() {}.type)
206
209
}
210
+
211
+ /* *
212
+ * Helper to download the text contents of a URL, because Java needs it.
213
+ * @param url the URL to download
214
+ */
215
+ @JvmStatic fun readUrlAsText (url : URL ): String {
216
+ val sb = StringBuilder ()
217
+ BufferedReader (InputStreamReader (url.openStream())).use { reader ->
218
+ var line: String?
219
+ while (reader.readLine().also { line = it } != null ) {
220
+ sb.append(line)
221
+ }
222
+ }
223
+ return sb.toString()
224
+ }
207
225
}
208
226
}
209
227
You can’t perform that action at this time.
0 commit comments