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 { 34 private final LZMAOutputStream out; 35 36 /** 37 * Creates a LZMA compressor. 38 * 39 * @param outputStream the stream to wrap 40 * @throws IOException on error 41 */ 42 public LZMACompressorOutputStream(final OutputStream outputStream) throws IOException { 43 out = new LZMAOutputStream(outputStream, new LZMA2Options(), -1); 44 } 45 46 /** {@inheritDoc} */ 47 @Override 48 public void close() throws IOException { 49 out.close(); 50 } 51 52 /** 53 * Finishes compression without closing the underlying stream. No more data can be written to this stream after finishing. 54 * 55 * @throws IOException on error 56 */ 57 public void finish() throws IOException { 58 out.finish(); 59 } 60 61 /** 62 * Doesn't do anything as {@link LZMAOutputStream} doesn't support flushing. 63 */ 64 @Override 65 public void flush() throws IOException { 66 // noop 67 } 68 69 /** {@inheritDoc} */ 70 @Override 71 public void write(final byte[] buf, final int off, final int len) throws IOException { 72 out.write(buf, off, len); 73 } 74 75 /** {@inheritDoc} */ 76 @Override 77 public void write(final int b) throws IOException { 78 out.write(b); 79 } 80 }