Changeset 31582
- Timestamp:
- 2017-04-06T19:15:55+12:00 (7 years ago)
- Location:
- main/trunk/gli/src/org/greenstone/gatherer
- Files:
-
- 1 added
- 2 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/gli/src/org/greenstone/gatherer/gui/ConfigFileEditor.java
r30959 r31582 29 29 import org.greenstone.gatherer.Dictionary; 30 30 import org.greenstone.gatherer.Gatherer; 31 import org.greenstone.gatherer.cdm.CollectionConfigXMLReadWrite;32 import org.greenstone.gatherer.util.Codec;33 import org.greenstone.gatherer.util.InputStreamGobbler;34 import org.greenstone.gatherer.util.OutputStreamGobbler;35 31 import org.greenstone.gatherer.util.StaticStrings; 36 32 import org.greenstone.gatherer.util.Utility; -
main/trunk/gli/src/org/greenstone/gatherer/gui/DownloadPane.java
r29974 r31582 52 52 import org.greenstone.gatherer.file.WorkspaceTree; 53 53 import org.greenstone.gatherer.greenstone.LocalGreenstone; 54 import org.greenstone.gatherer.util.SafeProcess; 54 55 import org.greenstone.gatherer.util.StaticStrings; 55 56 import org.greenstone.gatherer.util.Utility; … … 281 282 } 282 283 finally { 283 Utility.closeProcess(process);284 SafeProcess.closeProcess(process); 284 285 } 285 286 -
main/trunk/gli/src/org/greenstone/gatherer/gui/FormatConversionDialog.java
r30870 r31582 31 31 import org.greenstone.gatherer.cdm.CollectionConfigXMLReadWrite; 32 32 import org.greenstone.gatherer.util.Codec; 33 import org.greenstone.gatherer.util.InputStreamGobbler; 34 import org.greenstone.gatherer.util.OutputStreamGobbler; 33 import org.greenstone.gatherer.util.SafeProcess; 35 34 import org.greenstone.gatherer.util.StaticStrings; 36 35 import org.greenstone.gatherer.util.XMLTools; … … 317 316 }*/ 318 317 318 SafeProcess prcs = new SafeProcess(command_args); 319 prcs.setInputString(inputstr); 320 prcs.setSplitStdErrorNewLines(true); 321 prcs.runProcess(); 322 // process done, now get process output 323 outputstr = prcs.getStdOutput(); 324 String errmsg = prcs.getStdError(); 325 if(!errmsg.equals("")) { 326 System.err.println("*** Process errorstream: \n" + errmsg + "\n****"); 327 } 328 329 ///System.err.println("#### Got output: " + outputstr); 330 331 /* 319 332 try { 320 333 … … 363 376 //ie.printStackTrace(); 364 377 } 365 378 */ 366 379 return outputstr; 367 380 } -
main/trunk/gli/src/org/greenstone/gatherer/util/GS3ServerThread.java
r29361 r31582 86 86 // And we'll catch the error and output streams to prevent them from blocking during waitFor() 87 87 // (For normal input and output stream handling using the Gobblers, see FormatConversionDialog.java) 88 OutputStreamGobbler inputGobbler = new OutputStreamGobbler(p.getOutputStream(), null); 89 InputStreamGobbler errorGobbler = new InputStreamGobbler(p.getErrorStream(), true); 90 InputStreamGobbler outputGobbler = new InputStreamGobbler(p.getInputStream()); 88 SafeProcess.OutputStreamGobbler inputGobbler 89 = new SafeProcess.OutputStreamGobbler(p.getOutputStream(), null); 90 SafeProcess.InputStreamGobbler errorGobbler 91 = new SafeProcess.InputStreamGobbler(p.getErrorStream(), true); 92 SafeProcess.InputStreamGobbler outputGobbler 93 = new SafeProcess.InputStreamGobbler(p.getInputStream()); 91 94 92 95 errorGobbler.start(); -
main/trunk/gli/src/org/greenstone/gatherer/util/Utility.java
r30702 r31582 41 41 // Don't even think about adding import java.awt.* here! 42 42 // The functions in this class should not use any graphical classes. Put your function somewhere else buster! 43 import java.io.Closeable;44 43 import java.io.*; 45 44 import java.net.*; … … 50 49 // Don't even think about adding import org.greenstone.gatherer.Gatherer in here! 51 50 // The functions in this class should be independent of the Gatherer class. Put your function somewhere else buster! 52 51 import org.greenstone.gatherer.util.SafeProcess; // for the closeResource() static method 53 52 54 53 /** To provide a library of common methods, in a static context, for use in the Gatherer. … … 74 73 static final public String PERL_EXECUTABLE_WINDOWS = "Perl.exe"; 75 74 75 /** Platform independent NEWLINE character */ 76 public static final String NEWLINE; 77 78 // NEWLINE related code copied across from GS3 src code 79 // Before Java 7, no System.lineSeparator() or System.getProperty("line.separator") 80 // And on local linux, am compiling with JDK 6, so need this. 81 // http://stackoverflow.com/questions/207947/how-do-i-get-a-platform-dependent-new-line-character 82 // http://stackoverflow.com/questions/2591083/getting-java-version-at-runtime 83 // https://www.tutorialspoint.com/java/lang/package_getspecificationversion.htm 84 // https://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html 85 // Can initialise static final vars on declaration or in static initialisation code block 86 // http://stackoverflow.com/questions/2339932/java-can-final-variables-be-initialized-in-static-initialization-block 87 // Initialise object member final vars on declaration or in constructors 88 static { 89 double java_version = Double.parseDouble(System.getProperty("java.specification.version")); 90 if(java_version >= 1.7) { 91 NEWLINE = System.getProperty("line.separator"); 92 } else { 93 NEWLINE = isWindows() ? "\r\n" : "\n"; 94 } 95 } 76 96 77 97 /** … … 93 113 System.err.println("*** Exception occurred: " + e.getMessage()); 94 114 } finally { 95 closeResource(fin);115 SafeProcess.closeResource(fin); 96 116 } 97 117 … … 575 595 System.err.println("Exception occurred: " + e.getMessage()); 576 596 } finally { 577 closeResource(fin);578 closeResource(fout);597 SafeProcess.closeResource(fin); 598 SafeProcess.closeResource(fout); 579 599 580 600 } 581 601 return oldValue; 582 602 } 583 584 // For safely closing streams/handles/resources.585 // For examples of use look in the Input- and OutputStreamGobbler classes.586 // http://docs.oracle.com/javase/tutorial/essential/exceptions/finally.html587 // http://stackoverflow.com/questions/481446/throws-exception-in-finally-blocks588 public static void closeResource(Closeable resourceHandle) {589 try {590 if(resourceHandle != null) {591 resourceHandle.close();592 resourceHandle = null;593 }594 } catch(Exception e) {595 System.err.println("Exception closing resource: " + e.getMessage());596 e.printStackTrace();597 resourceHandle = null;598 }599 }600 601 public static void closeProcess(Process prcs) {602 if( prcs != null ) {603 closeResource(prcs.getErrorStream());604 closeResource(prcs.getOutputStream());605 closeResource(prcs.getInputStream());606 prcs.destroy();607 }608 }609 603 }
Note:
See TracChangeset
for help on using the changeset viewer.