org.apache.wicket.util.resource
Class ZipResourceStream

java.lang.Object
  extended by org.apache.wicket.util.resource.AbstractResourceStream
      extended by org.apache.wicket.util.resource.ZipResourceStream
All Implemented Interfaces:
java.io.Closeable, java.io.Serializable, IClusterable, IResourceStream, IModifiable

public class ZipResourceStream
extends AbstractResourceStream

An IResourceStream that ZIPs a directory's contents on the fly

NOTE 1. As a future improvement, cache a map of generated ZIP files for every directory and use a Watcher to detect modifications in this directory. Using ehcache would be good for that, but it's not in Wicket dependencies yet. No caching of the generated ZIP files is done yet.

NOTE 2. As a future improvement, implement getLastModified() and request ResourceStreamRequestTarget to generate Last-Modified and Expires HTTP headers. No HTTP cache headers are provided yet. See WICKET-385

Author:
Jean-Baptiste Quenot
See Also:
Serialized Form

Constructor Summary
ZipResourceStream(File dir)
          Construct.
ZipResourceStream(File dir, boolean recursive)
          Construct.
 
Method Summary
 void close()
          Closes the resource.
 java.lang.String getContentType()
          Gets the mime type of this resource
 java.io.InputStream getInputStream()
          Gets the resource stream.
 Time lastModifiedTime()
          Gets the last time this modifiable thing changed.
 Bytes length()
          Gets the size of this resource
 
Methods inherited from class org.apache.wicket.util.resource.AbstractResourceStream
getLocale, getStyle, getVariation, setLocale, setStyle, setVariation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ZipResourceStream

public ZipResourceStream(File dir,
                         boolean recursive)
Construct.

Parameters:
dir - The directory where to look for files. The directory itself will not be included in the ZIP.
recursive - If true, all subdirs will be zipped as well

ZipResourceStream

public ZipResourceStream(File dir)
Construct. Until Wicket 1.4-RC3 recursive zip was not supported. In order not to change the behavior, using this constructor will default to recursive == false.

Parameters:
dir - The directory where to look for files. The directory itself will not be included in the ZIP.
Method Detail

close

public void close()
           throws java.io.IOException
Description copied from interface: IResourceStream
Closes the resource. Normally, this includes closing any underlying input stream returned by getInputStream().

Throws:
java.io.IOException
See Also:
IResourceStream.close()

getContentType

public java.lang.String getContentType()
Description copied from interface: IResourceStream
Gets the mime type of this resource

Specified by:
getContentType in interface IResourceStream
Overrides:
getContentType in class AbstractResourceStream
Returns:
The mime type of this resource, such as "image/jpeg" or "text/html". Return null to let ResourceStreamRequestHandler handle the Content-Type automatically
See Also:
IResourceStream.getContentType()

getInputStream

public java.io.InputStream getInputStream()
                                   throws ResourceStreamNotFoundException
Description copied from interface: IResourceStream
Gets the resource stream. You should not directly close this stream. Instead call the close() method on IResourceStream.

Returns:
Returns the inputStream.
Throws:
ResourceStreamNotFoundException
See Also:
IResourceStream.getInputStream()

length

public Bytes length()
Description copied from interface: IResourceStream
Gets the size of this resource

Specified by:
length in interface IResourceStream
Overrides:
length in class AbstractResourceStream
Returns:
The size of this resource in the number of bytes, or null if unknown
See Also:
AbstractResourceStream.length()

lastModifiedTime

public Time lastModifiedTime()
Description copied from interface: IModifiable
Gets the last time this modifiable thing changed.

Specified by:
lastModifiedTime in interface IModifiable
Overrides:
lastModifiedTime in class AbstractResourceStream
Returns:
the last modification Time or null if that information is not available
See Also:
AbstractResourceStream.lastModifiedTime()


Copyright © 2006-2011 Apache Software Foundation. All Rights Reserved.