FileDocCategorySizeDatePackage
BUnzip2.javaAPI DocApache Ant 1.703807Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.taskdefs

BUnzip2

public class BUnzip2 extends Unpack
Expands a file that has been compressed with the BZIP2 algorithm. Normally used to compress non-compressed archives such as TAR files.
since
Ant 1.5
ant.task
category="packaging"

Fields Summary
private static final String
DEFAULT_EXTENSION
Constructors Summary
Methods Summary
protected voidextract()
Do the unbzipping.

        if (source.lastModified() > dest.lastModified()) {
            log("Expanding " + source.getAbsolutePath() + " to "
                + dest.getAbsolutePath());

            FileOutputStream out = null;
            CBZip2InputStream zIn = null;
            InputStream fis = null;
            BufferedInputStream bis = null;
            try {
                out = new FileOutputStream(dest);
                fis = srcResource.getInputStream();
                bis = new BufferedInputStream(fis);
                int b = bis.read();
                if (b != 'B") {
                    throw new BuildException("Invalid bz2 file.", getLocation());
                }
                b = bis.read();
                if (b != 'Z") {
                    throw new BuildException("Invalid bz2 file.", getLocation());
                }
                zIn = new CBZip2InputStream(bis);
                byte[] buffer = new byte[8 * 1024];
                int count = 0;
                do {
                    out.write(buffer, 0, count);
                    count = zIn.read(buffer, 0, buffer.length);
                } while (count != -1);
            } catch (IOException ioe) {
                String msg = "Problem expanding bzip2 " + ioe.getMessage();
                throw new BuildException(msg, ioe, getLocation());
            } finally {
                FileUtils.close(bis);
                FileUtils.close(fis);
                FileUtils.close(out);
                FileUtils.close(zIn);
            }
        }
    
protected java.lang.StringgetDefaultExtension()
Get the default extension.

return
the string ".bz2"


                 
       
        return DEFAULT_EXTENSION;
    
protected booleansupportsNonFileResources()
Whether this task can deal with non-file resources.

This implementation returns true only if this task is <gunzip>. Any subclass of this class that also wants to support non-file resources needs to override this method. We need to do so for backwards compatibility reasons since we can't expect subclasses to support resources.

return
true if this class supports non file resources.
since
Ant 1.7

        return getClass().equals(BUnzip2.class);