Package gov.nasa.worldwind.ogc.kml.io
Class KMZFile
- java.lang.Object
-
- gov.nasa.worldwind.ogc.kml.io.KMZFile
-
- All Implemented Interfaces:
KMLDoc
public class KMZFile extends java.lang.Object implements KMLDoc
Implements theKMLDoc
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
Fields Modifier and Type Field Description protected java.util.Map<java.lang.String,java.io.File>
files
A mapping of the files in the KMZ file to their location in the temporary directory.protected java.io.File
tempDir
The directory to hold files copied from the KMZ file.protected java.util.zip.ZipFile
zipFile
TheZipFile
reference specified to the constructor.
-
Constructor Summary
Constructors Constructor Description KMZFile(java.io.File file)
Construct a KMZFile instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.String
copyEntryToTempDir(java.util.zip.ZipEntry entry)
Copies a zip entry to a temporary file.java.io.InputStream
getKMLStream()
Returns anInputStream
to the first KML file in the KMZ file.java.lang.String
getSupportFilePath(java.lang.String path)
Returns an absolute path to a specified file within the KMZ file.java.io.InputStream
getSupportFileStream(java.lang.String path)
Returns anInputStream
to a specified file within the KMZ file.java.util.zip.ZipFile
getZipFile()
Returns the file file specified to the constructor as aZipFile
.
-
-
-
Field Detail
-
zipFile
protected java.util.zip.ZipFile zipFile
TheZipFile
reference specified to the constructor.
-
files
protected java.util.Map<java.lang.String,java.io.File> files
A mapping of the files in the KMZ file to their location in the temporary directory.
-
tempDir
protected java.io.File tempDir
The directory to hold files copied from the KMZ file. The directory and the files copied there are temporary.
-
-
Constructor Detail
-
KMZFile
public KMZFile(java.io.File file) throws java.io.IOException
Construct a KMZFile instance.- Parameters:
file
- path to the KMZ file.- Throws:
java.io.IOException
- if an error occurs while attempting to query or open the file.java.lang.IllegalArgumentException
- if the specified file is null.java.util.zip.ZipException
- if a Zip error occurs.
-
-
Method Detail
-
getZipFile
public java.util.zip.ZipFile getZipFile()
Returns the file file specified to the constructor as aZipFile
.- Returns:
- the file specified to the constructor, as a
ZipFile
.
-
getKMLStream
public java.io.InputStream getKMLStream() throws java.io.IOException
Returns anInputStream
to the first KML file in the KMZ file.- Specified by:
getKMLStream
in interfaceKMLDoc
- 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:
java.io.IOException
- if an error occurs while attempting to create or open the input stream.
-
getSupportFileStream
public java.io.InputStream getSupportFileStream(java.lang.String path) throws java.io.IOException
Returns anInputStream
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 interfaceKMLDoc
- 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:
java.lang.IllegalArgumentException
- if the path is null.java.io.IOException
- if an error occurs while attempting to create or open the input stream.
-
getSupportFilePath
public java.lang.String getSupportFilePath(java.lang.String path) throws java.io.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 interfaceKMLDoc
- 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:
java.lang.IllegalArgumentException
- if the path is null.java.io.IOException
- if an error occurs while attempting to create a temporary file.
-
copyEntryToTempDir
protected java.lang.String copyEntryToTempDir(java.util.zip.ZipEntry entry) throws java.io.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:
java.io.IOException
- if an error occurs during the copy.
-
-