* Convert file name into an absolute path in saveAs().
* Build directories in saveAs() if they don't exist, fixing bug 324 <http://helma.org/bugs/show_bug.cgi?id=324>
This commit is contained in:
parent
4b23a48c14
commit
a35d3ea425
1 changed files with 17 additions and 1 deletions
|
@ -577,7 +577,7 @@ public class ImageWrapper {
|
|||
*/
|
||||
public void saveAs(String filename, float quality, boolean alpha)
|
||||
throws IOException {
|
||||
generator.write(this, filename, quality, alpha);
|
||||
generator.write(this, checkFilename(filename), quality, alpha);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -660,4 +660,20 @@ public class ImageWrapper {
|
|||
else
|
||||
return bi.getRGB(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method to be used by write().
|
||||
* Converts file name to absolute path and creates parent directories.
|
||||
* @param filename the file name
|
||||
* @return the absolute path for the file name
|
||||
* @throws IOException if missing directories could not be created
|
||||
*/
|
||||
String checkFilename(String filename) throws IOException {
|
||||
File file = new File(filename).getAbsoluteFile();
|
||||
File parent = file.getParentFile();
|
||||
if (parent != null && !parent.exists() && !parent.mkdirs()) {
|
||||
throw new IOException("Error creating directories for " + filename);
|
||||
}
|
||||
return file.getPath();
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue