Class WadUtils

java.lang.Object
net.mtrop.doom.util.WadUtils

public final class WadUtils extends Object
WAD utility methods and functions.
Author:
Matthew Tropiano
  • Method Details

    • withEntries

      public static WadUtils.WadEntryAccumulator withEntries(WadEntry... entries)
      Creates a WadEntry accumulator with a set of entries.
      Parameters:
      entries - the entries to start the accumulator with.
      Returns:
      a new accumulator with the provided entries already added.
      Since:
      2.5.0
    • cleanEntries

      public static void cleanEntries(Wad source, File destination) throws IOException
      Creates a new WAD file by copying the contents of an existing WAD to another file, which discards all un-addressed data from the first. The source Wad must be an implementation that supports retrieving data from it.
      Parameters:
      source - the source Wad.
      destination - the destination file.
      Throws:
      UnsupportedOperationException - if the provided Wad is not an implementation that you can read data from.
      SecurityException - if the target file cannot be written to due to security reasons.
      IOException - if a read or write error occurs.
    • getEntriesInNamespace

      public static WadEntry[] getEntriesInNamespace(Wad wad, String prefix)
      Finds all entries within a WAD entry namespace. A namespace is marked by one or two characters and "_START" or "_END" as a suffix. All entries in between are considered part of the "namespace."

      The returned entries are valid only to the provided WAD. Using entry information with unassociated WADs could create undesired results.

      Parameters:
      prefix - the namespace prefix to use (e.g. "F" or "FF" for flats, "P" or "PP" for patches, etc.).
      wad - the WAD file to scan.
      Returns:
      an array of all entries in the namespace, or an empty array if none are found.
    • getEntriesInNamespace

      public static WadEntry[] getEntriesInNamespace(Wad wad, String prefix, Pattern ignorePattern)
      Finds all entries within a WAD entry namespace. A namespace is marked by one or two characters and "_START" or "_END" as a suffix. All entries in between are considered part of the "namespace."

      The returned entries are valid only to the provided WAD. Using entry information with unassociated WADs could create undesired results.

      Parameters:
      prefix - the namespace prefix to use (e.g. "F" or "FF" for flats, "P" or "PP" for texture patches, etc.).
      wad - the WAD file to scan.
      ignorePattern - the regex pattern to use for deciding which entries in the namespace to ignore.
      Returns:
      an array of all entries in the namespace, or an empty array if none are found.
    • createWadAnd

      public static void createWadAnd(String path, WadUtils.WadConsumer wadConsumer) throws IOException
      Creates a new WAD file, performs an action on it, and then closes it automatically afterward. The opened WAD is passed to the provided WadUtils.WadConsumer.
      Parameters:
      path - the path to the WAD file.
      wadConsumer - a WadUtils.WadConsumer that takes the opened Wad as its only parameter.
      Throws:
      IOException - if any I/O exception occurs.
      Since:
      2.6.0
    • createWadAnd

      public static void createWadAnd(File path, WadUtils.WadConsumer wadConsumer) throws IOException
      Creates a new WAD file, performs an action on it, and then closes it automatically afterward. The opened WAD is passed to the provided WadUtils.WadConsumer.
      Parameters:
      path - the path to the WAD file.
      wadConsumer - a WadUtils.WadConsumer that takes the opened Wad as its only parameter.
      Throws:
      IOException - if any I/O exception occurs.
      Since:
      2.6.0
    • openWadAnd

      public static void openWadAnd(String path, WadUtils.WadConsumer wadConsumer) throws IOException
      Opens a WAD file, performs an action on it, and then closes it automatically afterward. The opened WAD is passed to the provided WadUtils.WadConsumer.
      Parameters:
      path - the path to the WAD file.
      wadConsumer - a WadUtils.WadConsumer that takes the opened Wad as its only parameter.
      Throws:
      IOException - if any I/O exception occurs.
      Since:
      2.5.0
    • openWadAnd

      public static void openWadAnd(File path, WadUtils.WadConsumer wadConsumer) throws IOException
      Opens a WAD file, performs an action on it, and then closes it automatically afterward. The opened WAD is passed to the provided WadUtils.WadConsumer.

      This method is intended for pure convenience, and will throw a RuntimeException if an exception occurs. Do not use this if you intend to handle errors explicitly.

      Parameters:
      path - the path to the WAD file.
      wadConsumer - a WadUtils.WadConsumer that takes the opened Wad as its only parameter.
      Throws:
      IOException - if any I/O exception occurs.
      Since:
      2.5.0
    • openWadAndGet

      public static <R> R openWadAndGet(String path, WadUtils.WadFunction<R> wadFunction) throws IOException
      Opens a WAD file, retrieves information from it, and then closes it automatically afterward. The opened WAD is passed to the provided WadUtils.WadFunction.

      This method is intended for pure convenience, and will throw a RuntimeException if an exception occurs. Do not use this if you intend to handle errors explicitly.

      Type Parameters:
      R - the return type.
      Parameters:
      path - the path to the WAD file.
      wadFunction - a WadUtils.WadFunction that takes the opened Wad as its only parameter.
      Returns:
      the data returned from the provided function.
      Throws:
      IOException - if any I/O exception occurs.
      Since:
      2.5.0
    • openWadAndGet

      public static <R> R openWadAndGet(File path, WadUtils.WadFunction<R> wadFunction) throws IOException
      Opens a WAD file, retrieves information from it (which is returned), and then closes it automatically afterward. The opened WAD is passed to the provided WadUtils.WadFunction.

      This method is intended for pure convenience, and will throw a RuntimeException if an exception occurs. Do not use this if you intend to handle errors explicitly.

      Type Parameters:
      R - the return type.
      Parameters:
      path - the path to the WAD file.
      wadFunction - a WadUtils.WadFunction that takes the opened Wad as its only parameter.
      Returns:
      the data returned from the provided function.
      Throws:
      IOException - if any I/O exception occurs.
      Since:
      2.5.0
    • openWadAndExtractTo

      public static void openWadAndExtractTo(String path, String outPath, WadUtils.WadFunction<WadEntry[]> wadFunction) throws IOException
      Opens a WAD file, exports a list of entries to a new WAD, and then closes both automatically afterward. The opened WAD is passed to the provided WadUtils.WadFunction.

      This method is intended for pure convenience, and will throw a RuntimeException if an exception occurs. Do not use this if you intend to handle errors explicitly.

      Parameters:
      path - the path to the WAD file.
      outPath - the output path for the new WAD file.
      wadFunction - a WadUtils.WadFunction that takes the opened Wad as its only parameter.
      Throws:
      IOException - if any I/O exception occurs.
      Since:
      2.5.0
    • openWadAndExtractTo

      public static void openWadAndExtractTo(String path, File outPath, WadUtils.WadFunction<WadEntry[]> wadFunction) throws IOException
      Opens a WAD file, exports a list of entries to a new WAD, and then closes both automatically afterward. The opened WAD is passed to the provided WadUtils.WadFunction.

      This method is intended for pure convenience, and will throw a RuntimeException if an exception occurs. Do not use this if you intend to handle errors explicitly.

      Parameters:
      path - the path to the WAD file.
      outPath - the output path for the new WAD file.
      wadFunction - a WadUtils.WadFunction that takes the opened Wad as its only parameter.
      Throws:
      IOException - if any I/O exception occurs.
      Since:
      2.5.0
    • openWadAndExtractTo

      public static void openWadAndExtractTo(File path, String outPath, WadUtils.WadFunction<WadEntry[]> wadFunction) throws IOException
      Opens a WAD file, exports a list of entries to a new WAD, and then closes both automatically afterward. The opened WAD is passed to the provided WadUtils.WadFunction.

      This method is intended for pure convenience, and will throw a RuntimeException if an exception occurs. Do not use this if you intend to handle errors explicitly.

      Parameters:
      path - the path to the WAD file.
      outPath - the output path for the new WAD file.
      wadFunction - a WadUtils.WadFunction that takes the opened Wad as its only parameter.
      Throws:
      IOException - if any I/O exception occurs.
      Since:
      2.5.0
    • openWadAndExtractTo

      public static void openWadAndExtractTo(File path, File outPath, WadUtils.WadFunction<WadEntry[]> wadFunction) throws IOException
      Opens a WAD file, exports a list of entries to a new WAD, and then closes both automatically afterward. The opened WAD is passed to the provided WadUtils.WadFunction.

      This method is intended for pure convenience, and will throw a RuntimeException if an exception occurs. Do not use this if you intend to handle errors explicitly.

      Parameters:
      path - the path to the WAD file.
      outPath - the output path for the new WAD file.
      wadFunction - a WadUtils.WadFunction that takes the opened Wad as its only parameter.
      Throws:
      IOException - if any I/O exception occurs.
      Since:
      2.5.0
    • openWadAndExtractBuffer

      public static WadBuffer openWadAndExtractBuffer(String path, WadUtils.WadFunction<WadEntry[]> wadFunction) throws IOException
      Opens a WAD file, exports a list of entries to a new returned WadBuffer, and then closes it automatically afterward. The opened WAD is passed to the provided WadUtils.WadFunction.

      This method is intended for pure convenience, and will throw a RuntimeException if an exception occurs. Do not use this if you intend to handle errors explicitly.

      Parameters:
      path - the path to the WAD file.
      wadFunction - a WadUtils.WadFunction that takes the opened Wad as its only parameter.
      Returns:
      the WadBuffer with the desired entries.
      Throws:
      IOException - if any I/O exception occurs.
      Since:
      2.5.0
    • openWadAndExtractBuffer

      public static WadBuffer openWadAndExtractBuffer(File path, WadUtils.WadFunction<WadEntry[]> wadFunction) throws IOException
      Opens a WAD file, exports a list of entries to a new returned WadBuffer, and then closes it automatically afterward. The opened WAD is passed to the provided WadUtils.WadFunction.

      This method is intended for pure convenience, and will throw a RuntimeException if an exception occurs. Do not use this if you intend to handle errors explicitly.

      Parameters:
      path - the path to the WAD file.
      wadFunction - a WadUtils.WadFunction that takes the opened Wad as its only parameter.
      Returns:
      the WadBuffer with the desired entries.
      Throws:
      IOException - if any I/O exception occurs.
      Since:
      2.5.0