소스 검색

Hide StreamReader behind StreamUtils.

Change-Id: Ia24b29f2fcd414d7b27bad52cc6fad6312179de5
Reviewed-on: http://gerrit.dmdirc.com/4067
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Chris Smith <chris@dmdirc.com>
changes/67/4067/2
Greg Holmes 9 년 전
부모
커밋
57bcea0572
2개의 변경된 파일21개의 추가작업 그리고 5개의 파일을 삭제
  1. 5
    5
      src/com/dmdirc/util/io/StreamReader.java
  2. 16
    0
      src/com/dmdirc/util/io/StreamUtils.java

+ 5
- 5
src/com/dmdirc/util/io/StreamReader.java 파일 보기

@@ -31,7 +31,7 @@ import java.util.List;
31 31
 /**
32 32
  * Simple stream reader to read a stream and save/discard the data.
33 33
  */
34
-public class StreamReader extends Thread {
34
+class StreamReader extends Thread {
35 35
 
36 36
     /** This is the Input Stream we are reading. */
37 37
     private final InputStream stream;
@@ -45,7 +45,7 @@ public class StreamReader extends Thread {
45 45
      *
46 46
      * @param stream The stream to read
47 47
      */
48
-    public StreamReader(final InputStream stream) {
48
+    StreamReader(final InputStream stream) {
49 49
         super("StreamReader");
50 50
 
51 51
         this.stream = stream;
@@ -57,7 +57,7 @@ public class StreamReader extends Thread {
57 57
      * @param stream The stream to read
58 58
      * @param list The list to store the output from the stream in
59 59
      */
60
-    public StreamReader(final InputStream stream, final List<String> list) {
60
+    StreamReader(final InputStream stream, final List<String> list) {
61 61
         super("StreamReader");
62 62
 
63 63
         this.stream = stream;
@@ -70,7 +70,7 @@ public class StreamReader extends Thread {
70 70
      * @param stream The stream to read
71 71
      * @param buffer The StringBuffer to store the output from the stream in
72 72
      */
73
-    public StreamReader(final InputStream stream, final StringBuffer buffer) {
73
+    StreamReader(final InputStream stream, final StringBuffer buffer) {
74 74
         super("StreamReader");
75 75
 
76 76
         this.stream = stream;
@@ -82,7 +82,7 @@ public class StreamReader extends Thread {
82 82
      *
83 83
      * @return The output list
84 84
      */
85
-    public List<String> getList() {
85
+    List<String> getList() {
86 86
         return list;
87 87
     }
88 88
 

+ 16
- 0
src/com/dmdirc/util/io/StreamUtils.java 파일 보기

@@ -24,6 +24,8 @@ package com.dmdirc.util.io;
24 24
 
25 25
 import java.io.Closeable;
26 26
 import java.io.IOException;
27
+import java.io.InputStream;
28
+import java.util.List;
27 29
 
28 30
 /**
29 31
  * Utilities for dealing with streams.
@@ -36,6 +38,20 @@ public final class StreamUtils {
36 38
     private StreamUtils() {
37 39
     }
38 40
 
41
+    public static void readStream(final InputStream inputStream) {
42
+        new StreamReader(inputStream).run();
43
+    }
44
+
45
+    public static void readStreamIntoStringBuffer(final InputStream inputStream,
46
+            final StringBuffer stringBuffer) {
47
+        new StreamReader(inputStream, stringBuffer).start();
48
+    }
49
+
50
+    public static void readStreamIntoList(final InputStream inputStream,
51
+            final List<String> list) {
52
+        new StreamReader(inputStream, list).start();
53
+    }
54
+
39 55
     /**
40 56
      * Closes the stream if it is non-null, and ignores any IOExceptions
41 57
      * raised by doing so.

Loading…
취소
저장