LZMACompressorOutputStream.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one
  3.  * or more contributor license agreements.  See the NOTICE file
  4.  * distributed with this work for additional information
  5.  * regarding copyright ownership.  The ASF licenses this file
  6.  * to you under the Apache License, Version 2.0 (the
  7.  * "License"); you may not use this file except in compliance
  8.  * with the License.  You may obtain a copy of the License at
  9.  *
  10.  * http://www.apache.org/licenses/LICENSE-2.0
  11.  *
  12.  * Unless required by applicable law or agreed to in writing,
  13.  * software distributed under the License is distributed on an
  14.  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15.  * KIND, either express or implied.  See the License for the
  16.  * specific language governing permissions and limitations
  17.  * under the License.
  18.  */
  19. package org.apache.commons.compress.compressors.lzma;

  20. import java.io.IOException;
  21. import java.io.OutputStream;

  22. import org.apache.commons.compress.compressors.CompressorOutputStream;
  23. import org.tukaani.xz.LZMA2Options;
  24. import org.tukaani.xz.LZMAOutputStream;

  25. /**
  26.  * LZMA compressor.
  27.  *
  28.  * @since 1.13
  29.  */
  30. public class LZMACompressorOutputStream extends CompressorOutputStream<LZMAOutputStream> {

  31.     /**
  32.      * Creates a LZMA compressor.
  33.      *
  34.      * @param outputStream the stream to wrap
  35.      * @throws IOException on error
  36.      */
  37.     @SuppressWarnings("resource") // Caller closes
  38.     public LZMACompressorOutputStream(final OutputStream outputStream) throws IOException {
  39.         super(new LZMAOutputStream(outputStream, new LZMA2Options(), -1));
  40.     }

  41.     /**
  42.      * Finishes compression without closing the underlying stream. No more data can be written to this stream after finishing.
  43.      *
  44.      * @throws IOException on error
  45.      */
  46.     @SuppressWarnings("resource") // instance variable access
  47.     public void finish() throws IOException {
  48.         out().finish();
  49.     }

  50.     /**
  51.      * Doesn't do anything as {@link LZMAOutputStream} doesn't support flushing.
  52.      */
  53.     @Override
  54.     public void flush() throws IOException {
  55.         // noop
  56.     }

  57.     /** {@inheritDoc} */
  58.     @Override
  59.     public void write(final byte[] buf, final int off, final int len) throws IOException {
  60.         out.write(buf, off, len);
  61.     }

  62. }