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:
Mark Fisher
2009-07-16 13:26:30 +00:00
parent 64ef8c3ab5
commit f568344e59
2 changed files with 21 additions and 6 deletions

View File

@@ -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);
}
}
}

View File

@@ -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;
}