|
@@ -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
|
|
-}
|