NASA World Wind

gov.nasa.worldwind.ogc.kml.io
Class KMZFile

java.lang.Object
  extended by gov.nasa.worldwind.ogc.kml.io.KMZFile
All Implemented Interfaces:
KMLDoc

public class KMZFile
extends Object
implements KMLDoc

Implements the KMLDoc interface for KMZ files located within a computer's file system.

Note: This class does not yet resolve references to files in other KMZ archives. For example, it does not resolve references like this: ../other.kmz/file.png.


Field Summary
protected  Map<String,File> files
          A mapping of the files in the KMZ file to their location in the temporary directory.
protected  File tempDir
          The directory to hold files copied from the KMZ file.
protected  ZipFile zipFile
          The ZipFile reference specified to the constructor.
 
Constructor Summary
KMZFile(File file)
          Construct a KMZFile instance.
 
Method Summary
protected  String copyEntryToTempDir(ZipEntry entry)
          Copies a zip entry to a temporary file.
 InputStream getKMLStream()
          Returns an InputStream to the first KML file in the KMZ file.
 String getSupportFilePath(String path)
          Returns an absolute path to a specified file within the KMZ file.
 InputStream getSupportFileStream(String path)
          Returns an InputStream to a specified file within the KMZ file.
 ZipFile getZipFile()
          Returns the file file specified to the constructor as a ZipFile.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

files

protected Map<String,File> files
A mapping of the files in the KMZ file to their location in the temporary directory.


tempDir

protected File tempDir
The directory to hold files copied from the KMZ file. The directory and the files copied there are temporary.


zipFile

protected ZipFile zipFile
The ZipFile reference specified to the constructor.

Constructor Detail

KMZFile

public KMZFile(File file)
        throws IOException
Construct a KMZFile instance.

Parameters:
file - path to the KMZ file.
Throws:
IOException - if an error occurs while attempting to query or open the file.
IllegalArgumentException - if the specified file is null.
ZipException - if a Zip error occurs.
Method Detail

copyEntryToTempDir

protected String copyEntryToTempDir(ZipEntry entry)
                             throws IOException
Copies a zip entry to a temporary file. This method should only be called by a synchronized public method.

Parameters:
entry - the entry to copy.
Returns:
the path to the file, or null if the entry is a directory or the temporary directory cannot be created.
Throws:
IOException - if an error occurs during the copy.

getKMLStream

public InputStream getKMLStream()
                         throws IOException
Returns an InputStream to the first KML file in the KMZ file.

Specified by:
getKMLStream in interface KMLDoc
Returns:
an input stream positioned to the first KML file in the KMZ file, or null if the KMZ file does not contain a KML file.
Throws:
IOException - if an error occurs while attempting to create or open the input stream.

getSupportFilePath

public String getSupportFilePath(String path)
                          throws IOException
Returns an absolute path to a specified file within the KMZ file. The file's path is resolved relative to the internal root of the KMZ file.

Note: This class does not yet resolve references to files in other KMZ archives. For example, it does not resolve references like this: ../other.kmz/file.png. // TODO

Specified by:
getSupportFilePath in interface KMLDoc
Parameters:
path - the path of the requested file.
Returns:
an absolute path to the requested file, or null if the file does not exist or the specified path is absolute.
Throws:
IllegalArgumentException - if the path is null.
IOException - if an error occurs while attempting to create a temporary file.

getSupportFileStream

public InputStream getSupportFileStream(String path)
                                 throws IOException
Returns an InputStream to a specified file within the KMZ file. The file's path is resolved relative to the internal root of the KMZ file.

Note: This class does not yet resolve references to files in other KMZ archives. For example, it does not resolve references like this: ../other.kmz/file.png.

Specified by:
getSupportFileStream in interface KMLDoc
Parameters:
path - the path of the requested file.
Returns:
an input stream positioned to the start of the requested file, or null if the file does not exist or the specified path is absolute.
Throws:
IllegalArgumentException - if the path is null.
IOException - if an error occurs while attempting to create or open the input stream.

getZipFile

public ZipFile getZipFile()
Returns the file file specified to the constructor as a ZipFile.

Returns:
the file specified to the constructor, as a ZipFile.

NASA World Wind