You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by cm...@apache.org on 2009/06/26 17:12:24 UTC
svn commit: r788732 -
/camel/trunk/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamConsumer.java
Author: cmoulliard
Date: Fri Jun 26 15:12:24 2009
New Revision: 788732
URL: http://svn.apache.org/viewvc?rev=788732&view=rev
Log:
Correct the NPE at the line 83 of StreamConsumer.java (occurring if the endpoint can read stream from a file), add a test in the method resolveStreamFromUrl to check if the file is readable (be careful this test does not work on Windows when the path contains signs ${}) - no solution found for the moment
Modified:
camel/trunk/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamConsumer.java
Modified: camel/trunk/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamConsumer.java?rev=788732&r1=788731&r2=788732&view=diff
==============================================================================
--- camel/trunk/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamConsumer.java (original)
+++ camel/trunk/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamConsumer.java Fri Jun 26 15:12:24 2009
@@ -19,6 +19,7 @@
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -80,9 +81,10 @@
@Override
public void doStop() throws Exception {
// important: do not close the stream as it will close the standard system.in etc.
- executor.shutdownNow();
- executor = null;
- super.doStop();
+ ObjectHelper.notNull(executor, "Executor");
+ executor.shutdownNow();
+ executor = null;
+ super.doStop();
}
public void run() {
@@ -189,12 +191,22 @@
private InputStream resolveStreamFromFile() throws IOException {
String fileName = endpoint.getFileName();
ObjectHelper.notEmpty(fileName, "fileName");
+
+ FileInputStream fileStream;
+
+ File file = new File(fileName);
+
if (LOG.isDebugEnabled()) {
- LOG.debug("About to read from file: " + fileName);
+ LOG.debug("File to be scanned : " + file.getName() + ", path : " + file.getAbsolutePath());
}
- File file = new File(fileName);
- return new FileInputStream(file);
+ if ( file.canRead() ) {
+ fileStream = new FileInputStream(file);
+ } else {
+ throw new IllegalArgumentException(INVALID_URI);
+ }
+
+ return fileStream;
}
private void validateUri(String uri) throws IllegalArgumentException {