source: main/trunk/gli/src/org/greenstone/gatherer/util/OutputStreamGobbler.java@ 29031

Last change on this file since 29031 was 29031, checked in by ak19, 10 years ago

Moved out the NumberedJTextArea into its own class. It now manages the associated Undo and RedoButtons itself, so that the undo/redobutton code and their listeners are also moved out of FormatConversionDialog. Tested that it all still works, including bugfix to previous commit by overrding undo/redoLastAction() in NumberedJTextArea.java. 2. Also, cleaned up import statements, minor change to comments in the StreamGobbler classes, added the license text at the top of all these new classes.

File size: 2.7 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * Copyright (C) 1999 New Zealand Digital Library Project
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *########################################################################
24 */
25
26package org.greenstone.gatherer.util;
27
28import java.io.BufferedReader;
29import java.io.BufferedWriter;
30import java.io.File;
31import java.io.InputStream;
32import java.io.InputStreamReader;
33import java.io.IOException;
34import java.io.OutputStream;
35import java.io.OutputStreamWriter;
36
37// http://www.javaworld.com/article/2071275/core-java/when-runtime-exec---won-t.html?page=2
38// This class is used in FormatConversionDialog to properly write to the inputstream of a Process
39// Process.getOutputStream()
40public class OutputStreamGobbler extends Thread
41{
42 OutputStream os = null;
43 String inputstr = "";
44
45 public OutputStreamGobbler(OutputStream os, String inputstr)
46 {
47 this.os = os;
48 this.inputstr = inputstr;
49 }
50
51 public void run()
52 {
53 BufferedWriter osw = null;
54 try {
55 osw = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
56 //System.out.println("@@@ SENDING LINE: " + inputstr);
57 osw.write(inputstr, 0, inputstr.length());
58 osw.newLine();//osw.write("\n");
59 osw.flush();
60
61 // Don't explicitly send EOF when using StreamGobblers as below,
62 // as the EOF char is echoed to output.
63 // Flushing the write handle and/or closing the resource seems
64 // to already send EOF silently.
65
66 /*if(Utility.isWindows()) {
67 osw.write("\032"); // octal for Ctrl-Z, EOF on Windows
68 } else { // EOF on Linux/Mac is Ctrl-D
69 osw.write("\004"); // octal for Ctrl-D, see http://www.unix-manuals.com/refs/misc/ascii-table.html
70 }
71 osw.flush();
72 */
73 } catch (IOException ioe) {
74 ioe.printStackTrace();
75 } finally {
76 Utility.closeResource(osw);
77 }
78 }
79}
Note: See TracBrowser for help on using the repository browser.