Class Importer

java.lang.Object
VASSAL.tools.imports.Importer
Direct Known Subclasses:
ADC2Module, MapBoard, SymbolSet

public abstract class Importer extends Object
Abstract parent of all importer classes.
Since:
3.1.0
Author:
Michael Kiefte
  • Field Details

  • Constructor Details

    • Importer

      public Importer()
  • Method Details

    • insertComponent

      protected static void insertComponent(Buildable child, Buildable parent)
    • getMainMap

      protected Map getMainMap()
      Returns:
      The VASSAL Map object corresponding to this imported map.
    • getLayeredPieceCollection

      protected LayeredPieceCollection getLayeredPieceCollection()
    • load

      protected void load(File f) throws IOException
      The method that actually loads the file and creates the classes containing information needed for the archive. The archive is written in writeToArchive.
      Parameters:
      f - The base file to be imported.
      Throws:
      IOException - oops
    • writeToArchive

      public abstract void writeToArchive() throws IOException
      Create the VASSAL module based on the classes created by load. This should not be called directly but rather importFile.
      Throws:
      IOException - oops
    • importFile

      public void importFile(ImportAction action, File f) throws IOException
      Two methods are needed to import a file. Importer.importFile initializes the game module and calls load which must be overridden by descendants.
      Parameters:
      action - ImportAction which creates the Importer. This is needed for file dialogs that may be called by Importer methods.
      f - The base file to be imported.
      Throws:
      IOException - oops
    • stripExtension

      public static String stripExtension(String s)
      Return a file name without the extension.
    • readWindowsFileName

      public static String readWindowsFileName(InputStream in) throws IOException
      Read a null-terminated string representing a Windows file name and convert Windows separator characters '\\' to the local separator character. This is the default file name format for many imported modules and should be used whenever a filename is read as a null-terminated string in order to ensure platform independence.
      Throws:
      IOException
    • readNullTerminatedString

      public static String readNullTerminatedString(InputStream in, int maxLen) throws IOException
      Read a null-terminated string from a file up to a maximum length which includes the null termination. If the actual string is longer, no more bytes will be read.
      Throws:
      IOException
    • readNullTerminatedString

      public static String readNullTerminatedString(InputStream in) throws IOException
      Return a null-terminated string from an input stream.
      Throws:
      IOException
    • getUniqueImageFileName

      public static String getUniqueImageFileName(String s, String ext)
      Get a unique file name for an image in the game module archive. This function tests the provided name against those that are already present in the archive and if the file name already exists, creates an alternate, unique file name. If an alternate is created, it is of the form name + "(n)" where n is an integer.
    • getUniqueImageFileName

      public static String getUniqueImageFileName(String s)
    • getFileName

      public static String getFileName(String s)
      Get the file name without the qualifying path.
    • getExtension

      public static String getExtension(String s)
      Get the extension from a file name.
    • forceExtension

      public static String forceExtension(String s, String ext)
      Strip the extension from a filename and replace with the given extension.
    • isValidImportFile

      public abstract boolean isValidImportFile(File f) throws IOException
      Determine whether the file is valid for the given importer.
      Parameters:
      f - File
      Returns:
      true if f is a valid file for this type.
      Throws:
      FileNotFoundException - oops
      IOException - oops