Class ZIPExportContainer
- java.lang.Object
-
- ca.cgjennings.apps.arkham.ZIPExportContainer
-
- All Implemented Interfaces:
ExportContainer
public class ZIPExportContainer extends java.lang.Object implements ExportContainer
An export container that creates ZIP archives.- Since:
- 3.0
- Author:
- Chris Jennings
-
-
Constructor Summary
Constructors Constructor Description ZIPExportContainer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.io.OutputStreamaddEntry(java.lang.String name)Creates a new file in the container with the given name and returns an output stream for the caller to write the file to.voidcloseContainer(boolean display)Close the current container, allowing a new container to be created.voidconfigure(java.awt.Component locationHint)Show a dialog allow the user to configure the container options.voidcreateContainer()Begins an export operation by creating an empty container.voiddestroyContainer()Destroys the current container instead of closing it.java.lang.StringgetIdentifier()Returns an identifier unique to this container type.booleanisConfigurable()Returnstrueif the container has user-configurable options.booleanisFileFormatSupported(java.lang.String extension)Returns a hint as to whether a file format is supported.booleanselectLocation(java.lang.String baseName, java.awt.Component locationHint)Displays a dialog that allows the user to select a destination for the container.voidsetLocation(java.io.File location)This method can be used to set an explicit location for the container instead of asking the user to select a location.java.lang.StringtoString()Returns a description of the container format, ideally in the user interface locale.
-
-
-
Method Detail
-
getIdentifier
public java.lang.String getIdentifier()
Description copied from interface:ExportContainerReturns an identifier unique to this container type. It is never shown to the user and must not be localized; it is used to identify the user's preferred container in user settings.- Specified by:
getIdentifierin interfaceExportContainer- Returns:
- a unique identifier for the container
-
selectLocation
public boolean selectLocation(java.lang.String baseName, java.awt.Component locationHint)Description copied from interface:ExportContainerDisplays a dialog that allows the user to select a destination for the container. The dialog is not necessarily a file dialog; for example, it might prompt the user to enter account credentials for an online service or enter the address of an FTP server. It is not required to show any dialog at all, and may simply returntrueif there is nothing for the user to decide.- Specified by:
selectLocationin interfaceExportContainer- Parameters:
baseName- a suggested base name that can be used to compose a file or folder name for the containerlocationHint- an optional component that may be used as a hint to locate any dialogs that must be created- Returns:
trueif the export should proceed, orfalseif the user cancels the operation
-
setLocation
public void setLocation(java.io.File location)
Description copied from interface:ExportContainerThis method can be used to set an explicit location for the container instead of asking the user to select a location. It can only work with containers that write to the local file system, such asFolderExportContainerandZIPExportContainer. The method is provided for testing and for use with explicitly created containers.- Specified by:
setLocationin interfaceExportContainer- Parameters:
location- the parent folder where the container should be created
-
createContainer
public void createContainer() throws java.io.IOExceptionDescription copied from interface:ExportContainerBegins an export operation by creating an empty container.- Specified by:
createContainerin interfaceExportContainer- Throws:
java.io.IOException- if an I/O error occurs
-
addEntry
public java.io.OutputStream addEntry(java.lang.String name) throws java.io.IOExceptionDescription copied from interface:ExportContainerCreates a new file in the container with the given name and returns an output stream for the caller to write the file to. After writing the file, you are responsible for callingclose()on the output stream.- Specified by:
addEntryin interfaceExportContainer- Parameters:
name- the name of the file to create in the container- Returns:
- an output stream to which the "file" should be written
- Throws:
java.io.IOException- if an I/O error occurs
-
closeContainer
public void closeContainer(boolean display) throws java.io.IOExceptionDescription copied from interface:ExportContainerClose the current container, allowing a new container to be created.- Specified by:
closeContainerin interfaceExportContainer- Parameters:
display- iftrue, the user has requested that the container be "displayed"- Throws:
java.io.IOException- if an I/O exception occurs
-
destroyContainer
public void destroyContainer()
Description copied from interface:ExportContainerDestroys the current container instead of closing it. This can be called instead ofExportContainer.closeContainer(boolean)if an I/O error occurs while writing the container. Ideally, it should delete the partially-created container.- Specified by:
destroyContainerin interfaceExportContainer
-
isFileFormatSupported
public boolean isFileFormatSupported(java.lang.String extension)
Description copied from interface:ExportContainerReturns a hint as to whether a file format is supported. This method returnstrueif the file type is definitely supported. It returnsfalseif the file type is not supported, or if the container cannot determine whether the file type is supported.A common use of this method is to determine whether a container is compatible with some kind of task being presented to the user. In these cases, implementations that always return
falsewill not be included in the list of container choices presented to the user.Some export containers may not support files in some formats: while a ZIP archive can hold any kind of file, an image hosting service might only accept, say, PNG and JPG images. This method allows an export container to return a hint to exporters as to whether a file format is compatible with the container. To use it, the caller passes in a string representing the typical file name extension for files of the format in question.
Note that the
ExportContainer.addEntry(java.lang.String)method is required to accept any content that it is given, but an export container may choose to do anything it wishes with unsupported formats. For example, it may skip the file by returning a dummy output stream. Or it may accept the file but silently convert it into an acceptable format. (The documentation for the container should specify how unsupported files are handled.)- Specified by:
isFileFormatSupportedin interfaceExportContainer- Parameters:
extension- the typical file format extension for the file, such as "png" for PNG images- Returns:
trueif the file type is definitely supported, andfalseotherwise
-
toString
public java.lang.String toString()
Description copied from interface:ExportContainerReturns a description of the container format, ideally in the user interface locale.- Specified by:
toStringin interfaceExportContainer- Overrides:
toStringin classjava.lang.Object- Returns:
- a description of the container, such as "ZIP Archive"
-
configure
public void configure(java.awt.Component locationHint)
Description copied from interface:ExportContainerShow a dialog allow the user to configure the container options.- Specified by:
configurein interfaceExportContainer- Parameters:
locationHint- an optional hint as to where to locate the dialog
-
isConfigurable
public boolean isConfigurable()
Description copied from interface:ExportContainerReturnstrueif the container has user-configurable options.- Specified by:
isConfigurablein interfaceExportContainer- Returns:
trueif the container can beExportContainer.configure(java.awt.Component)d
-
-