001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.commons.compress.compressors.lzma; 020 021import java.io.IOException; 022import java.io.OutputStream; 023 024import org.apache.commons.compress.compressors.CompressorOutputStream; 025import org.tukaani.xz.LZMA2Options; 026import org.tukaani.xz.LZMAOutputStream; 027 028/** 029 * LZMA compressor. 030 * 031 * @since 1.13 032 */ 033public class LZMACompressorOutputStream extends CompressorOutputStream<LZMAOutputStream> { 034 035 /** 036 * Creates a LZMA compressor. 037 * 038 * @param outputStream the stream to wrap 039 * @throws IOException on error 040 */ 041 @SuppressWarnings("resource") // Caller closes 042 public LZMACompressorOutputStream(final OutputStream outputStream) throws IOException { 043 super(new LZMAOutputStream(outputStream, new LZMA2Options(), -1)); 044 } 045 046 /** 047 * Finishes compression without closing the underlying stream. No more data can be written to this stream after finishing. 048 * 049 * @throws IOException on error 050 */ 051 @SuppressWarnings("resource") // instance variable access 052 public void finish() throws IOException { 053 out().finish(); 054 } 055 056 /** 057 * Doesn't do anything as {@link LZMAOutputStream} doesn't support flushing. 058 */ 059 @Override 060 public void flush() throws IOException { 061 // noop 062 } 063 064 /** {@inheritDoc} */ 065 @Override 066 public void write(final byte[] buf, final int off, final int len) throws IOException { 067 out.write(buf, off, len); 068 } 069 070}