1   /**
2    * Distribution License:
3    * JSword is free software; you can redistribute it and/or modify it under
4    * the terms of the GNU Lesser General Public License, version 2.1 as published by
5    * the Free Software Foundation. This program is distributed in the hope
6    * that it will be useful, but WITHOUT ANY WARRANTY; without even the
7    * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8    * See the GNU Lesser General Public License for more details.
9    *
10   * The License is available on the internet at:
11   *       http://www.gnu.org/copyleft/lgpl.html
12   * or by writing to:
13   *      Free Software Foundation, Inc.
14   *      59 Temple Place - Suite 330
15   *      Boston, MA 02111-1307, USA
16   *
17   * Copyright: 2007
18   *     The copyright to this program is held by it's authors.
19   *
20   * ID: $Id: CompressorType.java 2050 2010-12-09 15:31:45Z dmsmith $
21   */
22  package org.crosswire.common.compress;
23  
24  import java.io.ByteArrayInputStream;
25  
26  /**
27   * An Enumeration of the possible Compressions.
28   * 
29   * @see gnu.lgpl.License for license details.<br>
30   *      The copyright to this program is held by it's authors.
31   * @author DM Smith [dmsmith555 at yahoo dot com]
32   */
33  public enum CompressorType {
34      ZIP {
35          @Override
36          public Compressor getCompressor(byte[] input) {
37              return new Zip(new ByteArrayInputStream(input));
38          }
39      },
40  
41      LZSS {
42  
43          @Override
44          public Compressor getCompressor(byte[] input) {
45              return new LZSS(new ByteArrayInputStream(input));
46          }
47      };
48  
49      /**
50       * Get a compressor.
51       * @param input the stream to compress or to uncompress.
52       */
53      public abstract Compressor getCompressor(byte[] input);
54  
55      /**
56       * Get a CompressorType from a String
57       * 
58       * @param name the case insensitive representation of the desired CompressorType
59       * @return the desired compressor or null if not found.
60       */
61      public static CompressorType fromString(String name) {
62          for (CompressorType v : values()) {
63              if (v.name().equalsIgnoreCase(name)) {
64                  return v;
65              }
66          }
67  
68          // cannot get here
69          assert false;
70          return null;
71      }
72  }
73