Package gov.nasa.worldwind.ogc.kml.io
Class KMZInputStream
- java.lang.Object
-
- gov.nasa.worldwind.ogc.kml.io.KMZInputStream
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.zip.ZipEntry
currentEntry
The next entry to read from the input stream.protected java.util.Map<java.lang.String,java.io.File>
files
A mapping of the files in the KMZ stream to their location in the temporary directory.protected java.io.File
tempDir
The directory to hold files copied from the stream.protected java.util.zip.ZipInputStream
zipStream
The zip stream created for the specified input stream.
-
Constructor Summary
Constructors Constructor Description KMZInputStream(java.io.InputStream sourceStream)
Constructs a KMZInputStream instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
copyCurrentEntryToTempDir()
Copies a file from the input stream to the temporary area created to represent the KMZ contents.java.io.InputStream
getKMLStream()
Returns anInputStream
to the first KML file within the stream.java.lang.String
getSupportFilePath(java.lang.String path)
Returns an absolute path to a specified file within the KMZ stream.java.io.InputStream
getSupportFileStream(java.lang.String path)
Returns anInputStream
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.
-
-
-
Field Detail
-
zipStream
protected java.util.zip.ZipInputStream zipStream
The zip stream created for the specified input stream.
-
currentEntry
protected java.util.zip.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 java.util.Map<java.lang.String,java.io.File> files
A mapping of the files in the KMZ stream to their location in the temporary directory.
-
tempDir
protected java.io.File tempDir
The directory to hold files copied from the stream. Both the directory and the files copied there are temporary.
-
-
Constructor Detail
-
KMZInputStream
public KMZInputStream(java.io.InputStream sourceStream) throws java.io.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:
java.lang.IllegalArgumentException
- if the specified stream is null.java.io.IOException
- if an error occurs while accessing the stream.
-
-
Method Detail
-
moveToNextEntry
protected void moveToNextEntry() throws java.io.IOException
Moves this stream to its next zip entry and updates this stream's current-entry field.- Throws:
java.io.IOException
- if an exception occurs while attempting to more the stream to the next entry.
-
getKMLStream
public java.io.InputStream getKMLStream() throws java.io.IOException
Returns anInputStream
to the first KML file within the stream.- Specified by:
getKMLStream
in interfaceKMLDoc
- 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:
java.io.IOException
- if an error occurs while reading the stream.
-
getSupportFileStream
public java.io.InputStream getSupportFileStream(java.lang.String path) throws java.io.IOException
Returns anInputStream
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 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 read 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 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 interfaceKMLDoc
- 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:
java.lang.IllegalArgumentException
- if the path is null.java.io.IOException
- if an error occurs while attempting to create a temporary file.
-
copyCurrentEntryToTempDir
protected void copyCurrentEntryToTempDir() throws java.io.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:
java.io.IOException
- if an error occurs during the copy.
-
-