[Generator-rt-devel] generator_runtime/src/java/generator/runtime/fileupload/transform LoggingStre
Brought to you by:
rickknowles
|
From: Rick K. <ric...@us...> - 2010-04-05 02:31:50
|
Update of /cvsroot/generator-rt/generator_runtime/src/java/generator/runtime/fileupload/transform In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv11801/src/java/generator/runtime/fileupload/transform Modified Files: ImageMagickImageResizer.java Added Files: LoggingStreamConsumer.java Log Message: A bunch of translation tag changes and addons to the velocity mail rendering. A fix to the DBConnectionPool keep alive process also included. --- NEW FILE: LoggingStreamConsumer.java --- /* * Generator Runtime Servlet Framework * Copyright (C) 2004 Rick Knowles * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public License * Version 2 as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License Version 2 for more details. * * You should have received a copy of the GNU Library General Public License * Version 2 along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package generator.runtime.fileupload.transform; import generator.runtime.log.Log; import generator.runtime.log.LogManager; import java.io.IOException; import java.io.InputStream; /** * Logs the output of an stream, used primarily to track the output of jvm spawned system processes * * @author <a href="mailto:ric...@ho...">Rick Knowles</a> * @version $Id: LoggingStreamConsumer.java,v 1.1 2010/04/05 02:31:41 rickknowles Exp $ */ public class LoggingStreamConsumer implements Runnable { private final Log log = LogManager.getLog(ImageMagickImageResizer.class); private String id; private InputStream in; private String encoding; public LoggingStreamConsumer(String id, InputStream in, String encoding) { this.id = id; this.in = in; this.encoding = encoding; } public void run() { byte buffer[] = new byte[4096]; int read = 0; try { while ((read = in.read(buffer)) != -1) { log.debug(new String(buffer, 0, read, encoding)); } } catch (IOException err) { log.error("Error in stream consumer (" + id + ")", err); } log.fullDebug("Stream consumer finished (" + id + ")"); try { in.close(); } catch (IOException err) { log.error("Error closing stream (" + id + ")", err); } } } Index: ImageMagickImageResizer.java =================================================================== RCS file: /cvsroot/generator-rt/generator_runtime/src/java/generator/runtime/fileupload/transform/ImageMagickImageResizer.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ImageMagickImageResizer.java 21 Oct 2008 10:52:47 -0000 1.2 --- ImageMagickImageResizer.java 5 Apr 2010 02:31:41 -0000 1.3 *************** *** 26,30 **** import java.io.File; import java.io.IOException; - import java.io.InputStream; import java.util.Arrays; --- 26,29 ---- *************** *** 78,83 **** log.debug("Launching image resize process (" + this.id + "): " + Arrays.asList(resizeCmdArgs)); //comment out Process p = Runtime.getRuntime().exec(resizeCmdArgs); ! Thread thStdOut = new Thread(new LoggingStreamConsumer(p.getInputStream(), logEncoding)); ! Thread thStdErr = new Thread(new LoggingStreamConsumer(p.getErrorStream(), logEncoding)); thStdOut.setDaemon(true); thStdOut.start(); --- 77,82 ---- log.debug("Launching image resize process (" + this.id + "): " + Arrays.asList(resizeCmdArgs)); //comment out Process p = Runtime.getRuntime().exec(resizeCmdArgs); ! Thread thStdOut = new Thread(new LoggingStreamConsumer(this.id + ":stdout", p.getInputStream(), logEncoding)); ! Thread thStdErr = new Thread(new LoggingStreamConsumer(this.id + ":stderr", p.getErrorStream(), logEncoding)); thStdOut.setDaemon(true); thStdOut.start(); *************** *** 91,121 **** } } - - class LoggingStreamConsumer implements Runnable { - private InputStream in; - private String encoding; - - LoggingStreamConsumer(InputStream in, String encoding) { - this.in = in; - this.encoding = encoding; - } - - public void run() { - byte buffer[] = new byte[4096]; - int read = 0; - try { - while ((read = in.read(buffer)) != -1) { - log.debug(new String(buffer, 0, read, encoding)); - } - } catch (IOException err) { - log.error("Error in stream consumer (" + id + ")", err); - } - log.fullDebug("Stream consumer finished (" + id + ")"); - try { - in.close(); - } catch (IOException err) { - log.error("Error closing stream (" + id + ")", err); - } - } - } } --- 90,92 ---- |