Class ZipResource

All Implemented Interfaces:
Cloneable, Comparable<Resource>, Iterable<Resource>, ResourceCollection

public class ZipResource extends ArchiveResource
A Resource representation of an entry in a zipfile.
Since:
Ant 1.7
  • Constructor Details

    • ZipResource

      public ZipResource()
      Default constructor.
    • ZipResource

      public ZipResource(File z, String enc, ZipEntry e)
      Construct a ZipResource representing the specified entry in the specified zipfile.
      Parameters:
      z - the zipfile as File.
      enc - the encoding used for filenames.
      e - the ZipEntry.
  • Method Details

    • setZipfile

      public void setZipfile(File z)
      Set the zipfile that holds this ZipResource.
      Parameters:
      z - the zipfile as a File.
    • getZipfile

      public File getZipfile()
      Get the zipfile that holds this ZipResource.
      Returns:
      the zipfile as a File.
    • addConfigured

      public void addConfigured(ResourceCollection a)
      Sets the archive that holds this as a single element Resource collection.
      Overrides:
      addConfigured in class ArchiveResource
      Parameters:
      a - the archive as a single element Resource collection.
    • setEncoding

      public void setEncoding(String enc)
      Set the encoding to use with the zipfile.
      Parameters:
      enc - the String encoding.
    • getEncoding

      public String getEncoding()
      Get the encoding to use with the zipfile.
      Returns:
      String encoding.
    • setRefid

      public void setRefid(Reference r)
      Overrides the super version.
      Overrides:
      setRefid in class ArchiveResource
      Parameters:
      r - the Reference to set.
    • getInputStream

      public InputStream getInputStream() throws IOException
      Return an InputStream for reading the contents of this Resource.
      Overrides:
      getInputStream in class Resource
      Returns:
      an InputStream object.
      Throws:
      IOException - if the zip file cannot be opened, or the entry cannot be read.
    • getOutputStream

      public OutputStream getOutputStream() throws IOException
      Get an OutputStream for the Resource.
      Overrides:
      getOutputStream in class Resource
      Returns:
      an OutputStream to which content can be written.
      Throws:
      IOException - if unable to provide the content of this Resource as a stream.
      UnsupportedOperationException - if OutputStreams are not supported for this Resource type.
    • getExtraFields

      public ZipExtraField[] getExtraFields()
      Retrieves extra fields.
      Returns:
      an array of the extra fields
      Since:
      Ant 1.8.0
    • getMethod

      public int getMethod()
      The compression method that has been used.
      Returns:
      int
      Since:
      Ant 1.8.0
    • getZipEntryStream

      public static InputStream getZipEntryStream(ZipFile zipFile, String zipEntry) throws IOException
      Return an InputStream for reading the contents of a ZipEntry with autoclose.
      Parameters:
      zipFile - a org.apache.tools.zip.ZipFile
      zipEntry - String a name of a zip entry
      Returns:
      an InputStream object
      Throws:
      IOException - if the entry cannot be read
    • fetchEntry

      protected void fetchEntry()
      fetches information from the named entry inside the archive.
      Specified by:
      fetchEntry in class ArchiveResource
    • getRef

      protected ZipResource getRef()
      Description copied from class: Resource
      Perform the check for circular references and return the referenced Resource.
      Overrides:
      getRef in class ArchiveResource
      Returns:
      Resource.