Class WadBuffer
java.lang.Object
net.mtrop.doom.WadBuffer
-
Nested Class Summary
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default internal capacity of the WadBuffer in bytes.static final intDefault capacity increment for the buffer (doubles every resize).Fields inherited from interface net.mtrop.doom.Wad
NO_DATA, NO_ENTRIES -
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty WadBuffer (as a PWAD).WadBuffer(int capacity) Creates an empty WadBuffer (as a PWAD).WadBuffer(int capacity, int capacityIncrement) Creates an empty WadBuffer (as a PWAD).Creates a new WadBuffer using the contents of a file.WadBuffer(InputStream in) Creates a new WadBuffer.Creates a new WadBuffer using the contents of a file, denoted by the path.Creates an empty WadBuffer with a specific type.Creates an empty WadBuffer with a specific type.Creates an empty WadBuffer with a specific type. -
Method Summary
Modifier and TypeMethodDescriptionaddDataAt(int index, String entryName, InputStream in, int maxLength) Adds data to this Wad at a particular entry offset, usingentryNameas the name of the entry.addEntryAt(int index, WadEntry entry) Adds a new entry to the Wad.voidclose()Closes this Wad.deleteEntry(int n) Deletes a Wad's entry and its contents.static WadBufferCreates a new WadBuffer from a subset of entries (and their data) from another Wad.static WadBufferCreates a new WadBuffer from a subset of entries (and their data) from another Wad.voidfetchContent(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.intGets the capacity of this buffer.intReturns the capacity increment value.intgetEntry(int n) Gets the WadEntry at index n.intgetInputStream(WadEntry entry) Retrieves the data of the specified entry from a starting index and returns it as a stream.final Wad.TypegetType()Gets the type of WAD that this is.booleanisIWAD()Checks if this WAD is an Internal WAD.booleanisPWAD()Checks if this WAD is a Patch WAD.iterator()removeEntry(int n) Remove a Wad's entry (but not contents).voidrenameEntry(int index, String newName) Renames the entry at an index in the Wad.voidreplaceEntry(int index, byte[] data) Replaces the entry at an index in the Wad.voidsetCapacityIncrement(int capacityIncrement) Sets the capacity increment value.voidsetEntries(WadEntry... entryList) Completely replaces the list of entries in this Wad with a completely different set of entries.final voidSets the type of WAD that this is.voidunmapEntries(int startIndex, WadEntry... entryList) Replaces a series of WadEntry objects in this Wad, using the provided list of entries as the replacement list.final voidwriteToFile(File path) Writes the contents of this buffer out to a file in Wad format.final voidwriteToFile(String path) Writes the contents of this buffer out to a file in Wad format.final voidWrites the contents of this buffer out to an output stream in Wad format.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface net.mtrop.doom.Wad
addData, addData, addData, addData, addData, addData, addData, addDataAt, addDataAt, addDataAt, addDataAt, addDataAt, addDataAt, addEntry, addEntry, addEntryAt, addFrom, addFrom, addFromAt, addFromAt, addMarker, addMarkerAt, contains, contains, contains, fetchData, fetchData, fetchData, fetchData, fetchData, getAllEntries, getAllEntries, getAllEntryIndices, getContent, getData, 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
-
Field Details
-
DEFAULT_CAPACITY
public static final int DEFAULT_CAPACITYThe default internal capacity of the WadBuffer in bytes.- See Also:
-
DEFAULT_CAPACITY_INCREMENT
public static final int DEFAULT_CAPACITY_INCREMENTDefault capacity increment for the buffer (doubles every resize).- See Also:
-
-
Constructor Details
-
WadBuffer
public WadBuffer()Creates an empty WadBuffer (as a PWAD). -
WadBuffer
public WadBuffer(int capacity) Creates an empty WadBuffer (as a PWAD).- Parameters:
capacity- the initial capacity of the buffer in bytes.- Since:
- 2.15.0
-
WadBuffer
public WadBuffer(int capacity, int capacityIncrement) Creates an empty WadBuffer (as a PWAD).- Parameters:
capacity- the initial capacity of the buffer in bytes.capacityIncrement- the capacity increment in bytes to grow the buffer. 0 or less will double the buffer's size.- Since:
- 2.15.0
-
WadBuffer
Creates an empty WadBuffer with a specific type.- Parameters:
type- the type to set.
-
WadBuffer
Creates an empty WadBuffer with a specific type.- Parameters:
type- the type to set.capacity- the initial capacity of the buffer in bytes.- Since:
- 2.15.0
-
WadBuffer
Creates an empty WadBuffer with a specific type.- Parameters:
type- the type to set.capacity- the initial capacity of the buffer in bytes.capacityIncrement- the capacity increment in bytes to grow the buffer. 0 or less will double the buffer's size.- Since:
- 2.15.0
-
WadBuffer
Creates a new WadBuffer 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- ifpathis null.
-
WadBuffer
Creates a new WadBuffer 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- ifpathis null.
-
WadBuffer
Creates a new WadBuffer.- Parameters:
in- the input stream.- Throws:
IOException- if the file can't be read.WadException- if the stream contents are not a Wad file.NullPointerException- ifpathis null.
-
-
Method Details
-
extract
Creates a new WadBuffer from a subset of entries (and their data) from another Wad.- Parameters:
source- the the source Wad.startIndex- the starting entry index.maxLength- the maximum amount of entries from the starting index to copy.- Returns:
- a new WadBuffer that only contains the desired entries, plus their data.
- Throws:
IOException- if an error occurs on read from the source Wad.- Since:
- 2.1.0
-
extract
Creates a new WadBuffer from a subset of entries (and their data) from another Wad.- Parameters:
source- the the source Wad.entries- the entries to copy over.- Returns:
- a new WadBuffer that only contains the desired entries, plus their data.
- Throws:
IOException- if an error occurs on read from the source Wad.- Since:
- 2.1.0
-
setType
Sets the type of WAD that this is.- Parameters:
type- the new type.
-
getType
-
getCapacity
public int getCapacity()Gets the capacity of this buffer.- Returns:
- the current capacity in bytes.
- Since:
- 2.15.0
-
getCapacityIncrement
public int getCapacityIncrement()Returns the capacity increment value.- Returns:
- the current capacity increment in bytes (or a value of 0 or less if it doubles).
- Since:
- 2.15.0
-
setCapacityIncrement
public void setCapacityIncrement(int capacityIncrement) Sets the capacity increment value.- Parameters:
capacityIncrement- what to increase the capacity of this buffer by (in bytes) if this reaches the max. if 0 or less, it will double.- Since:
- 2.15.0
-
writeToFile
Writes the contents of this buffer out to a file in Wad format. The target file will be overwritten.- Parameters:
path- the file path to write to.- Throws:
IOException- if a problem occurs during the write.SecurityException- if you don't have permission to write the file.NullPointerException- ifoutis null.- Since:
- 2.6.0
-
writeToFile
Writes the contents of this buffer out to a file in Wad format. The target file will be overwritten.- Parameters:
path- the file to write to.- Throws:
IOException- if a problem occurs during the write.SecurityException- if you don't have permission to write the file.NullPointerException- ifoutis null.
-
writeToStream
Writes the contents of this buffer out to an output stream in Wad format. Does not close the stream.- Parameters:
out- the output stream to write to.- Throws:
IOException- if a problem occurs during the write.NullPointerException- ifoutis null.
-
getContentLength
public int getContentLength()- Specified by:
getContentLengthin interfaceWad- Returns:
- the amount of content data in this Wad in bytes.
-
isIWAD
-
isPWAD
-
getEntryCount
public int getEntryCount()- Specified by:
getEntryCountin interfaceWad- Returns:
- the number of entries in this Wad.
-
getEntry
-
fetchContent
Description copied from interface:WadFetches 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:
fetchContentin 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.
-
getInputStream
Description copied from interface:WadRetrieves the data of the specified entry from a starting index and returns it as a stream.- Specified by:
getInputStreamin 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.
-
removeEntry
Description copied from interface:WadRemove 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:
removeEntryin 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.
-
deleteEntry
Description copied from interface:WadDeletes a Wad's entry and its contents. The overhead for multiple deletions may be expensive I/O-wise.- Specified by:
deleteEntryin interfaceWad- Parameters:
n- the index of the entry to delete.- Returns:
- the entry deleted.
- Throws:
IOException- if the entry cannot be deleted.
-
renameEntry
Description copied from interface:WadRenames the entry at an index in the Wad.- Specified by:
renameEntryin 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:WadReplaces 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:
replaceEntryin 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:WadReplaces 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:
unmapEntriesin 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:WadCompletely replaces the list of entries in this Wad with a completely different set of entries.- Specified by:
setEntriesin interfaceWad- Parameters:
entryList- the set of entries that will make up this Wad.- Throws:
IOException- if the entries could not be written.
-
addEntryAt
Description copied from interface:WadAdds 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:
addEntryAtin 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.
-
addDataAt
public WadEntry addDataAt(int index, String entryName, InputStream in, int maxLength) throws IOException Description copied from interface:WadAdds data to this Wad at a particular entry offset, usingentryNameas the name of the entry. The provided input stream is read until the end of the stream is reached ormaxLengthbytes 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:
addDataAtin 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.
-
iterator
-
close
Description copied from interface:WadCloses this Wad. Does nothing on some implementations.- Specified by:
closein interfaceWad- Throws:
IOException- if an error occurred during close.
-