| 1 | // SPDX-License-Identifier: 0BSD |
| 2 | // SPDX-FileCopyrightText: The XZ for Java authors and contributors |
| 3 | // SPDX-FileContributor: Lasse Collin <[email protected]> |
| 4 | |
| 5 | package org.tukaani.xz; |
| 6 | |
| 7 | import java.io.OutputStream; |
| 8 | import java.io.IOException; |
| 9 | |
| 10 | /** |
| 11 | * Wraps an output stream to a finishable output stream for use with |
| 12 | * raw encoders. This is not needed for XZ compression and thus most |
| 13 | * people will never need this. |
| 14 | */ |
| 15 | public class FinishableWrapperOutputStream extends FinishableOutputStream { |
| 16 | /** |
| 17 | * The {@link java.io.OutputStream OutputStream} that has been |
| 18 | * wrapped into a FinishableWrapperOutputStream. |
| 19 | */ |
| 20 | protected OutputStream out; |
| 21 | |
| 22 | /** |
| 23 | * Creates a new output stream which support finishing. |
| 24 | * The {@code finish()} method will do nothing. |
| 25 | */ |
| 26 | public FinishableWrapperOutputStream(OutputStream out) { |
| 27 | this.out = out; |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Calls {@link java.io.OutputStream#write(int) out.write(b)}. |
| 32 | */ |
| 33 | @Override |
| 34 | public void write(int b) throws IOException { |
| 35 | out.write(b); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Calls {@link java.io.OutputStream#write(byte[]) out.write(buf)}. |
| 40 | */ |
| 41 | @Override |
| 42 | public void write(byte[] buf) throws IOException { |
| 43 | out.write(buf); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Calls {@link java.io.OutputStream#write(byte[],int,int) |
| 48 | out.write(buf, off, len)}. |
| 49 | */ |
| 50 | @Override |
| 51 | public void write(byte[] buf, int off, int len) throws IOException { |
| 52 | out.write(buf, off, len); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Calls {@link java.io.OutputStream#flush() out.flush()}. |
| 57 | */ |
| 58 | @Override |
| 59 | public void flush() throws IOException { |
| 60 | out.flush(); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Calls {@link java.io.OutputStream#close() out.close()}. |
| 65 | */ |
| 66 | @Override |
| 67 | public void close() throws IOException { |
| 68 | out.close(); |
| 69 | } |
| 70 | } |