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 21 import java.io.IOException; 22 import java.io.OutputStream; 23 24 import org.apache.commons.compress.compressors.CompressorOutputStream; 25 import org.tukaani.xz.LZMA2Options; 26 import org.tukaani.xz.LZMAOutputStream; 27 28 /** 29 * LZMA compressor. 30 * 31 * @since 1.13 32 */ 33 public class LZMACompressorOutputStream extends CompressorOutputStream<LZMAOutputStream> { 34 35 /** 36 * Creates a LZMA compressor. 37 * 38 * @param outputStream the stream to wrap 39 * @throws IOException on error 40 */ 41 @SuppressWarnings("resource") // Caller closes 42 public LZMACompressorOutputStream(final OutputStream outputStream) throws IOException { 43 super(new LZMAOutputStream(outputStream, new LZMA2Options(), -1)); 44 } 45 46 /** 47 * Finishes compression without closing the underlying stream. No more data can be written to this stream after finishing. 48 * 49 * @throws IOException on error 50 */ 51 @SuppressWarnings("resource") // instance variable access 52 public void finish() throws IOException { 53 out().finish(); 54 } 55 56 /** 57 * Doesn't do anything as {@link LZMAOutputStream} doesn't support flushing. 58 */ 59 @Override 60 public void flush() throws IOException { 61 // noop 62 } 63 64 /** {@inheritDoc} */ 65 @Override 66 public void write(final byte[] buf, final int off, final int len) throws IOException { 67 out.write(buf, off, len); 68 } 69 70 }