VASSAL.tools
Class DataArchive

java.lang.Object
  |
  +--java.lang.ClassLoader
        |
        +--java.security.SecureClassLoader
              |
              +--VASSAL.tools.DataArchive
Direct Known Subclasses:
ArchiveWriter

public class DataArchive
extends java.security.SecureClassLoader

Wrapper around a Zip archive with methods to cache images


Inner Class Summary
static class DataArchive.Scaler
           
 
Field Summary
protected  java.util.zip.ZipFile archive
           
protected  java.util.Vector extensions
           
static java.lang.String IMAGE_DIR
           
protected  java.lang.String[] imageNames
           
 
Constructor Summary
protected DataArchive()
           
  DataArchive(java.lang.String zipName)
           
 
Method Summary
 void addExtension(DataArchive ext)
          DataArchives can extend other archives.
protected  java.lang.Class findClass(java.lang.String name)
           
static java.awt.Image findImage(java.io.File zip, java.lang.String file)
           
static java.awt.Image findImage(java.io.File dir, java.lang.String zip, java.lang.String file)
           
 java.util.zip.ZipFile getArchive()
           
static byte[] getBytes(java.io.InputStream in)
          Read all available bytes from the given InputStream
 java.awt.Image getCachedImage(java.lang.String file)
           
static java.io.InputStream getFileStream(java.io.File zip, java.lang.String file)
           
static java.io.InputStream getFileStream(java.io.File dir, java.lang.String zipName, java.lang.String file)
           
 java.io.InputStream getFileStream(java.lang.String file)
          Get an inputstream from the given filename in the archive
static java.awt.Image getImage(java.io.InputStream in)
           
static java.awt.Rectangle getImageBounds(java.awt.Image im)
           
 java.lang.String[] getImageNames()
           
 java.lang.String getName()
           
protected  java.security.PermissionCollection getPermissions(java.security.CodeSource codesource)
           
 java.awt.Image getScaledImage(java.awt.Image base, double scale)
          Return a scaled instance of the image.
 java.net.URL getURL(java.lang.String fileName)
           
 ArchiveWriter getWriter()
          Return the writeable instance of DataArchive, either this or one of its extensions (At most one archive should be being edited at a time)
protected  boolean isNameCacheStale()
           
protected  void listImageNames(java.util.Vector v)
          Place the names of the image files stored in this DataArchive into the argument Vector
 java.lang.Class loadClass(java.lang.String name, boolean resolve)
           
 void unCacheImage(java.lang.String file)
           
 
Methods inherited from class java.security.SecureClassLoader
defineClass
 
Methods inherited from class java.lang.ClassLoader
defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findResource, findResources, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, resolveClass, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

archive

protected java.util.zip.ZipFile archive

extensions

protected java.util.Vector extensions

imageNames

protected java.lang.String[] imageNames

IMAGE_DIR

public static final java.lang.String IMAGE_DIR
Constructor Detail

DataArchive

protected DataArchive()

DataArchive

public DataArchive(java.lang.String zipName)
            throws java.io.IOException
Method Detail

getName

public java.lang.String getName()

getArchive

public java.util.zip.ZipFile getArchive()

findImage

public static java.awt.Image findImage(java.io.File zip,
                                       java.lang.String file)
                                throws java.io.IOException

getFileStream

public static java.io.InputStream getFileStream(java.io.File zip,
                                                java.lang.String file)
                                         throws java.io.IOException

findImage

public static java.awt.Image findImage(java.io.File dir,
                                       java.lang.String zip,
                                       java.lang.String file)
                                throws java.io.IOException

getCachedImage

public java.awt.Image getCachedImage(java.lang.String file)
                              throws java.io.IOException

getScaledImage

public java.awt.Image getScaledImage(java.awt.Image base,
                                     double scale)
Return a scaled instance of the image. Each zoom factory of each image is stored in a cache
Parameters:
base -  
scale -  
Returns:
 

getImageBounds

public static java.awt.Rectangle getImageBounds(java.awt.Image im)
Parameters:
im -  
Returns:
the boundaries of this image, where (0,0) is the center of the image

unCacheImage

public void unCacheImage(java.lang.String file)

getImage

public static java.awt.Image getImage(java.io.InputStream in)
                               throws java.io.IOException

getBytes

public static byte[] getBytes(java.io.InputStream in)
                       throws java.io.IOException
Read all available bytes from the given InputStream

getFileStream

public java.io.InputStream getFileStream(java.lang.String file)
                                  throws java.io.IOException
Get an inputstream from the given filename in the archive

getURL

public java.net.URL getURL(java.lang.String fileName)
                    throws java.io.IOException

addExtension

public void addExtension(DataArchive ext)
DataArchives can extend other archives. The extensions will be searched for data if not found in the parent archive
Parameters:
ext - the extension

getWriter

public ArchiveWriter getWriter()
Return the writeable instance of DataArchive, either this or one of its extensions (At most one archive should be being edited at a time)
Returns:
 

getFileStream

public static java.io.InputStream getFileStream(java.io.File dir,
                                                java.lang.String zipName,
                                                java.lang.String file)

loadClass

public java.lang.Class loadClass(java.lang.String name,
                                 boolean resolve)
                          throws java.lang.ClassNotFoundException
Overrides:
loadClass in class java.lang.ClassLoader

getPermissions

protected java.security.PermissionCollection getPermissions(java.security.CodeSource codesource)
Overrides:
getPermissions in class java.security.SecureClassLoader

findClass

protected java.lang.Class findClass(java.lang.String name)
                             throws java.lang.ClassNotFoundException
Overrides:
findClass in class java.lang.ClassLoader

getImageNames

public java.lang.String[] getImageNames()

isNameCacheStale

protected boolean isNameCacheStale()

listImageNames

protected void listImageNames(java.util.Vector v)
Place the names of the image files stored in this DataArchive into the argument Vector
Parameters:
v -