$darkmode
DENOPTIM
StreamGobbler.java
Go to the documentation of this file.
1/*
2 * DENOPTIM
3 * Copyright (C) 2019 Vishwesh Venkatraman <vishwesh.venkatraman@ntnu.no>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package denoptim.task;
20
21import java.io.BufferedReader;
22import java.io.IOException;
23import java.io.InputStream;
24import java.io.InputStreamReader;
25
26import denoptim.constants.DENOPTIMConstants;
27
32class StreamGobbler extends Thread
33{
34 InputStream is;
35 String type;
36 StringBuilder sb;
37
38//------------------------------------------------------------------------------
39
40 StreamGobbler(InputStream is, String type)
41 {
42 this.is = is;
43 this.type = type;
44 this.sb = new StringBuilder();
45 }
46
47//------------------------------------------------------------------------------
48
49 public String getMessages()
50 {
51 return sb.toString();
52 }
53
54//------------------------------------------------------------------------------
55
56 @Override
57 public void run()
58 {
59 try
60 {
61 InputStreamReader isr = new InputStreamReader(is);
62 BufferedReader br = new BufferedReader(isr);
63 String line;
64 while ((line = br.readLine()) != null)
65 sb.append(type).append("> ").append(line).append(
67
68 br.close();
69 }
70 catch (IOException ioe)
71 {
72 }
73 }
74
75//------------------------------------------------------------------------------
76}
General set of constants used in DENOPTIM.
static final String EOL
new line character
See http://www.javaworld.com/jw-12-2000/jw-1229-traps.html?page=4.
StreamGobbler(InputStream is, String type)