Author: ningjiang
Date: Thu Oct 27 11:08:21 2011
New Revision: 1189704

URL: http://svn.apache.org/viewvc?rev=1189704&view=rev
Log:
Merged revisions 1189693 via svnmerge from 
https://svn.apache.org/repos/asf/camel/trunk

........
  r1189693 | ningjiang | 2011-10-27 17:50:09 +0800 (Thu, 27 Oct 2011) | 1 line
  
  CAMEL-4581 fix the NPE issue of stream endpoint
........

Modified:
    camel/branches/camel-2.8.x/   (props changed)
    
camel/branches/camel-2.8.x/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamEndpoint.java
    
camel/branches/camel-2.8.x/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamProducer.java

Propchange: camel/branches/camel-2.8.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Oct 27 11:08:21 2011
@@ -1 +1 @@
-/camel/trunk:1186106,1186625,1186772,1187221,1187485,1187882,1187893,1188070-1188085,1188642,1188674,1188879,1188881,1189600,1189681
+/camel/trunk:1186106,1186625,1186772,1187221,1187485,1187882,1187893,1188070-1188085,1188642,1188674,1188879,1188881,1189600,1189681,1189693

Propchange: camel/branches/camel-2.8.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: 
camel/branches/camel-2.8.x/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamEndpoint.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamEndpoint.java?rev=1189704&r1=1189703&r2=1189704&view=diff
==============================================================================
--- 
camel/branches/camel-2.8.x/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamEndpoint.java
 (original)
+++ 
camel/branches/camel-2.8.x/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamEndpoint.java
 Thu Oct 27 11:08:21 2011
@@ -40,6 +40,7 @@ public class StreamEndpoint extends Defa
     private long promptDelay;
     private long initialPromptDelay = 2000;
     private int groupLines;
+    private Charset charset;
 
     public StreamEndpoint(String endpointUri, Component component) throws 
Exception {
         super(endpointUri, component);
@@ -151,11 +152,19 @@ public class StreamEndpoint extends Defa
     public void setGroupLines(int groupLines) {
         this.groupLines = groupLines;
     }
+    
+    public Charset getCharset() {
+        return charset;
+    }
 
     // Implementations
     //-------------------------------------------------------------------------
 
-    Charset getCharset() {
+    protected void doStart() throws Exception {
+        charset = loadCharset();
+    }
+    
+    Charset loadCharset() {
         if (encoding == null) {
             encoding = Charset.defaultCharset().name();
             LOG.debug("No encoding parameter using default charset: {}", 
encoding);

Modified: 
camel/branches/camel-2.8.x/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamProducer.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamProducer.java?rev=1189704&r1=1189703&r2=1189704&view=diff
==============================================================================
--- 
camel/branches/camel-2.8.x/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamProducer.java
 (original)
+++ 
camel/branches/camel-2.8.x/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamProducer.java
 Thu Oct 27 11:08:21 2011
@@ -45,8 +45,6 @@ public class StreamProducer extends Defa
     private static final String TYPES = "out,err,file,header,url";
     private static final String INVALID_URI = "Invalid uri, valid form: 
'stream:{" + TYPES + "}'";
     private static final List<String> TYPES_LIST = 
Arrays.asList(TYPES.split(","));
-    private OutputStream outputStream = System.out;
-    private boolean isSystemStream;
     private StreamEndpoint endpoint;
     private String uri;
 
@@ -56,16 +54,10 @@ public class StreamProducer extends Defa
         validateUri(uri);
     }
 
-    @Override
-    public void doStop() throws Exception {
-        closeStream();
-        super.doStop();
-    }
-
     public void process(Exchange exchange) throws Exception {
         delay(endpoint.getDelay());
-
-        isSystemStream = false;
+        OutputStream outputStream = System.out;         
+        boolean isSystemStream = false;
         if ("out".equals(uri)) {
             isSystemStream = true;
             outputStream = System.out;
@@ -80,8 +72,8 @@ public class StreamProducer extends Defa
             outputStream = resolveStreamFromUrl();
         }
 
-        writeToStream(exchange);
-        closeStream();
+        writeToStream(outputStream, exchange);
+        closeStream(outputStream, isSystemStream);
     }
 
     private OutputStream resolveStreamFromUrl() throws IOException {
@@ -116,7 +108,7 @@ public class StreamProducer extends Defa
         Thread.sleep(ms);
     }
 
-    private void writeToStream(Exchange exchange) throws IOException, 
CamelExchangeException {
+    private void writeToStream(OutputStream outputStream, Exchange exchange) 
throws IOException, CamelExchangeException {
         Object body = exchange.getIn().getBody();
 
         // if not a string then try as byte array first
@@ -142,12 +134,11 @@ public class StreamProducer extends Defa
         bw.flush();
     }
 
-    private void closeStream() throws Exception {
+    private void closeStream(OutputStream outputStream, boolean 
isSystemStream) throws Exception {
         // important: do not close the writer on a standard system.out etc.
         if (outputStream != null && !isSystemStream) {
             outputStream.close();
         }
-        outputStream = null;
     }
 
     private void validateUri(String uri) throws Exception {


Reply via email to