Class ArchiveWriter

All Implemented Interfaces:
Closeable, AutoCloseable

public class ArchiveWriter extends DataArchive
An ArchiveWriter is a writeable DataArchive. New files may be added with the addFile(java.lang.String, java.lang.String) and addImage(java.lang.String, java.lang.String) methods. save() and saveAs() will cause the archive to be written out, with FileChooser invoked if appropriate.
  • Constructor Details

    • ArchiveWriter

      public ArchiveWriter(String zipName, String defaultExtension)
      Create a new writeable archive.
      Parameters:
      zipName - the name of the archive. If null, the user will be prompted for a filename when saving. If not null, new entries will be added to the named archive. If the file exists and is not a zip archive, it will be overwritten.
      defaultExtension - the default file extension for the archive. If non-null, and the user needs to be prompted for a filename, this will be the default file extension added automatically.
    • ArchiveWriter

      public ArchiveWriter(FileArchive archive, String defaultExtension)
    • ArchiveWriter

      public ArchiveWriter(String zipName)
      Create a new writeable archive.
      Parameters:
      zipName - the name of the archive. If null, the user will be prompted for a filename when saving. If not null, new entries will be added to the named archive. If the file exists and is not a zip archive, it will be overwritten.
    • ArchiveWriter

      public ArchiveWriter(FileArchive archive)
  • Method Details

    • addImage

      public void addImage(String path, String name)
      Add an image file to the archive. The file will be copied into an "images" directory in the archive. Storing another image with the same name will overwrite the previous image.
      Parameters:
      path - the full path of the image file on the user's filesystem
      name - the name under which to store the image in the archive
    • addImage

      public void addImage(String name, byte[] contents)
    • addSound

      public void addSound(String path, String fileName)
    • removeImage

      public void removeImage(String name)
    • removeFile

      public void removeFile(String name)
      Removes a file in the archive
      Parameters:
      name - file in the archive to be removed
    • addFile

      public void addFile(String path, String fileName)
      Copy a file from the user's filesystem to the archive.
      Parameters:
      path - the full path of the file on the user's filesystem
      fileName - the name under which to store the file in the archive
    • addFile

      public void addFile(String fileName, InputStream in)
      Copy an InputStream into the archive
      Parameters:
      fileName - the name under which to store the contents of the stream
      in - the stream to copy
    • addFile

      public void addFile(String fileName, byte[] content)
      Copy am array of bytes into the archive
      Parameters:
      fileName - the name under which to store the contents of the stream
      content - array of bytes to copy
    • save

      public void save() throws IOException
      Throws:
      IOException
    • save

      public void save(boolean notifyModuleManager) throws IOException
      Throws:
      IOException
    • saveAs

      public void saveAs() throws IOException
      Throws:
      IOException
    • saveAs

      public void saveAs(boolean notifyModuleManager) throws IOException
      Throws:
      IOException
    • saveButVerify

      public boolean saveButVerify() throws IOException
      Saves the archive, prompting for a name only if none has ever been provided.
      Throws:
      IOException - IOException
    • saveButVerify

      public boolean saveButVerify(boolean notifyModuleManager) throws IOException
      Saves the archive, prompting for a name only if none has ever been provided.
      Parameters:
      notifyModuleManager - If true, notifies Module Manager that the save has occurred
      Throws:
      IOException - IOException
    • saveAsButVerify

      public boolean saveAsButVerify() throws IOException
      Saves the archive, always prompting for a new filename.
      Throws:
      IOException - IOException
    • write

      protected void write(FileArchive fa, boolean notifyModuleManager) throws IOException
      Writes the file archive.
      Parameters:
      fa - File archive
      notifyModuleManager - if true, notifies the module manager that a file has been saved.
      Throws:
      IOException - IOException
    • saveAsButVerify

      public boolean saveAsButVerify(boolean notifyModuleManager) throws IOException
      Saves the archive, always prompting for a new filename. If a defaultExtension has been provided, it will be added to the filename unless the user specifies a different one explicitly.
      Parameters:
      notifyModuleManager - If true, notifies Module Manager that the save has occurred
      Returns:
      true if operation proceeded, false if it was cancelled by user at file chooser or confirmation dialog
      Throws:
      IOException - IOException