Class ZipResource

All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable<Resource>, java.lang.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​(java.io.File z, java.lang.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​(java.io.File z)
      Set the zipfile that holds this ZipResource.
      Parameters:
      z - the zipfile as a File.
    • getZipfile

      public java.io.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​(java.lang.String enc)
      Set the encoding to use with the zipfile.
      Parameters:
      enc - the String encoding.
    • getEncoding

      public java.lang.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 java.io.InputStream getInputStream() throws java.io.IOException
      Return an InputStream for reading the contents of this Resource.
      Overrides:
      getInputStream in class Resource
      Returns:
      an InputStream object.
      Throws:
      java.io.IOException - if the zip file cannot be opened, or the entry cannot be read.
    • getOutputStream

      public java.io.OutputStream getOutputStream() throws java.io.IOException
      Get an OutputStream for the Resource.
      Overrides:
      getOutputStream in class Resource
      Returns:
      an OutputStream to which content can be written.
      Throws:
      java.io.IOException - if unable to provide the content of this Resource as a stream.
      java.lang.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 java.io.InputStream getZipEntryStream​(ZipFile zipFile, java.lang.String zipEntry) throws java.io.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:
      java.io.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.