Added fallback to URI when getting File from Resource. This avoids the IOException that can occur when calling resource.getFile() if that File does not yet exist (as occurs with OsgiBundleResource).
This commit is contained in:
@@ -106,13 +106,19 @@ public class FileReadingMessageSource implements MessageSource<File>, Initializi
|
||||
* Specify the input directory.
|
||||
*/
|
||||
public void setInputDirectory(Resource inputDirectory) {
|
||||
Assert.notNull(inputDirectory, "inputDirectory cannot be null");
|
||||
Assert.notNull(inputDirectory, "inputDirectory must not be null");
|
||||
try {
|
||||
this.inputDirectory = inputDirectory.getFile();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IllegalArgumentException(
|
||||
catch (IOException ioe) {
|
||||
try {
|
||||
// fallback to the URI
|
||||
this.inputDirectory = new File(inputDirectory.getURI());
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalArgumentException(
|
||||
"Unexpected IOException when looking for source directory: " + inputDirectory, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -77,13 +77,22 @@ public class FileWritingMessageHandler extends AbstractReplyProducingMessageHand
|
||||
|
||||
|
||||
public FileWritingMessageHandler(Resource destinationDirectory) {
|
||||
Assert.notNull(destinationDirectory, "Destination directory must not be null.");
|
||||
File dir = null;
|
||||
try {
|
||||
this.destinationDirectory = destinationDirectory.getFile();
|
||||
dir = destinationDirectory.getFile();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IllegalArgumentException(
|
||||
catch (IOException ioe) {
|
||||
try {
|
||||
// fallback to the URI
|
||||
dir = new File(destinationDirectory.getURI());
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalArgumentException(
|
||||
"Unexpected IOException when looking for destination directory: " + destinationDirectory, e);
|
||||
}
|
||||
}
|
||||
this.destinationDirectory = dir;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user