X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=support%2Fgeneral%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fio%2FSimpleProcess.java;h=c08f001da84910d26e8b74a2be72968f78503a26;hb=e72743b6a9fac5a99b842f92b1687fba65ef3210;hp=ed748a24da408d8dfed7ee73e30687ee83db9338;hpb=8de36ff0206c996baf3ee4adc3e2293b12ff5f39;p=utils diff --git a/support/general/src/main/java/org/wamblee/io/SimpleProcess.java b/support/general/src/main/java/org/wamblee/io/SimpleProcess.java index ed748a24..c08f001d 100644 --- a/support/general/src/main/java/org/wamblee/io/SimpleProcess.java +++ b/support/general/src/main/java/org/wamblee/io/SimpleProcess.java @@ -1,32 +1,30 @@ /* - * Copyright 2007 the original author or authors. - * + * Copyright 2005-2010 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ + */ package org.wamblee.io; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.PrintStream; import java.io.StringWriter; import java.io.Writer; +import java.util.Arrays; +import java.util.logging.Level; +import java.util.logging.Logger; /** * @@ -34,7 +32,7 @@ import java.io.Writer; * @version $Revision$ */ public class SimpleProcess { - private static final Log LOG = LogFactory.getLog(SimpleProcess.class); + private static final Logger LOG = Logger.getLogger(SimpleProcess.class.getName()); private File directory; @@ -50,7 +48,7 @@ public class SimpleProcess { */ public SimpleProcess(File aDirectory, String[] aCmd) { directory = aDirectory; - cmd = aCmd; + cmd = Arrays.copyOf(aCmd, aCmd.length); } /** @@ -83,13 +81,13 @@ public class SimpleProcess { private int runImpl() throws IOException { try { - String fullcmd = ""; + StringBuffer fullcmd = new StringBuffer(); for (String part : cmd) { - fullcmd += (" " + part); + fullcmd.append(" " + part); } - LOG.debug("Executing '" + fullcmd + "' in directory '" + directory + + LOG.fine("Executing '" + fullcmd + "' in directory '" + directory + "'"); java.lang.Process proc = Runtime.getRuntime().exec(cmd, null, @@ -120,9 +118,9 @@ public class SimpleProcess { stderr = myStderr.toString(); if (proc.exitValue() != 0) { - LOG.warn("Exit value was non-zero: " + this); + LOG.warning("Exit value was non-zero: " + this); } else { - LOG.debug("Process finished"); + LOG.fine("Process finished"); } return proc.exitValue(); @@ -139,8 +137,8 @@ public class SimpleProcess { aReaderThread.join(); } catch (InterruptedException e) { LOG - .warn(this + - ": error waiting for output stream reader of process to finish"); + .log(Level.WARNING, this + + ": error waiting for output stream reader of process to finish", e); } } @@ -157,18 +155,18 @@ public class SimpleProcess { String str; while ((str = br.readLine()) != null) { - LOG.debug(aPrefix + str); + LOG.fine(aPrefix + str); aOutput.write(str); } } catch (IOException e) { - LOG.warn(SimpleProcess.this + + LOG.log(Level.FINE, SimpleProcess.this + ": error reading input stream", e); } finally { if (br != null) { try { br.close(); } catch (IOException e) { - LOG.warn("Error closing stream " + aPrefix); + LOG.log(Level.WARNING, "Error closing stream " + aPrefix, e); } } } @@ -182,10 +180,10 @@ public class SimpleProcess { @Override public String toString() { - String fullcmd = ""; + StringBuffer fullcmd = new StringBuffer(); for (String part : cmd) { - fullcmd += (part + " "); + fullcmd.append(part + " "); } return "process(dir = '" + directory + "', cmd = '" + fullcmd + "')";