FileDocCategorySizeDatePackage
TarResource.javaAPI DocApache Ant 1.705713Wed Dec 13 06:16:22 GMT 2006org.apache.tools.ant.types.resources

TarResource

public class TarResource extends ArchiveResource
A Resource representation of an entry in a tar archive.
since
Ant 1.7

Fields Summary
private String
userName
private String
groupName
private int
uid
private int
gid
Constructors Summary
public TarResource()
Default constructor.


           
      
    
public TarResource(File a, org.apache.tools.tar.TarEntry e)
Construct a TarResource representing the specified entry in the specified archive.

param
a the archive as File.
param
e the TarEntry.

        super(a, true);
        setEntry(e);
    
public TarResource(org.apache.tools.ant.types.Resource a, org.apache.tools.tar.TarEntry e)
Construct a TarResource representing the specified entry in the specified archive.

param
a the archive as Resource.
param
e the TarEntry.

        super(a, true);
        setEntry(e);
    
Methods Summary
protected voidfetchEntry()
fetches information from the named entry inside the archive.

        Resource archive = getArchive();
        TarInputStream i = null;
        try {
            i = new TarInputStream(archive.getInputStream());
            TarEntry te = null;
            while ((te = i.getNextEntry()) != null) {
                if (te.getName().equals(getName())) {
                    setEntry(te);
                    return;
                }
            }
        } catch (IOException e) {
            log(e.getMessage(), Project.MSG_DEBUG);
            throw new BuildException(e);
        } finally {
            if (i != null) {
                FileUtils.close(i);
            }
        }
        setEntry(null);
    
public intgetGid()

return
the uid for the tar entry

        if (isReference()) {
            return ((TarResource) getCheckedRef()).getGid();
        }
        return uid;
    
public java.lang.StringgetGroup()

return
the group name for the tar entry

        if (isReference()) {
            return ((TarResource) getCheckedRef()).getGroup();
        }
        return groupName;
    
public java.io.InputStreamgetInputStream()
Return an InputStream for reading the contents of this Resource.

return
an InputStream object.
throws
IOException if the tar file cannot be opened, or the entry cannot be read.

        if (isReference()) {
            return ((Resource) getCheckedRef()).getInputStream();
        }
        Resource archive = getArchive();
        final TarInputStream i = new TarInputStream(archive.getInputStream());
        TarEntry te = null;
        while ((te = i.getNextEntry()) != null) {
            if (te.getName().equals(getName())) {
                return i;
            }
        }

        FileUtils.close(i);
        throw new BuildException("no entry " + getName() + " in "
                                 + getArchive());
    
public java.io.OutputStreamgetOutputStream()
Get an OutputStream for the Resource.

return
an OutputStream to which content can be written.
throws
IOException if unable to provide the content of this Resource as a stream.
throws
UnsupportedOperationException if OutputStreams are not supported for this Resource type.

        if (isReference()) {
            return ((Resource) getCheckedRef()).getOutputStream();
        }
        throw new UnsupportedOperationException(
            "Use the tar task for tar output.");
    
public intgetUid()

return
the uid for the tar entry

        if (isReference()) {
            return ((TarResource) getCheckedRef()).getUid();
        }
        return uid;
    
public java.lang.StringgetUserName()

return
the user name for the tar entry

        if (isReference()) {
            return ((TarResource) getCheckedRef()).getUserName();
        }
        return userName;
    
private voidsetEntry(org.apache.tools.tar.TarEntry e)

        if (e == null) {
            setExists(false);
            return;
        }
        setName(e.getName());
        setExists(true);
        setLastModified(e.getModTime().getTime());
        setDirectory(e.isDirectory());
        setSize(e.getSize());
        setMode(e.getMode());
        userName = e.getUserName();
        groupName = e.getGroupName();
        uid = e.getUserId();
        gid = e.getGroupId();