- Timestamp:
- 2014-05-01T20:15:13+12:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/gli/src/org/greenstone/gatherer/gui/FormatConversionDialog.java
r29016 r29017 7 7 import org.greenstone.gatherer.cdm.CollectionConfigXMLReadWrite; 8 8 import org.greenstone.gatherer.util.Codec; 9 import org.greenstone.gatherer.util.InputStreamGobbler; 10 import org.greenstone.gatherer.util.OutputStreamGobbler; 9 11 import org.greenstone.gatherer.util.StaticStrings; 10 12 import org.greenstone.gatherer.util.Utility; … … 370 372 371 373 return outputstr; 372 }373 374 375 // http://docs.oracle.com/javase/tutorial/essential/exceptions/finally.html376 // http://stackoverflow.com/questions/481446/throws-exception-in-finally-blocks377 private void closeResource(Closeable resourceHandle) {378 try {379 if(resourceHandle != null) {380 resourceHandle.close();381 resourceHandle = null;382 }383 } catch(Exception e) {384 System.err.println("Exception closing resource: " + e.getMessage());385 e.printStackTrace();386 }387 374 } 388 375 … … 946 933 } 947 934 948 // http://www.javaworld.com/article/2071275/core-java/when-runtime-exec---won-t.html?page=2949 class InputStreamGobbler extends Thread950 {951 InputStream is = null;952 StringBuffer outputstr = new StringBuffer();953 boolean split_newlines = false;954 955 956 public InputStreamGobbler(InputStream is)957 {958 this.is = is;959 split_newlines = false;960 }961 962 public InputStreamGobbler(InputStream is, boolean split_newlines)963 {964 this.is = is;965 this.split_newlines = split_newlines;966 }967 968 public void run()969 {970 BufferedReader br = null;971 try {972 br = new BufferedReader(new InputStreamReader(is, "UTF-8"));973 String line=null;974 while ( (line = br.readLine()) != null) {975 //System.out.println("@@@ GOT LINE: " + line);976 outputstr.append(line);977 if(split_newlines) {978 outputstr.append("\n");979 }980 981 }982 } catch (IOException ioe) {983 ioe.printStackTrace();984 } finally {985 closeResource(br);986 }987 }988 989 public String getOutput() {990 return outputstr.toString(); // implicit toString() call anyway. //return outputstr;991 }992 }993 994 class OutputStreamGobbler extends Thread995 {996 OutputStream os = null;997 String inputstr = "";998 999 public OutputStreamGobbler(OutputStream os, String inputstr)1000 {1001 this.os = os;1002 this.inputstr = inputstr;1003 }1004 1005 public void run()1006 {1007 BufferedWriter osw = null;1008 try {1009 osw = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));1010 //System.out.println("@@@ SENDING LINE: " + inputstr);1011 osw.write(inputstr, 0, inputstr.length());1012 osw.newLine();//osw.write("\n");1013 osw.flush();1014 1015 // Don't explicitly send EOF when using StreamGobblers as below,1016 // as the EOF char is echoed to output.1017 // Flushing the write handle and/or closing the resource seems1018 // to already send EOF silently.1019 1020 /*if(Utility.isWindows()) {1021 osw.write("\032"); // octal for Ctrl-Z, EOF on Windows1022 } else { // EOF on Linux/Mac is Ctrl-D1023 osw.write("\004"); // octal for Ctrl-D, see http://www.unix-manuals.com/refs/misc/ascii-table.html1024 }1025 osw.flush();1026 */1027 } catch (IOException ioe) {1028 ioe.printStackTrace();1029 } finally {1030 closeResource(osw);1031 }1032 }1033 }1034 1035 935 private class UndoListener implements ActionListener 1036 936 {
Note:
See TracChangeset
for help on using the changeset viewer.