Package net.mtrop.doom
Class WadFile.Adder
java.lang.Object
net.mtrop.doom.WadFile.Adder
- All Implemented Interfaces:
AutoCloseable
- Enclosing class:
- WadFile
Bulk add mechanism for WadFile.
All methods on this object manipulate the WadFile it is created from, and
defers the final writing of the entry list until it is closed. This object is meant
to be created via a try-with-resources block, like so:
try (WadFile.Adder adder = wad.createAdder()) { adder.addData(....); ... }...upon which the entries are committed on close. This will still commit the list even on an error occurring during add, unless the the writing of the list results in an error as well.
- Since:
- 2.7.0
-
Method Summary
Modifier and TypeMethodDescriptionAdds data to this Wad, usingentryName
as the name of the new entry.<BO extends BinaryObject>
WadEntryAdds data to this Wad, usingentryName
as the name of the new entry.<BO extends BinaryObject>
WadEntryAdds data to this Wad, usingentryName
as the name of the new entry.Adds data to this Wad, usingentryName
as the name of the new entry.addData
(String entryName, InputStream in) Adds data to this Wad, usingentryName
as the name of the new entry.addData
(String entryName, InputStream in, int maxLength) Adds data to this Wad, usingentryName
as the name of the new entry.<TO extends TextObject>
WadEntryAdds data to this Wad, usingentryName
as the name of the new entry.Adds data to this Wad at a particular entry offset, usingentryName
as the name of the entry.<BO extends BinaryObject>
WadEntryAdds data to this Wad at a particular entry offset, usingentryName
as the name of the entry.<BO extends BinaryObject>
WadEntryAdds data to this Wad at a particular entry offset, usingentryName
as the name of the entry.Adds data to this Wad, usingentryName
as the name of the new entry.addDataAt
(int index, String entryName, InputStream in) Adds data to this Wad at a particular entry offset, usingentryName
as the name of the 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.<TO extends TextObject>
WadEntryAdds data to this Wad at a particular entry offset, usingentryName
as the name of the entry.Adds a new entry to the Wad, but with an explicit offset and size.Adds an entry marker to the Wad (entry with 0 size, arbitrary offset).addMarkerAt
(int index, String entryName) Adds an entry marker to the Wad (entry with 0 size, arbitrary offset).void
close()
-
Method Details
-
close
- Specified by:
close
in interfaceAutoCloseable
- Throws:
IOException
-
addEntry
Adds a new entry to the Wad, but with an explicit offset and size. Exercise caution with this method, since you can reference anywhere in the Wad!NOTE: The entry is not written until
close()
is called (or theWadFile.Adder
is closed automatically).- Parameters:
entryName
- the name of the entry.offset
- the entry's content start byte.length
- the entry's length in bytes.- Returns:
- the entry that was created.
- Throws:
IllegalArgumentException
- if the provided name is not a valid name, or the offset/size is negative.IOException
- if the entry cannot be written.NullPointerException
- ifname
isnull
.
-
addMarker
Adds an entry marker to the Wad (entry with 0 size, arbitrary offset).- Parameters:
entryName
- the name of the entry.- Returns:
- the entry that was added.
- Throws:
IllegalArgumentException
- if the provided name is not a valid name.IOException
- if the entry cannot be written.NullPointerException
- ifname
isnull
.
-
addMarkerAt
Adds an entry marker to the Wad (entry with 0 size, arbitrary offset).- Parameters:
index
- the index at which to add the marker.entryName
- the name of the entry.- Returns:
- the entry that was added.
- Throws:
IllegalArgumentException
- if the provided name is not a valid name.IOException
- if the entry cannot be written.NullPointerException
- ifname
isnull
.
-
addData
Adds data to this Wad, usingentryName
as the name of the new entry. The overhead for multiple additions may be expensive I/O-wise depending on the Wad implementation.- Parameters:
entryName
- the name of the entry to add this as.data
- the bytes of data to add as this wad's data.- Returns:
- a WadEntry that describes the added data.
- Throws:
IllegalArgumentException
- if the provided name is not a valid name.IOException
- if the data cannot be written.NullPointerException
- ifentryName
ordata
isnull
.
-
addData
Adds data to this Wad, usingentryName
as the name of the new entry. The overhead for multiple additions may be expensive I/O-wise depending on the Wad implementation.- Type Parameters:
BO
- a BinaryObject type.- Parameters:
entryName
- the name of the entry to add this as.data
- the BinaryObject to add as this wad's data (converted viaBinaryObject.toBytes()
).- Returns:
- a WadEntry that describes the added data.
- Throws:
IllegalArgumentException
- if the provided name is not a valid name.IOException
- if the data cannot be written.NullPointerException
- ifentryName
ordata
isnull
.
-
addData
Adds data to this Wad, usingentryName
as the name of the new entry. The BinaryObjects provided have all of their converted data concatenated together as one blob of contiguous data. The overhead for multiple additions may be expensive I/O-wise depending on the Wad implementation.- Type Parameters:
BO
- a BinaryObject type.- Parameters:
entryName
- the name of the entry to add this as.data
- the BinaryObjects to add as this wad's data (converted viaBinaryObject.toBytes()
).- Returns:
- a WadEntry that describes the added data.
- Throws:
IllegalArgumentException
- if the provided name is not a valid name.IOException
- if the data cannot be written.NullPointerException
- ifentryName
ordata
isnull
.
-
addData
public <TO extends TextObject> WadEntry addData(String entryName, TO data, Charset encoding) throws IOException Adds data to this Wad, usingentryName
as the name of the new entry. The overhead for multiple additions may be expensive I/O-wise depending on the Wad implementation.- Type Parameters:
TO
- a TextObject type.- Parameters:
entryName
- the name of the entry to add this as.data
- the TextObject to add as this wad's data (converted viaTextObject.toText()
, thenString.getBytes(Charset)
).encoding
- the encoding type for the data written to the Wad.- Returns:
- a WadEntry that describes the added data.
- Throws:
IllegalArgumentException
- if the provided name is not a valid name.IOException
- if the data cannot be written.NullPointerException
- ifentryName
ordata
orencoding
isnull
.
-
addData
Adds data to this Wad, usingentryName
as the name of the new entry. The provided File is read until the end of the file is reached. The overhead for multiple individual additions may be expensive I/O-wise depending on the Wad implementation.- Parameters:
entryName
- the name of the entry to add this as.fileToAdd
- the file to add the contents of.- Returns:
- a WadEntry that describes the added data.
- Throws:
IllegalArgumentException
- if the provided name is not a valid name.FileNotFoundException
- if the file path refers to a file that is a directory or doesn't exist.IOException
- if the data cannot be written or the stream could not be read.NullPointerException
- ifentryName
ordata
orencoding
isnull
.- Since:
- 2.7.0
-
addData
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. The overhead for multiple additions may be expensive I/O-wise depending on the Wad implementation.- Parameters:
entryName
- the name of the entry to add this as.in
- the input stream to read.- Returns:
- a WadEntry that describes the added data.
- Throws:
IllegalArgumentException
- if the provided name is not a valid name.IOException
- if the data cannot be written or the stream could not be read.NullPointerException
- ifentryName
ordata
orencoding
isnull
.
-
addData
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 overhead for multiple additions may be expensive I/O-wise depending on the Wad implementation.- 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:
IllegalArgumentException
- if the provided name is not a valid name.IOException
- if the data cannot be written or the stream could not be read.NullPointerException
- ifentryName
ordata
orencoding
isnull
.
-
addDataAt
Adds data to this Wad at a particular entry offset, usingentryName
as the name of the entry. The rest of the entries in the wad are shifted down one index. The overhead for multiple additions may be expensive I/O-wise depending on the Wad implementation.- Parameters:
index
- the index at which to add the entry.entryName
- the name of the entry to add this as.data
- the bytes of data to add as this wad's data.- Returns:
- a WadEntry that describes the added data.
- Throws:
IllegalArgumentException
- if the provided name is not a valid name.IndexOutOfBoundsException
- if the provided index < 0 or >getEntryCount()
.IOException
- if the data cannot be written.NullPointerException
- ifentryName
ordata
isnull
.
-
addDataAt
public <BO extends BinaryObject> WadEntry addDataAt(int index, String entryName, BO data) throws IOException Adds data to this Wad at a particular entry offset, usingentryName
as the name of the entry. The rest of the entries in the wad are shifted down one index. The overhead for multiple additions may be expensive I/O-wise depending on the Wad implementation.- Type Parameters:
BO
- a BinaryObject type.- Parameters:
index
- the index at which to add the entry.entryName
- the name of the entry to add this as.data
- the BinaryObject to add as this wad's data (converted viaBinaryObject.toBytes()
).- Returns:
- a WadEntry that describes the added data.
- Throws:
IllegalArgumentException
- if the provided name is not a valid name.IndexOutOfBoundsException
- if the provided index < 0 or >getEntryCount()
.IOException
- if the data cannot be written.NullPointerException
- ifentryName
ordata
isnull
.
-
addDataAt
public <BO extends BinaryObject> WadEntry addDataAt(int index, String entryName, BO[] data) throws IOException Adds data to this Wad at a particular entry offset, usingentryName
as the name of the entry. The rest of the entries in the wad are shifted down one index. The BinaryObjects provided have all of their converted data concatenated together as one blob of contiguous data. The overhead for multiple additions may be expensive I/O-wise depending on the Wad implementation.- Type Parameters:
BO
- a BinaryObject type.- Parameters:
index
- the index at which to add the entry.entryName
- the name of the entry to add this as.data
- the BinaryObjects to add as this wad's data (converted viaBinaryObject.toBytes()
).- Returns:
- a WadEntry that describes the added data.
- Throws:
IllegalArgumentException
- if the provided name is not a valid name.IndexOutOfBoundsException
- if the provided index < 0 or >getEntryCount()
.IOException
- if the data cannot be written.NullPointerException
- ifentryName
ordata
isnull
.
-
addDataAt
public <TO extends TextObject> WadEntry addDataAt(int index, String entryName, TO data, Charset encoding) throws IOException Adds data to this Wad at a particular entry offset, usingentryName
as the name of the entry. The rest of the entries in the wad are shifted down one index. The overhead for multiple additions may be expensive I/O-wise depending on the Wad implementation.- Type Parameters:
TO
- a TextObject type.- Parameters:
index
- the index at which to add the entry.entryName
- the name of the entry to add this as.data
- the TextObject to add as this wad's data (converted viaTextObject.toText()
, thenString.getBytes(Charset)
).encoding
- the encoding type for the data written to the Wad.- Returns:
- a WadEntry that describes the added data.
- Throws:
IllegalArgumentException
- if the provided name is not a valid name.IndexOutOfBoundsException
- if the provided index < 0 or >getEntryCount()
.IOException
- if the data cannot be written.NullPointerException
- ifentryName
ordata
isnull
.
-
addDataAt
Adds data to this Wad, usingentryName
as the name of the new entry. The provided File is read until the end of the file is reached. The overhead for multiple individual additions may be expensive I/O-wise depending on the Wad implementation.- Parameters:
index
- the index at which to add the entry.entryName
- the name of the entry to add this as.fileToAdd
- the file to add the contents of.- Returns:
- a WadEntry that describes the added data.
- Throws:
IllegalArgumentException
- if the provided name is not a valid name.FileNotFoundException
- if the file path refers to a file that is a directory or doesn't exist.IOException
- if the data cannot be written or the stream could not be read.NullPointerException
- ifentryName
ordata
orencoding
isnull
.- Since:
- 2.7.0
-
addDataAt
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. The rest of the entries in the wad are shifted down one index. The overhead for multiple additions may be expensive I/O-wise depending on the Wad implementation.- 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.- Returns:
- a WadEntry that describes the added data.
- Throws:
IllegalArgumentException
- if the provided name is not a valid name.IndexOutOfBoundsException
- if the provided index < 0 or >getEntryCount()
.IOException
- if the data cannot be written or the stream could not be read.NullPointerException
- ifentryName
ordata
isnull
.
-
addDataAt
public WadEntry addDataAt(int index, String entryName, InputStream in, int maxLength) throws IOException 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 rest of the entries in the wad are shifted down one index. The overhead for multiple additions may be expensive I/O-wise depending on the Wad implementation.- 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:
IllegalArgumentException
- if the provided name is not a valid name.IndexOutOfBoundsException
- if the provided index < 0 or >getEntryCount()
.IOException
- if the data cannot be written or the stream could not be read.NullPointerException
- ifentryName
ordata
isnull
.
-