src/core/net/sf/basedb/util/zip/FilePacker.java

Code
Comments
Other
Rev Date Author Line
3568 18 Jul 07 martin 1 /**
3568 18 Jul 07 martin 2 $Id$
3568 18 Jul 07 martin 3
3675 16 Aug 07 jari 4 Copyright (C) 2007 Nicklas Nordborg, Martin Svensson
4889 06 Apr 09 nicklas 5 Copyright (C) 2008 Jari Häkkinen
3568 18 Jul 07 martin 6
3568 18 Jul 07 martin 7 This file is part of BASE - BioArray Software Environment.
3568 18 Jul 07 martin 8 Available at http://base.thep.lu.se/
3568 18 Jul 07 martin 9
3568 18 Jul 07 martin 10 BASE is free software; you can redistribute it and/or modify it
3568 18 Jul 07 martin 11 under the terms of the GNU General Public License as published by
4479 05 Sep 08 jari 12 the Free Software Foundation; either version 3 of the License, or
3568 18 Jul 07 martin 13 (at your option) any later version.
3568 18 Jul 07 martin 14
3568 18 Jul 07 martin 15 BASE is distributed in the hope that it will be useful, but
3568 18 Jul 07 martin 16 WITHOUT ANY WARRANTY; without even the implied warranty of
3568 18 Jul 07 martin 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
3568 18 Jul 07 martin 18 General Public License for more details.
3568 18 Jul 07 martin 19
3568 18 Jul 07 martin 20 You should have received a copy of the GNU General Public License
4515 11 Sep 08 jari 21 along with BASE. If not, see <http://www.gnu.org/licenses/>.
3568 18 Jul 07 martin 22 */
3568 18 Jul 07 martin 23
3568 18 Jul 07 martin 24 package net.sf.basedb.util.zip;
3568 18 Jul 07 martin 25
3568 18 Jul 07 martin 26 import java.io.IOException;
3641 08 Aug 07 nicklas 27 import java.io.InputStream;
3568 18 Jul 07 martin 28 import java.io.OutputStream;
3568 18 Jul 07 martin 29
8094 04 Nov 22 nicklas 30 import net.sf.basedb.core.PluginParameter;
8094 04 Nov 22 nicklas 31 import net.sf.basedb.core.StringParameterType;
8094 04 Nov 22 nicklas 32
3568 18 Jul 07 martin 33 /**
3641 08 Aug 07 nicklas 34    This interface should be implemented by classes that can pack files and directories
4483 07 Sep 08 jari 35    from BASE file system. The implementing class must also have a public no-argument
3641 08 Aug 07 nicklas 36    constructor. The implementing classes are used by the  
3641 08 Aug 07 nicklas 37    {@link net.sf.basedb.plugins.PackedFileExporter} plug-in. Each class should
3641 08 Aug 07 nicklas 38    be registered in a {@link net.sf.basedb.core.PluginConfiguration} for the
3641 08 Aug 07 nicklas 39    <code>PackedFileExporter</code>.
3641 08 Aug 07 nicklas 40    
3641 08 Aug 07 nicklas 41     @author Martin, Nicklas
3568 18 Jul 07 martin 42     @version 2.4    
3568 18 Jul 07 martin 43     @base.modified $Date: 2006-11-30 10:50:05 +0100 (Thu, 30 Nov 2006) $
3641 08 Aug 07 nicklas 44 */
3568 18 Jul 07 martin 45 public interface FilePacker
7551 12 Dec 18 nicklas 46   extends AutoCloseable
3568 18 Jul 07 martin 47 {
3641 08 Aug 07 nicklas 48   
3568 18 Jul 07 martin 49   /**
3641 08 Aug 07 nicklas 50     Get a short description of this file format that is suitable for display in
3641 08 Aug 07 nicklas 51     selection list boxes.
3568 18 Jul 07 martin 52   */
3641 08 Aug 07 nicklas 53   public String getDescription();
3641 08 Aug 07 nicklas 54   
3641 08 Aug 07 nicklas 55   /**
3641 08 Aug 07 nicklas 56      Gets the extension that files, packed with this tool, should have,
3641 08 Aug 07 nicklas 57      for example, <code>zip</code> or <code>tar.gz</code> Don't include the first 
3641 08 Aug 07 nicklas 58      dot!
3641 08 Aug 07 nicklas 59       @return A String with the file extension excluding the dot
3641 08 Aug 07 nicklas 60   */
3568 18 Jul 07 martin 61   public String getFileExtension();
3568 18 Jul 07 martin 62   
3568 18 Jul 07 martin 63   /**
3641 08 Aug 07 nicklas 64     Gets the MIME type to give compressed files from this packer
3641 08 Aug 07 nicklas 65       @return The MIME type of the compressed file format
3641 08 Aug 07 nicklas 66   */
3568 18 Jul 07 martin 67   public String getMimeType();
3568 18 Jul 07 martin 68   
3568 18 Jul 07 martin 69   /**
8094 04 Nov 22 nicklas 70     Does the packer support encryption or not?
8094 04 Nov 22 nicklas 71     The default implementation return false.
8094 04 Nov 22 nicklas 72     @since 3.19.5
8094 04 Nov 22 nicklas 73   */
8094 04 Nov 22 nicklas 74   public default boolean supportsEncryption()
8094 04 Nov 22 nicklas 75   {
8094 04 Nov 22 nicklas 76     return false;
8094 04 Nov 22 nicklas 77   }
8094 04 Nov 22 nicklas 78   
8094 04 Nov 22 nicklas 79   /**
8094 04 Nov 22 nicklas 80     The default implementation return a parameter asking for a password.
8094 04 Nov 22 nicklas 81     The implementing class may create another parameter as long as it is
8094 04 Nov 22 nicklas 82     named "password". This method is only called if the implementation
8094 04 Nov 22 nicklas 83     supports encryption.
8094 04 Nov 22 nicklas 84     @since 3.19.5
8094 04 Nov 22 nicklas 85   */
8094 04 Nov 22 nicklas 86   public default PluginParameter<String> getPasswordParameter()
8094 04 Nov 22 nicklas 87   {
8094 04 Nov 22 nicklas 88     PluginParameter<String> passwordParameter = new PluginParameter<String>
8094 04 Nov 22 nicklas 89     (
8094 04 Nov 22 nicklas 90       "password", "Password", "Enter a password to encrypt the archive." , new StringParameterType()
8094 04 Nov 22 nicklas 91     );
8094 04 Nov 22 nicklas 92     return passwordParameter;
8094 04 Nov 22 nicklas 93   }
8094 04 Nov 22 nicklas 94   
8094 04 Nov 22 nicklas 95   /**
8094 04 Nov 22 nicklas 96     Set the password to use for encrypting the archive. This method
8094 04 Nov 22 nicklas 97     is only called if the implementation supports encryption and the
8094 04 Nov 22 nicklas 98     user has entered a password.
8094 04 Nov 22 nicklas 99     @since 3.19.5
8094 04 Nov 22 nicklas 100   */
8094 04 Nov 22 nicklas 101   public default void setPassword(String password)
8094 04 Nov 22 nicklas 102   {}
8094 04 Nov 22 nicklas 103   
8094 04 Nov 22 nicklas 104   /**
3641 08 Aug 07 nicklas 105     The output stream that the compressed files should be written to.
3641 08 Aug 07 nicklas 106     @param out The output stream to write to
3641 08 Aug 07 nicklas 107     @throws IOException If there is an error setting the output stream
3641 08 Aug 07 nicklas 108   */
3641 08 Aug 07 nicklas 109   public void setOutputStream(OutputStream out)
3641 08 Aug 07 nicklas 110     throws IOException;
3568 18 Jul 07 martin 111   
3568 18 Jul 07 martin 112   /**
3641 08 Aug 07 nicklas 113      Compress the uncompressed input stream to an entry with the given
3641 08 Aug 07 nicklas 114      name into the outputstream.
3643 08 Aug 07 nicklas 115      @param entryName The name of the packed resource, including path 
3643 08 Aug 07 nicklas 116        information
3641 08 Aug 07 nicklas 117       @param in The input stream to read uncompressed data from, or null
3641 08 Aug 07 nicklas 118         if the entry represents a directory
3641 08 Aug 07 nicklas 119       @param size The number of bytes of uncompressed data
3641 08 Aug 07 nicklas 120       @param lastModified The time the contents was last modified, or 0
3641 08 Aug 07 nicklas 121         if not known
3641 08 Aug 07 nicklas 122       @throws IOException If there are any errors when reading or writing
3641 08 Aug 07 nicklas 123   */
3641 08 Aug 07 nicklas 124   public void pack(String entryName, InputStream in, long size, long lastModified)
3568 18 Jul 07 martin 125     throws IOException;
3641 08 Aug 07 nicklas 126   
3641 08 Aug 07 nicklas 127   /**
3646 09 Aug 07 nicklas 128     End the packing and close. The plug-in should close any open resources, including
3646 09 Aug 07 nicklas 129     the output stream set by the {@link #setOutputStream(OutputStream)} method, and
3646 09 Aug 07 nicklas 130     cleanup temporary objects.
3641 08 Aug 07 nicklas 131     
3641 08 Aug 07 nicklas 132       @throws IOException If there are any errors
3641 08 Aug 07 nicklas 133   */
7551 12 Dec 18 nicklas 134   @Override
3641 08 Aug 07 nicklas 135   public void close()
3641 08 Aug 07 nicklas 136     throws IOException;
3568 18 Jul 07 martin 137 }