Uploaded image for project: 'Commons Compress'
  1. Commons Compress
  2. COMPRESS-368

Allow compressor extensions through a standard JRE ServiceLoader

    XMLWordPrintableJSON

    Details

    • Type: New Feature
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.13
    • Component/s: Compressors
    • Labels:
      None

      Description

      Allow compressor extensions through a standard JRE ServiceLoader.

      Introduce a new interface org.apache.commons.compress.compressors.CompressorStreamProvider

      Update CompressorStreamFactory to implement this new interface and use a service loader to pick up extra CompressorStreamProvider.

      The service loader file is META-INF/services/org.apache.commons.compress.compressors.CompressorStreamProvider

      The new interface:

      /*
       * Licensed to the Apache Software Foundation (ASF) under one
       * or more contributor license agreements.  See the NOTICE file
       * distributed with this work for additional information
       * regarding copyright ownership.  The ASF licenses this file
       * to you under the Apache License, Version 2.0 (the
       * "License"); you may not use this file except in compliance
       * with the License.  You may obtain a copy of the License at
       *
       * http://www.apache.org/licenses/LICENSE-2.0
       *
       * Unless required by applicable law or agreed to in writing,
       * software distributed under the License is distributed on an
       * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
       * KIND, either express or implied.  See the License for the
       * specific language governing permissions and limitations
       * under the License.
       */
      
      package org.apache.commons.compress.compressors;
      
      import java.io.InputStream;
      import java.io.OutputStream;
      import java.util.Set;
      
      /**
       * Creates Compressor {@link CompressorInputStream}s and
       * {@link CompressorOutputStream}s.
       * 
       * @since 1.13
       */
      public interface CompressorStreamProvider {
      
          /**
           * Creates a compressor input stream from a compressor name and an input
           * stream.
           * 
           * @param name
           *            of the compressor, i.e. {@value #GZIP}, {@value #BZIP2},
           *            {@value #XZ}, {@value #LZMA}, {@value #PACK200},
           *            {@value #SNAPPY_RAW}, {@value #SNAPPY_FRAMED}, {@value #Z} or
           *            {@value #DEFLATE}
           * @param in
           *            the input stream
           * @return compressor input stream
           * @throws CompressorException
           *             if the compressor name is not known
           * @throws IllegalArgumentException
           *             if the name or input stream is null
           */
          CompressorInputStream createCompressorInputStream(final String name, final InputStream in)
                  throws CompressorException;
      
          /**
           * Creates a compressor output stream from an compressor name and an output
           * stream.
           * 
           * @param name
           *            the compressor name, i.e. {@value #GZIP}, {@value #BZIP2},
           *            {@value #XZ}, {@value #PACK200} or {@value #DEFLATE}
           * @param out
           *            the output stream
           * @return the compressor output stream
           * @throws CompressorException
           *             if the archiver name is not known
           * @throws IllegalArgumentException
           *             if the archiver name or stream is null
           */
          CompressorOutputStream createCompressorOutputStream(final String name, final OutputStream out)
                  throws CompressorException;
      
          /**
           * Gets all the input stream compressor names for this provider
           * 
           * @return all the input compressor names for this provider
           */
          Set<String> getInputStreamCompressorNames();
      
          /**
           * Gets all the output stream compressor names for this provider
           * 
           * @return all the output compressor names for this provider
           */
          Set<String> getOutputStreamCompressorNames();
      
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                ggregory Gary D. Gregory
                Reporter:
                ggregory Gary D. Gregory
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: