Package net.mtrop.doom
Class WadMap
java.lang.Object
net.mtrop.doom.WadMap
This is just a basic mapping of WAD entries to a file.
The file is NOT kept open after the read, and the file or
stream used to gather the WAD metadata is not kept.
This may not be added to or changed, and its data may not be read directly, because this is just a mapping of entries. Individual entries may be read for data offset information and then read from the corresponding file or stream.
Despite the name, this is not a structure that reads Doom Map information.
Use DoomMap
, HexenMap
, or UDMFMap
for that purpose.
- Author:
- Matthew Tropiano
-
Nested Class Summary
-
Field Summary
Fields inherited from interface net.mtrop.doom.Wad
NO_DATA, NO_ENTRIES
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddData
(String entryName, InputStream in, int maxLength) Adds data to this Wad, usingentryName
as the name of the new entry.addDataAt
(int index, String entryName, InputStream in, int maxLength) Adds data to this Wad at a particular entry offset, usingentryName
as the name of the entry.Adds a new entry to the Wad.addEntryAt
(int index, WadEntry entry) Adds a new entry to the Wad.void
close()
Closes this Wad.deleteEntry
(int n) Deletes a Wad's entry and its contents.void
fetchContent
(int offset, int length, byte[] dest, int destOffset) Fetches a series of bytes from an arbitrary place in the Wad and puts them into a provided array.byte[]
getContent
(int offset, int length) Gets a series of bytes representing the data at an arbitrary place in the Wad.int
byte[]
Retrieves the data of the specified entry.getEntry
(int n) Gets the WadEntry at index n.int
getInputStream
(WadEntry entry) Retrieves the data of the specified entry from a starting index and returns it as a stream.boolean
isIWAD()
Checks if this WAD is an Internal WAD.boolean
isPWAD()
Checks if this WAD is a Patch WAD.iterator()
removeEntry
(int n) Remove a Wad's entry (but not contents).void
renameEntry
(int index, String newName) Renames the entry at an index in the Wad.void
replaceEntry
(int index, byte[] data) Replaces the entry at an index in the Wad.void
setEntries
(WadEntry... entryList) Completely replaces the list of entries in this Wad with a completely different set of entries.void
unmapEntries
(int startIndex, WadEntry... entryList) Replaces a series of WadEntry objects in this Wad, using the provided list of entries as the replacement list.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface net.mtrop.doom.Wad
addData, addData, addData, addData, addData, addData, addDataAt, addDataAt, addDataAt, addDataAt, addDataAt, addDataAt, addEntry, addEntryAt, addFrom, addFrom, addFromAt, addFromAt, addMarker, addMarkerAt, contains, contains, contains, fetchData, fetchData, fetchData, fetchData, fetchData, getAllEntries, getAllEntries, getAllEntryIndices, getData, getData, getData, getData, getDataAs, getDataAs, getDataAs, getDataAs, getDataAs, getDataAs, getDataAs, getDataAs, getDataAs, getDataAs, getDataAsList, getDataAsList, getDataAsList, getDataAsList, getDataAsList, getEntry, getEntry, getEntry, getInlineScanner, getInlineScanner, getInlineScanner, getInlineScanner, getInlineScanner, getInputStream, getInputStream, getInputStream, getInputStream, getLastEntry, getNthEntry, getReader, getReader, getReader, getReader, getReader, getScanner, getScanner, getScanner, getScanner, getScanner, getTextData, getTextData, getTextData, getTextData, getTextData, getTextDataAs, getTextDataAs, getTextDataAs, getTextDataAs, getTextDataAs, indexOf, indexOf, indexOf, lastIndexOf, mapEntries, replaceEntry, replaceEntry, replaceEntry, setEntry, transformData, transformData, transformData, transformData, transformData, transformData, transformData, transformData, transformTextData, transformTextData, transformTextData, transformTextData
-
Constructor Details
-
WadMap
Creates a new WadMap using the contents of a file, denoted by the path.- Parameters:
path
- the path to the file to read.- Throws:
IOException
- if the file can't be read.FileNotFoundException
- if the file can't be found.SecurityException
- if you don't have permission to access the file.WadException
- if the file isn't a Wad file.NullPointerException
- ifpath
is null.
-
WadMap
Creates a new WadMap using the contents of a file.- Parameters:
f
- the file to read.- Throws:
IOException
- if the file can't be read.FileNotFoundException
- if the file can't be found.SecurityException
- if you don't have permission to access the file.WadException
- if the file isn't a Wad file.NullPointerException
- iff
is null.
-
WadMap
Creates a new WadMap.- Parameters:
in
- the input stream.- Throws:
IOException
- if the file can't be read.WadException
- if the file isn't a Wad file.NullPointerException
- ifin
is null.
-
-
Method Details
-
isIWAD
public boolean isIWAD()Description copied from interface:Wad
Checks if this WAD is an Internal WAD. -
isPWAD
public boolean isPWAD()Description copied from interface:Wad
Checks if this WAD is a Patch WAD. -
getEntryCount
public int getEntryCount()- Specified by:
getEntryCount
in interfaceWad
- Returns:
- the number of entries in this Wad.
-
getContentLength
public int getContentLength()- Specified by:
getContentLength
in interfaceWad
- Returns:
- the amount of content data in this Wad in bytes.
-
addEntry
Description copied from interface:Wad
Adds a new entry to the Wad. Exercise caution with this method, as this entry is added as-is, and an entry can reference anywhere in the Wad!- Specified by:
addEntry
in interfaceWad
- Parameters:
entry
- the entry to add.- Returns:
- the entry added.
- Throws:
IOException
- if the entry cannot be written.
-
addEntryAt
Description copied from interface:Wad
Adds a new entry to the Wad. Exercise caution with this method, as this entry is added as-is, and an entry can reference anywhere in the Wad!- Specified by:
addEntryAt
in interfaceWad
- Parameters:
index
- the index at which to add the entry.entry
- the entry to add.- Returns:
- the entry added.
- Throws:
IOException
- if the entry cannot be written.
-
addData
Description copied from interface:Wad
Adds data to this Wad, usingentryName
as the name of the new entry. The provided input stream is read until the end of the stream is reached ormaxLength
bytes are read. The input stream is NOT CLOSED, afterward. The overhead for multiple individual additions may be expensive I/O-wise depending on the Wad implementation.- Specified by:
addData
in interfaceWad
- Parameters:
entryName
- the name of the entry to add this as.in
- the input stream to read.maxLength
- the maximum amount of bytes to read from the InputStream, or a value < 0 to keep reading until end-of-stream.- Returns:
- a WadEntry that describes the added data.
- Throws:
IOException
- if the data cannot be written or the stream could not be read.
-
addDataAt
public WadEntry addDataAt(int index, String entryName, InputStream in, int maxLength) throws IOException Description copied from interface:Wad
Adds data to this Wad at a particular entry offset, usingentryName
as the name of the entry. The provided input stream is read until the end of the stream is reached ormaxLength
bytes are read. The input stream is NOT CLOSED, afterward. The rest of the entries in the wad are shifted down one index. The overhead for multiple individual additions may be expensive I/O-wise depending on the Wad implementation.- Specified by:
addDataAt
in interfaceWad
- Parameters:
index
- the index at which to add the entry.entryName
- the name of the entry to add this as.in
- the input stream to read.maxLength
- the maximum amount of bytes to read from the InputStream, or a value < 0 to keep reading until end-of-stream.- Returns:
- a WadEntry that describes the added data.
- Throws:
IOException
- if the data cannot be written or the stream could not be read.
-
deleteEntry
Description copied from interface:Wad
Deletes a Wad's entry and its contents. The overhead for multiple deletions may be expensive I/O-wise.- Specified by:
deleteEntry
in interfaceWad
- Parameters:
n
- the index of the entry to delete.- Returns:
- the entry deleted.
- Throws:
IOException
- if the entry cannot be deleted.
-
removeEntry
Description copied from interface:Wad
Remove a Wad's entry (but not contents). This will leave abandoned, un-addressed data in a Wad file and will not be removed until the data is purged.- Specified by:
removeEntry
in interfaceWad
- Parameters:
n
- the index of the entry to delete.- Returns:
- the entry removed from the Wad.
- Throws:
IOException
- if the entry cannot be removed.
-
renameEntry
Description copied from interface:Wad
Renames the entry at an index in the Wad.- Specified by:
renameEntry
in interfaceWad
- Parameters:
index
- the index of the entry to rename.newName
- the new name of the entry.- Throws:
IOException
- if the entry cannot be renamed.
-
replaceEntry
Description copied from interface:Wad
Replaces the entry at an index in the Wad. If the incoming data is the same size as the entry at the index, this will change the data in-place without deleting and adding.- Specified by:
replaceEntry
in interfaceWad
- Parameters:
index
- the index of the entry to replace.data
- the data to replace the entry with.- Throws:
IOException
- if the entry cannot be replaced.
-
unmapEntries
Description copied from interface:Wad
Replaces a series of WadEntry objects in this Wad, using the provided list of entries as the replacement list. If the list of entries plus the starting index would breach the original list of entries, the excess is appended to the Wad.- Specified by:
unmapEntries
in interfaceWad
- Parameters:
startIndex
- the starting index to replace from (inclusive).entryList
- the set of entries to replace (in order) from the starting index.- Throws:
IOException
- if the entries could not be written.
-
setEntries
Description copied from interface:Wad
Completely replaces the list of entries in this Wad with a completely different set of entries.- Specified by:
setEntries
in interfaceWad
- Parameters:
entryList
- the set of entries that will make up this Wad.- Throws:
IOException
- if the entries could not be written.
-
fetchContent
Description copied from interface:Wad
Fetches a series of bytes from an arbitrary place in the Wad and puts them into a provided array. This is will attempt to get the full provided length, throwing an exception if it does not.- Specified by:
fetchContent
in interfaceWad
- Parameters:
offset
- the offset byte into that data to start at.length
- the amount of bytes to fetch.dest
- the destination array of bytes.destOffset
- the offset into the destination array to put the bytes into.- Throws:
IOException
- if an error occurs during read.
-
getContent
Description copied from interface:Wad
Gets a series of bytes representing the data at an arbitrary place in the Wad.- Specified by:
getContent
in interfaceWad
- Parameters:
offset
- the offset byte into that data to start at.length
- the amount of bytes to return.- Returns:
- a copy of the byte data as an array of bytes.
- Throws:
IOException
- if an error occurs during read.
-
getData
Description copied from interface:Wad
Retrieves the data of the specified entry.- Specified by:
getData
in interfaceWad
- Parameters:
entry
- the entry to use.- Returns:
- a byte array of the data.
- Throws:
IOException
- if the data couldn't be retrieved or the entry's offsets breach the file extents.
-
getInputStream
Description copied from interface:Wad
Retrieves the data of the specified entry from a starting index and returns it as a stream.- Specified by:
getInputStream
in interfaceWad
- Parameters:
entry
- the entry to use.- Returns:
- an open input stream of the data.
- Throws:
IOException
- if the data couldn't be retrieved or the entry's offsets breach the file extents.
-
getEntry
Description copied from interface:Wad
Gets the WadEntry at index n. -
iterator
-
close
Description copied from interface:Wad
Closes this Wad. Does nothing on some implementations.- Specified by:
close
in interfaceWad
- Throws:
IOException
- if an error occurred during close.
-