Class DoomPK3
- All Implemented Interfaces:
Closeable
,AutoCloseable
ZipFile
.- Author:
- Matthew Tropiano
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final long
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final long
static final int
static final int
static final int
static final int
static final int
static final int
static final long
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final long
static final int
static final int
static final int
Fields inherited from class java.util.zip.ZipFile
OPEN_DELETE, OPEN_READ
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Checks if this Wad contains a particular entry.byte[]
Gets the data in one entry in the PK3 by entry name (path and all).<BO extends BinaryObject>
BORetrieves the data for a particular entry as a deserialized lump.<BO extends BinaryObject>
BO[]Retrieves the data for a particular entry as a deserialized lump of multiple objects.<BO extends BinaryObject>
List<BO>getDataAsList
(String entryName, Class<BO> type, int objectLength) Retrieves the data for a particular entry as a deserialized lump of multiple objects.getDataAsTempWadFile
(String entryName, File outFile) Retrieves the data for a particular entry, extracts it, and, presuming it to be a WAD of some kind, opens it as a WadFile.getDataAsTempWadFile
(String entryName, String outFilePath) Retrieves the data for a particular entry, extracts it, and, presuming it to be a WAD of some kind, opens it as a WadFile.getDataAsWadBuffer
(String entryName) Retrieves the data for a particular entry, presuming it to be a WAD of some kind, and returns it as a fully read WadBuffer.getDataAsWadMap
(String entryName) Retrieves the data for a particular entry, presuming it to be a WAD of some kind, and returns it as a WadMap.Returns a list of all entries that start with a type of key.int
static String
getEntryName
(ZipEntry ze) Gets the "entry name" for a ZipEntry, which is just the filename itself minus extension.Gets the data in one entry in the PK3 and extracts it to a file.Gets the data in one entry in the PK3 and extracts it to a file.final String
Gets this file's name (and just the name).final String
Gets this file's path.<BO extends BinaryObject>
BinaryObject.InlineScanner<BO>getInlineScanner
(String entryName, Class<BO> type, int objectLength) Retrieves the data for a particular entry and returns it as a deserializing scanner iterator that returns the same object instance with its contents changed.getInputStream
(String entry) Gets the data in one entry in the PK3 as an input stream by entry name (path and all).Retrieves a Reader for a particular entry as a decoded stream of characters.<BO extends BinaryObject>
BinaryObject.Scanner<BO>getScanner
(String entryName, Class<BO> type, int objectLength) Retrieves the data for a particular entry and returns it as a deserializing scanner iterator that returns independent instances of objects.getTextData
(String entryName, Charset charset) Retrieves the data for a particular entry as a decoded string of characters.<TO extends TextObject>
TOgetTextDataAs
(String entryName, Charset charset, Class<TO> type) Retrieves the data of the first occurrence of a particular entry as an interpreted text-originating object.final void
Refreshes the entry lists, if ZIP contents changed.Methods inherited from class java.util.zip.ZipFile
close, entries, getComment, getEntry, getInputStream, getName, size, stream
-
Field Details
-
LOCSIG
static final long LOCSIG- See Also:
-
EXTSIG
static final long EXTSIG- See Also:
-
CENSIG
static final long CENSIG- See Also:
-
ENDSIG
static final long ENDSIG- See Also:
-
LOCHDR
static final int LOCHDR- See Also:
-
EXTHDR
static final int EXTHDR- See Also:
-
CENHDR
static final int CENHDR- See Also:
-
ENDHDR
static final int ENDHDR- See Also:
-
LOCVER
static final int LOCVER- See Also:
-
LOCFLG
static final int LOCFLG- See Also:
-
LOCHOW
static final int LOCHOW- See Also:
-
LOCTIM
static final int LOCTIM- See Also:
-
LOCCRC
static final int LOCCRC- See Also:
-
LOCSIZ
static final int LOCSIZ- See Also:
-
LOCLEN
static final int LOCLEN- See Also:
-
LOCNAM
static final int LOCNAM- See Also:
-
LOCEXT
static final int LOCEXT- See Also:
-
EXTCRC
static final int EXTCRC- See Also:
-
EXTSIZ
static final int EXTSIZ- See Also:
-
EXTLEN
static final int EXTLEN- See Also:
-
CENVEM
static final int CENVEM- See Also:
-
CENVER
static final int CENVER- See Also:
-
CENFLG
static final int CENFLG- See Also:
-
CENHOW
static final int CENHOW- See Also:
-
CENTIM
static final int CENTIM- See Also:
-
CENCRC
static final int CENCRC- See Also:
-
CENSIZ
static final int CENSIZ- See Also:
-
CENLEN
static final int CENLEN- See Also:
-
CENNAM
static final int CENNAM- See Also:
-
CENEXT
static final int CENEXT- See Also:
-
CENCOM
static final int CENCOM- See Also:
-
CENDSK
static final int CENDSK- See Also:
-
CENATT
static final int CENATT- See Also:
-
CENATX
static final int CENATX- See Also:
-
CENOFF
static final int CENOFF- See Also:
-
ENDSUB
static final int ENDSUB- See Also:
-
ENDTOT
static final int ENDTOT- See Also:
-
ENDSIZ
static final int ENDSIZ- See Also:
-
ENDOFF
static final int ENDOFF- See Also:
-
ENDCOM
static final int ENDCOM- See Also:
-
-
Constructor Details
-
DoomPK3
Opens a DoomPK3 file for reading and caches its contents.- Parameters:
path
- the path to the file to open.- Throws:
ZipException
- if this is not a PK3/ZIP archive.IOException
- if the file cannot be read.
-
DoomPK3
Opens a DoomPK3 file for reading and caches its contents.- Parameters:
pk3File
- the file to open.- Throws:
ZipException
- if this is not a PK3/ZIP archive.IOException
- if the file cannot be read.
-
-
Method Details
-
getFilePath
Gets this file's path.- Returns:
- this file's path.
- See Also:
-
getFileName
Gets this file's name (and just the name).- Returns:
- this file's name (and just the name).
- See Also:
-
refreshEntries
public final void refreshEntries()Refreshes the entry lists, if ZIP contents changed. -
getEntriesStartingWith
Returns a list of all entries that start with a type of key. This is treated case-insensitively.- Parameters:
key
- the start of an entry.- Returns:
- an array of entry names starting with the key string.
-
getEntryCount
public int getEntryCount()- Returns:
- the amount of entries in this archive.
-
contains
Checks if this Wad contains a particular entry.The name is case-insensitive.
- Parameters:
entryName
- the name of the entry.- Returns:
- true if so, false if not.
-
getData
Gets the data in one entry in the PK3 by entry name (path and all).- Parameters:
entryName
- the entry to extract and return as a byte array.- Returns:
- a byte array of the entry's data, or null if the entry doesn't exist.
- Throws:
IOException
- if a read error occurs.ZipException
- if a ZIP format error has occurredIllegalStateException
- if the zip file has been closed
-
getInputStream
Gets the data in one entry in the PK3 as an input stream by entry name (path and all).- Parameters:
entry
- the entry to extract and return as a byte array.- Returns:
- an InputStream of the entry's data, or null if the entry doesn't exist.
- Throws:
IOException
- if a read error occurs.ZipException
- if a ZIP format error has occurredIllegalStateException
- if the zip file has been closed
-
getFile
Gets the data in one entry in the PK3 and extracts it to a file. If the target file exists, it is overwritten.- Parameters:
entryName
- the entry to extract and return as a byte array.outFilePath
- the destination file path for the data.- Returns:
- a reference to the file created, or null if the entry doesn't exist.
- Throws:
IOException
- if a read error occurs.FileNotFoundException
- if the target file is a directory.SecurityException
- if the file could not be created due to system permission.ZipException
- if a ZIP format error has occurredIllegalStateException
- if the zip file has been closed
-
getFile
Gets the data in one entry in the PK3 and extracts it to a file. If the target file exists, it is overwritten.- Parameters:
entryName
- the entry to extract and return as a byte array.outFile
- the destination file for the data.- Returns:
- a reference to the file created, or null if the entry doesn't exist.
- Throws:
IOException
- if a read error occurs.FileNotFoundException
- if the target file is a directory.SecurityException
- if the file could not be created due to system permission.ZipException
- if a ZIP format error has occurredIllegalStateException
- if the zip file has been closed
-
getTextData
Retrieves the data for a particular entry as a decoded string of characters.The name is case-insensitive.
- Parameters:
entryName
- the name of the entry to find.charset
- the source charset.- Returns:
- the data, decoded, or null if the entry doesn't exist.
- Throws:
IOException
- if the data couldn't be retrieved.ZipException
- if a ZIP format error has occurredIllegalStateException
- if the zip file has been closedNullPointerException
- ifentryName
isnull
.- See Also:
-
getReader
Retrieves a Reader for a particular entry as a decoded stream of characters.The name is case-insensitive.
- Parameters:
entryName
- the name of the entry to find.charset
- the source charset.- Returns:
- a Reader for reading the character stream, or null if the entry doesn't exist.
- Throws:
IOException
- if the data couldn't be retrieved.ZipException
- if a ZIP format error has occurredIllegalStateException
- if the zip file has been closedNullPointerException
- ifentryName
isnull
.- See Also:
-
getTextDataAs
public <TO extends TextObject> TO getTextDataAs(String entryName, Charset charset, Class<TO> type) throws IOException Retrieves the data of the first occurrence of a particular entry as an interpreted text-originating object.The name is case-insensitive.
- Type Parameters:
TO
- the result type.- Parameters:
entryName
- the name of the entry to find.charset
- the source charset encoding.type
- the object type to convert the text data to.- Returns:
- the data, decoded, or null if the entry doesn't exist.
- Throws:
IOException
- if the data couldn't be retrieved or the entry's offsets breach the file extents.ZipException
- if a ZIP format error has occurredIllegalStateException
- if the zip file has been closedNullPointerException
- ifentryName
isnull
.- See Also:
-
getDataAs
Retrieves the data for a particular entry as a deserialized lump.The name is case-insensitive.
- Type Parameters:
BO
- a type that extends BinaryObject.- Parameters:
entryName
- the name of the entry to find.type
- the class type to deserialize into.- Returns:
- the data, deserialized, or null if the entry doesn't exist.
- Throws:
IOException
- if the data couldn't be retrieved.ZipException
- if a ZIP format error has occurredIllegalStateException
- if the zip file has been closedNullPointerException
- ifentryName
isnull
.- See Also:
-
getDataAs
public <BO extends BinaryObject> BO[] getDataAs(String entryName, Class<BO> type, int objectLength) throws IOException Retrieves the data for a particular entry as a deserialized lump of multiple objects.The name is case-insensitive.
- Type Parameters:
BO
- a type that extends BinaryObject.- Parameters:
entryName
- the name of the entry to find.type
- the class type to deserialize into.objectLength
- the length of each individual object in bytes.- Returns:
- the data, deserialized, or null if the entry doesn't exist.
- Throws:
IOException
- if the data couldn't be retrieved.ZipException
- if a ZIP format error has occurredIllegalStateException
- if the zip file has been closedNullPointerException
- ifentryName
isnull
.- See Also:
-
getDataAsList
public <BO extends BinaryObject> List<BO> getDataAsList(String entryName, Class<BO> type, int objectLength) throws IOException Retrieves the data for a particular entry as a deserialized lump of multiple objects.The name is case-insensitive.
- Type Parameters:
BO
- a type that extends BinaryObject.- Parameters:
entryName
- the name of the entry to find.type
- the class type to deserialize into.objectLength
- the length of each individual object in bytes.- Returns:
- the data, deserialized, or null if the entry doesn't exist.
- Throws:
IOException
- if the data couldn't be retrieved.ZipException
- if a ZIP format error has occurredIllegalStateException
- if the zip file has been closedNullPointerException
- ifentryName
isnull
.- See Also:
-
getDataAsWadMap
Retrieves the data for a particular entry, presuming it to be a WAD of some kind, and returns it as a WadMap.- Parameters:
entryName
- the name of the entry to find.- Returns:
- a WadMap representing the contents of the entry, or null if the entry doesn't exist.
- Throws:
IOException
- if the data couldn't be retrieved.ZipException
- if a ZIP format error has occurredIllegalStateException
- if the zip file has been closedNullPointerException
- ifentryName
isnull
.
-
getDataAsTempWadFile
Retrieves the data for a particular entry, extracts it, and, presuming it to be a WAD of some kind, opens it as a WadFile. If the target file exists, it is overwritten.NOTE: The WadFile returned is special: as soon as it is closed, it is deleted!
- Parameters:
entryName
- the entry to extract and return as a byte array.outFilePath
- the destination file path for the data.- Returns:
- a reference to the open WAD file created, or null if the entry doesn't exist.
- Throws:
IOException
- if a read error occurs.FileNotFoundException
- if the target file is a directory.SecurityException
- if the file could not be created due to system permission.ZipException
- if a ZIP format error has occurredIllegalStateException
- if the zip file has been closed
-
getDataAsTempWadFile
Retrieves the data for a particular entry, extracts it, and, presuming it to be a WAD of some kind, opens it as a WadFile. If the target file exists, it is overwritten.NOTE: The WadFile returned is special: as soon as it is closed, it is deleted!
- Parameters:
entryName
- the entry to extract and return as a byte array.outFile
- the destination file for the data.- Returns:
- a reference to the open WAD file created, or null if the entry doesn't exist.
- Throws:
IOException
- if a read error occurs.FileNotFoundException
- if the target file is a directory.SecurityException
- if the file could not be created due to system permission.ZipException
- if a ZIP format error has occurredIllegalStateException
- if the zip file has been closed
-
getDataAsWadBuffer
Retrieves the data for a particular entry, presuming it to be a WAD of some kind, and returns it as a fully read WadBuffer. Changing the WadBuffer does NOT change the entry data.- Parameters:
entryName
- the name of the entry to find.- Returns:
- a WadBuffer containing the contents of the entry, or null if the entry doesn't exist.
- Throws:
IOException
- if the data couldn't be retrieved.ZipException
- if a ZIP format error has occurredIllegalStateException
- if the zip file has been closedNullPointerException
- ifentryName
isnull
.
-
getScanner
public <BO extends BinaryObject> BinaryObject.Scanner<BO> getScanner(String entryName, Class<BO> type, int objectLength) throws IOException Retrieves the data for a particular entry and returns it as a deserializing scanner iterator that returns independent instances of objects.The name is case-insensitive.
If you don't intend to read the entirety of the entry via the
BinaryObject.InlineScanner
, close it after you finish (or use a try-with-resources block)!- Type Parameters:
BO
- a type that extends BinaryObject.- Parameters:
entryName
- the name of the entry to find.type
- the class type to deserialize into.objectLength
- the length of each object in the entry in bytes.- Returns:
- a scanner for the data, or null if the entry can't be found.
- Throws:
IOException
- if the data couldn't be retrieved.ZipException
- if a ZIP format error has occurredIllegalStateException
- if the zip file has been closed
-
getInlineScanner
public <BO extends BinaryObject> BinaryObject.InlineScanner<BO> getInlineScanner(String entryName, Class<BO> type, int objectLength) throws IOException Retrieves the data for a particular entry and returns it as a deserializing scanner iterator that returns the same object instance with its contents changed.This is useful for when you would want to quickly scan through a set of serialized objects while ensuring low memory use. Do NOT store the references returned by
next()
anywhere as the contents of that reference will be changed by the next call tonext()
.The name is case-insensitive.
If you don't intend to read the entirety of the entry via the
BinaryObject.InlineScanner
, close it after you finish (or use a try-with-resources block)!- Type Parameters:
BO
- a type that extends BinaryObject.- Parameters:
entryName
- the name of the entry to find.type
- the class type to deserialize into.objectLength
- the length of each object in the entry in bytes.- Returns:
- a scanner for the data, or null if the entry can't be found.
- Throws:
IOException
- if the data couldn't be retrieved.ZipException
- if a ZIP format error has occurredIllegalStateException
- if the zip file has been closed
-
getEntryName
Gets the "entry name" for a ZipEntry, which is just the filename itself minus extension.- Parameters:
ze
- the ZipEntry to use.- Returns:
- the "entry name" for this ZipEntry.
-