Class ZipMap

  • All Implemented Interfaces:
    java.util.Map<java.lang.String,​ZipMapFile>

    public class ZipMap
    extends java.lang.Object
    implements java.util.Map<java.lang.String,​ZipMapFile>
    The ZipMap provides a convenient way of working with zip files by providing a Map that is backed by a zip file.

    A variety of constructors are available for creating the ZipMap. Once loaded, you can work with file objects as you would work with any normal map. To save changes, you must call writeToFile.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      protected class  ZipMap.ZipMapFileImpl  
      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Constructor Summary

      Constructors 
      Constructor Description
      ZipMap()
      Creates an empty ZipMap.
      ZipMap​(java.io.File zipFile)
      Create a ZipMap with the contents of the given zip file.
      ZipMap​(java.io.InputStream zipFile)
      Create a ZipMap with the contents of the given zip file.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()  
      boolean containsKey​(java.lang.Object key)  
      boolean containsValue​(java.lang.Object value)  
      protected void ensureAllLoaded()  
      java.util.Set<java.util.Map.Entry<java.lang.String,​ZipMapFile>> entrySet()  
      ZipMapFile get​(java.lang.Object key)  
      boolean isEmpty()  
      java.util.Set<java.lang.String> keySet()  
      protected byte[] loadEntry​(java.util.zip.ZipEntry e)  
      ZipMapFile put​(java.lang.String key, byte[] value)
      Convenience method for putting a file into the ZipMap.
      ZipMapFile put​(java.lang.String key, ZipMapFile value)
      Puts an entry into the ZipMap.
      ZipMapFile put​(java.lang.String key, java.io.File value)
      Convenience method for putting a file into the ZipMap.
      void putAll​(java.util.Map<? extends java.lang.String,​? extends ZipMapFile> t)  
      ZipMapFile remove​(java.lang.Object key)  
      int size()  
      java.util.Collection<ZipMapFile> values()  
      void writeToFile​(java.io.File outputFile)
      Write the contents of this ZipMap to a zip file using the supplied File.
      void writeToFile​(java.io.OutputStream outputStream)
      Write the contents of this ZipMap to a zip file using the supplied OutputStream.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
    • Constructor Detail

      • ZipMap

        public ZipMap​(java.io.File zipFile)
               throws java.io.IOException
        Create a ZipMap with the contents of the given zip file. Changes need to be explicitly written using writeToFile(File) or writeToFile(OutputStream).
        Throws:
        java.io.IOException
      • ZipMap

        public ZipMap​(java.io.InputStream zipFile)
               throws java.io.IOException
        Create a ZipMap with the contents of the given zip file. Changes need to be explicitly written using writeToFile(File) or writeToFile(OutputStream).
        Throws:
        java.io.IOException
    • Method Detail

      • loadEntry

        protected byte[] loadEntry​(java.util.zip.ZipEntry e)
      • ensureAllLoaded

        protected void ensureAllLoaded()
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • writeToFile

        public void writeToFile​(java.io.File outputFile)
                         throws java.io.IOException
        Write the contents of this ZipMap to a zip file using the supplied File.
        Parameters:
        outputFile - the file to write to
        Throws:
        java.io.IOException - on failure to write
      • writeToFile

        public void writeToFile​(java.io.OutputStream outputStream)
                         throws java.io.IOException
        Write the contents of this ZipMap to a zip file using the supplied OutputStream.
        Throws:
        java.io.IOException
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Map<java.lang.String,​ZipMapFile>
      • containsKey

        public boolean containsKey​(java.lang.Object key)
        Specified by:
        containsKey in interface java.util.Map<java.lang.String,​ZipMapFile>
      • containsValue

        public boolean containsValue​(java.lang.Object value)
        Specified by:
        containsValue in interface java.util.Map<java.lang.String,​ZipMapFile>
      • entrySet

        @Nonnull
        public java.util.Set<java.util.Map.Entry<java.lang.String,​ZipMapFile>> entrySet()
        Specified by:
        entrySet in interface java.util.Map<java.lang.String,​ZipMapFile>
      • get

        public ZipMapFile get​(java.lang.Object key)
        Specified by:
        get in interface java.util.Map<java.lang.String,​ZipMapFile>
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Map<java.lang.String,​ZipMapFile>
      • keySet

        @Nonnull
        public java.util.Set<java.lang.String> keySet()
        Specified by:
        keySet in interface java.util.Map<java.lang.String,​ZipMapFile>
      • put

        public ZipMapFile put​(java.lang.String key,
                              ZipMapFile value)
        Puts an entry into the ZipMap. Directory names should end with a "/".
        Specified by:
        put in interface java.util.Map<java.lang.String,​ZipMapFile>
      • put

        public ZipMapFile put​(java.lang.String key,
                              java.io.File value)
        Convenience method for putting a file into the ZipMap.
        Parameters:
        key - Name of the file. Example: "hello.txt" or "dir/world.txt".
        value - The file itself. A ZipMapFile will be created from this File.
        Returns:
        The ZipMapFile added to the ZipMap.
      • put

        public ZipMapFile put​(java.lang.String key,
                              byte[] value)
        Convenience method for putting a file into the ZipMap.
        Parameters:
        key - Name of the file. Example: "hello.txt" or "dir/world.txt".
        value - The byte[] itself. A ZipMapFile will be created from this byte[] with directory=false.
        Returns:
        The ZipMapFile added to the ZipMap.
      • putAll

        public void putAll​(java.util.Map<? extends java.lang.String,​? extends ZipMapFile> t)
        Specified by:
        putAll in interface java.util.Map<java.lang.String,​ZipMapFile>
      • remove

        public ZipMapFile remove​(java.lang.Object key)
        Specified by:
        remove in interface java.util.Map<java.lang.String,​ZipMapFile>
      • size

        public int size()
        Specified by:
        size in interface java.util.Map<java.lang.String,​ZipMapFile>
      • values

        @Nonnull
        public java.util.Collection<ZipMapFile> values()
        Specified by:
        values in interface java.util.Map<java.lang.String,​ZipMapFile>