NASA World Wind

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

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

public class KMZInputStream
extends Object
implements KMLDoc

Implements the KMLDoc interface for KMZ files read from a stream.


Field Summary
protected  ZipEntry currentEntry
          The next entry to read from the input stream.
protected  Map<String,File> files
          A mapping of the files in the KMZ stream to their location in the temporary directory.
protected  File tempDir
          The directory to hold files copied from the stream.
protected  ZipInputStream zipStream
          The zip stream created for the specified input stream.
 
Constructor Summary
KMZInputStream(InputStream sourceStream)
          Constructs a KMZInputStream instance.
 
Method Summary
protected  void copyCurrentEntryToTempDir()
          Copies a file from the input stream to the temporary area created to represent the KMZ contents.
 InputStream getKMLStream()
          Returns an InputStream to the first KML file within the stream.
 String getSupportFilePath(String path)
          Returns an absolute path to a specified file within the KMZ stream.
 InputStream getSupportFileStream(String path)
          Returns an InputStream to a specified file within the KMZ stream.
protected  void moveToNextEntry()
          Moves this stream to its next zip entry and updates this stream's current-entry field.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

currentEntry

protected ZipEntry currentEntry
The next entry to read from the input stream. This field refers to the first entry in the stream when the constructor returns, and after each entry is copied to the temp dir it is updated to point to the subsequent entry. If null, the stream contains no more entries.


files

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


tempDir

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


zipStream

protected ZipInputStream zipStream
The zip stream created for the specified input stream.

Constructor Detail

KMZInputStream

public KMZInputStream(InputStream sourceStream)
               throws IOException
Constructs a KMZInputStream instance. Upon return, the new instance's current-entry field refers to the first entry in the stream.

Parameters:
sourceStream - the input stream to read from.
Throws:
IllegalArgumentException - if the specified stream is null.
IOException - if an error occurs while accessing the stream.
Method Detail

copyCurrentEntryToTempDir

protected void copyCurrentEntryToTempDir()
                                  throws IOException
Copies a file from the input stream to the temporary area created to represent the KMZ contents. If that area does not yet exists, it is created.

Note: This method should be called only by another synchronized method of this instance.

Throws:
IOException - if an error occurs during the copy.

getKMLStream

public InputStream getKMLStream()
                         throws IOException
Returns an InputStream to the first KML file within the stream.

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

getSupportFilePath

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

Note: Since relative references to files outside the stream have no meaning, this class does not resolve relative references to files in other KMZ archives. For example, it does not resolve references like this: ../other.kmz/file.png.

Specified by:
getSupportFilePath in interface KMLDoc
Parameters:
path - the path of the requested file.
Returns:
an absolute path for 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 stream. The file's path is resolved relative to the internal root of the KMZ file represented by the stream.

Note: Since relative references to files outside the stream have no meaning, this class does not resolve relative 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 read the input stream.

moveToNextEntry

protected void moveToNextEntry()
                        throws IOException
Moves this stream to its next zip entry and updates this stream's current-entry field.

Throws:
IOException - if an exception occurs while attempting to more the stream to the next entry.

NASA World Wind