source: other-projects/FileTransfer-WebSocketPair/testGXTWithGreenstone/src/org/greenstone/gatherer/util/OutputStreamGobbler.java@ 33053

Last change on this file since 33053 was 33053, checked in by ak19, 5 years ago

I still had some stuff of Nathan Kelly's (FileTransfer-WebSocketPair) sitting on my USB. Had already commited the Themes folder at the time, 2 years back. Not sure if he wanted this additional folder commited. But I didn't want to delete it and decided it will be better off on SVN. When we use his project, if we find we didn't need this test folder, we can remove it from svn then.

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
54 if (inputstr == null) {
55 return;
56 }
57
58 BufferedWriter osw = null;
59 try {
60 osw = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
61 //System.out.println("@@@ SENDING LINE: " + inputstr);
62 osw.write(inputstr, 0, inputstr.length());
63 osw.newLine();//osw.write("\n");
64 osw.flush();
65
66 // Don't explicitly send EOF when using StreamGobblers as below,
67 // as the EOF char is echoed to output.
68 // Flushing the write handle and/or closing the resource seems
69 // to already send EOF silently.
70
71 /*if(Utility.isWindows()) {
72 osw.write("\032"); // octal for Ctrl-Z, EOF on Windows
73 } else { // EOF on Linux/Mac is Ctrl-D
74 osw.write("\004"); // octal for Ctrl-D, see http://www.unix-manuals.com/refs/misc/ascii-table.html
75 }
76 osw.flush();
77 */
78 } catch (IOException ioe) {
79 ioe.printStackTrace();
80 } finally {
81 Utility.closeResource(osw);
82 }
83 }
84}
Note: See TracBrowser for help on using the repository browser.