File tree Expand file tree Collapse file tree 1 file changed +2
-18
lines changed
codepulse/src/main/scala/com/secdec/codepulse/util Expand file tree Collapse file tree 1 file changed +2
-18
lines changed Original file line number Diff line number Diff line change 2020package com .secdec .codepulse .util
2121
2222import java .io .ByteArrayInputStream
23- import java .io .ByteArrayOutputStream
2423import java .io .InputStream
2524
2625import scala .io .Codec
27- import scala .io .Codec .string2codec
2826import scala .io .Source
2927
28+ import org .apache .commons .io .IOUtils
3029import org .mozilla .universalchardet .UniversalDetector
3130
3231/** Loader that detects the proper character set when loading the contents of a
@@ -64,22 +63,7 @@ class SmartLoader {
6463 * memory.
6564 */
6665 def loadStream (stream : InputStream ): String = {
67- val bytes = {
68- val bos = new ByteArrayOutputStream
69- val buffer = new Array [Byte ](BufferSize )
70-
71- val chunks = Iterator .continually {
72- stream.read(buffer, 0 , buffer.length) -> buffer
73- } takeWhile { _._1 > 0 }
74-
75- for ((len, buffer) <- chunks) {
76- bos.write(buffer, 0 , len)
77- }
78-
79- bos.flush
80- bos.toByteArray
81- }
82-
66+ val bytes = IOUtils .toByteArray(stream)
8367 val charset = Option (detectCharset(new ByteArrayInputStream (bytes))).map[Codec ](identity)
8468 Source .fromInputStream(new ByteArrayInputStream (bytes))(charset getOrElse Codec .UTF8 ).mkString
8569 }
You can’t perform that action at this time.
0 commit comments