Переглянути джерело

Delete some StreamUtils.

pull/21/head
Greg Holmes 9 роки тому
джерело
коміт
b699f94261

+ 62
- 0
src/com/dmdirc/util/io/StreamIgnorer.java Переглянути файл

@@ -0,0 +1,62 @@
1
+/*
2
+ * Copyright (c) 2006-2014 DMDirc Developers
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.util.io;
24
+
25
+import java.io.BufferedReader;
26
+import java.io.IOException;
27
+import java.io.InputStream;
28
+import java.io.InputStreamReader;
29
+
30
+/**
31
+ * Stream reader to read, but ignore a stream.
32
+ */
33
+class StreamIgnorer extends Thread {
34
+
35
+    /** This is the Input Stream we are reading. */
36
+    private final InputStream stream;
37
+
38
+    /**
39
+     * Create a new Stream Ignorer that discards output.
40
+     *
41
+     * @param stream The stream to ignore
42
+     */
43
+    StreamIgnorer(final InputStream stream) {
44
+        super("StreamIgnorer");
45
+
46
+        this.stream = stream;
47
+    }
48
+
49
+    /**
50
+     * Wait for input on stream, and discards the data.
51
+     */
52
+    @Override
53
+    public void run() {
54
+        try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream))) {
55
+            while (reader.readLine() != null) {
56
+                //Totally Ignore
57
+            }
58
+        } catch (IOException ex) {
59
+            // OH WELL
60
+        }
61
+    }
62
+}

+ 0
- 110
src/com/dmdirc/util/io/StreamReader.java Переглянути файл

@@ -1,110 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in
12
- * all copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
-package com.dmdirc.util.io;
24
-
25
-import java.io.BufferedReader;
26
-import java.io.IOException;
27
-import java.io.InputStream;
28
-import java.io.InputStreamReader;
29
-import java.util.List;
30
-
31
-/**
32
- * Simple stream reader to read a stream and save/discard the data.
33
- */
34
-class StreamReader extends Thread {
35
-
36
-    /** This is the Input Stream we are reading. */
37
-    private final InputStream stream;
38
-    /** List to store output in. */
39
-    private List<String> list;
40
-    /** StringBuffer to store output in. */
41
-    private StringBuffer buffer; // NOPMD
42
-
43
-    /**
44
-     * Create a new Stream Reader that discards output.
45
-     *
46
-     * @param stream The stream to read
47
-     */
48
-    StreamReader(final InputStream stream) {
49
-        super("StreamReader");
50
-
51
-        this.stream = stream;
52
-    }
53
-
54
-    /**
55
-     * Create a new Stream Reader that outputs to a List.
56
-     *
57
-     * @param stream The stream to read
58
-     * @param list The list to store the output from the stream in
59
-     */
60
-    @SuppressWarnings("AssignmentToCollectionOrArrayFieldFromParameter")
61
-    StreamReader(final InputStream stream, final List<String> list) {
62
-        super("StreamReader");
63
-
64
-        this.stream = stream;
65
-        this.list = list;
66
-    }
67
-
68
-    /**
69
-     * Create a new Stream Reader that outputs to a StringBuffer.
70
-     *
71
-     * @param stream The stream to read
72
-     * @param buffer The StringBuffer to store the output from the stream in
73
-     */
74
-    StreamReader(final InputStream stream, final StringBuffer buffer) {
75
-        super("StreamReader");
76
-
77
-        this.stream = stream;
78
-        this.buffer = buffer;
79
-    }
80
-
81
-    /**
82
-     * Get the list that the output is being stored in.
83
-     *
84
-     * @return The output list
85
-     */
86
-    @SuppressWarnings("ReturnOfCollectionOrArrayField")
87
-    List<String> getList() {
88
-        return list;
89
-    }
90
-
91
-    /**
92
-     * Wait for input on stream, and output/throw away/save to list.
93
-     */
94
-    @Override
95
-    public void run() {
96
-        try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream))) {
97
-            String line;
98
-            while ((line = reader.readLine()) != null) {
99
-                if (list != null) {
100
-                    list.add(line);
101
-                } else if (buffer != null) {
102
-                    if (buffer.length() > 0) { buffer.append('\n'); }
103
-                    buffer.append(line);
104
-                }
105
-            }
106
-        } catch (IOException ex) {
107
-            // OH WELL
108
-        }
109
-    }
110
-}

+ 1
- 12
src/com/dmdirc/util/io/StreamUtils.java Переглянути файл

@@ -25,7 +25,6 @@ package com.dmdirc.util.io;
25 25
 import java.io.Closeable;
26 26
 import java.io.IOException;
27 27
 import java.io.InputStream;
28
-import java.util.List;
29 28
 
30 29
 /**
31 30
  * Utilities for dealing with streams.
@@ -39,17 +38,7 @@ public final class StreamUtils {
39 38
     }
40 39
 
41 40
     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();
41
+        new StreamIgnorer(inputStream).run();
53 42
     }
54 43
 
55 44
     /**

+ 3
- 3
test/com/dmdirc/util/io/StreamReaderTest.java Переглянути файл

@@ -45,7 +45,7 @@ public class StreamReaderTest {
45 45
     @Test
46 46
     public void testGetListDiscarding() throws Exception {
47 47
         final InputStream inputStream = spy(getClass().getResource("test5.txt").openStream());
48
-        final StreamReader streamReader = new StreamReader(inputStream);
48
+        final StreamIgnorer streamReader = new StreamIgnorer(inputStream);
49 49
         assertNull(streamReader.getList());
50 50
         streamReader.run();
51 51
         assertNull(streamReader.getList());
@@ -55,7 +55,7 @@ public class StreamReaderTest {
55 55
     @Test
56 56
     public void testGetListBuffer() throws Exception {
57 57
         final StringBuffer stringBuffer = new StringBuffer();
58
-        final StreamReader streamReader = new StreamReader(getClass().getResource("test5.txt")
58
+        final StreamIgnorer streamReader = new StreamIgnorer(getClass().getResource("test5.txt")
59 59
                 .openStream(),
60 60
                 stringBuffer);
61 61
         assertNull(streamReader.getList());
@@ -67,7 +67,7 @@ public class StreamReaderTest {
67 67
     @Test
68 68
     public void testGetListList() throws Exception {
69 69
         final List<String> list = new ArrayList<>();
70
-        final StreamReader streamReader = new StreamReader(getClass().getResource("test5.txt")
70
+        final StreamIgnorer streamReader = new StreamIgnorer(getClass().getResource("test5.txt")
71 71
                 .openStream(), list);
72 72
         assertTrue(streamReader.getList().isEmpty());
73 73
         streamReader.run();

Завантаження…
Відмінити
Зберегти