Methods Summary |
---|
public void | add(org.apache.tools.ant.types.optional.image.ImageOperation instr)Add an ImageOperation to chain.
addImageOperation(instr);
|
public void | addDraw(org.apache.tools.ant.types.optional.image.Draw instr)Add a Draw ImageOperation to the chain. DrawOperation
DataType objects can be nested inside the Draw object.
instructions.add(instr);
|
public void | addFileset(org.apache.tools.ant.types.FileSet set)Add a set of files to be deleted.
// CheckStyle:MemberNameCheck ON
// CheckStyle:VisibilityModifier ON
filesets.addElement(set);
|
public void | addImageOperation(org.apache.tools.ant.types.optional.image.ImageOperation instr)Add an ImageOperation to chain.
instructions.add(instr);
|
public void | addRotate(org.apache.tools.ant.types.optional.image.Rotate instr)Add a Rotate ImageOperation to the chain.
instructions.add(instr);
|
public void | addScale(org.apache.tools.ant.types.optional.image.Scale instr)Add a Scale ImageOperation to the chain.
instructions.add(instr);
|
public void | execute()Executes the Task.
validateAttributes();
try {
DirectoryScanner ds = null;
String[] files = null;
ArrayList filesList = new ArrayList();
// deal with specified srcDir
if (srcDir != null) {
ds = super.getDirectoryScanner(srcDir);
files = ds.getIncludedFiles();
for (int i = 0; i < files.length; i++) {
filesList.add(new File(srcDir, files[i]));
}
}
// deal with the filesets
for (int i = 0; i < filesets.size(); i++) {
FileSet fs = (FileSet) filesets.elementAt(i);
ds = fs.getDirectoryScanner(getProject());
files = ds.getIncludedFiles();
File fromDir = fs.getDir(getProject());
for (int j = 0; j < files.length; j++) {
filesList.add(new File(fromDir, files[j]));
}
}
if (!overwrite) {
// remove any files that shouldn't be overwritten.
ArrayList filesToRemove = new ArrayList();
for (Iterator i = filesList.iterator(); i.hasNext();) {
File f = (File) i.next();
File newFile = new File(destDir, f.getName());
if (newFile.exists()) {
filesToRemove.add(f);
}
}
filesList.removeAll(filesToRemove);
}
// iterator through all the files and process them.
for (Iterator i = filesList.iterator(); i.hasNext();) {
File file = (File) i.next();
processFile(file);
if (garbage_collect) {
System.gc();
}
}
} catch (Exception err) {
err.printStackTrace();
throw new BuildException(err.getMessage());
}
|
public void | processFile(java.io.File file)Executes all the chained ImageOperations on the file
specified.
try {
log("Processing File: " + file.getAbsolutePath());
FileSeekableStream input = new FileSeekableStream(file);
PlanarImage image = JAI.create("stream", input);
for (int i = 0; i < instructions.size(); i++) {
Object instr = instructions.elementAt(i);
if (instr instanceof TransformOperation) {
image = ((TransformOperation) instr)
.executeTransformOperation(image);
} else {
log("Not a TransformOperation: " + instr);
}
}
input.close();
if (str_encoding.toLowerCase().equals("jpg")) {
str_encoding = "JPEG";
} else if (str_encoding.toLowerCase().equals("tif")) {
str_encoding = "TIFF";
}
if (destDir == null) {
destDir = srcDir;
}
File newFile = new File(destDir, file.getName());
if ((overwrite && newFile.exists()) && (!newFile.equals(file))) {
newFile.delete();
}
FileOutputStream stream = new FileOutputStream(newFile);
JAI.create("encode", image, stream, str_encoding.toUpperCase(),
null);
stream.flush();
stream.close();
} catch (IOException err) {
if (!failonerror) {
log("Error processing file: " + err);
} else {
throw new BuildException(err);
}
} catch (java.lang.RuntimeException rerr) {
if (!failonerror) {
log("Error processing file: " + rerr);
} else {
throw new BuildException(rerr);
}
}
|
public void | setDestDir(java.io.File destDir)Set the destination directory for manipulated images.
this.destDir = destDir;
|
public void | setEncoding(java.lang.String encoding)Set the image encoding type.
See this table in the JAI Programming Guide.
str_encoding = encoding;
|
public void | setFailOnError(boolean failonerror)Set whether to fail on error.
If false, note errors to the output but keep going.
this.failonerror = failonerror;
|
public void | setGc(boolean gc)Set whether to invoke Garbage Collection after each image processed.
Defaults to false.
garbage_collect = gc;
|
public void | setOverwrite(boolean overwrite)Set whether to overwrite a file if there is a naming conflict.
this.overwrite = overwrite;
|
public void | setSrcdir(java.io.File srcDir)Set the source dir to find the image files.
this.srcDir = srcDir;
|
protected void | validateAttributes()Ensure we have a consistent and legal set of attributes, and set
any internal flags necessary based on different combinations
of attributes.
if (srcDir == null && filesets.size() == 0) {
throw new BuildException("Specify at least one source"
+ "--a srcDir or a fileset.");
}
if (srcDir == null && destDir == null) {
throw new BuildException("Specify the destDir, or the srcDir.");
}
|