1 /* 2 * FilterOptions 3 * 4 * Authors: Lasse Collin <lasse.collin@tukaani.org> 5 * Igor Pavlov <http://7-zip.org/> 6 * 7 * This file has been put into the public domain. 8 * You can do whatever you want with this file. 9 */ 10 11 package org.tukaani.xz; 12 13 import java.io.InputStream; 14 import java.io.IOException; 15 16 /** 17 * Base class for filter-specific options classes. 18 */ 19 public abstract class FilterOptions implements Cloneable { 20 /** 21 * Gets how much memory the encoder will need with 22 * the given filter chain. This function simply calls 23 * <code>getEncoderMemoryUsage()</code> for every filter 24 * in the array and returns the sum of the returned values. 25 */ getEncoderMemoryUsage(FilterOptions[] options)26 public static int getEncoderMemoryUsage(FilterOptions[] options) { 27 int m = 0; 28 29 for (int i = 0; i < options.length; ++i) 30 m += options[i].getEncoderMemoryUsage(); 31 32 return m; 33 } 34 35 /** 36 * Gets how much memory the decoder will need with 37 * the given filter chain. This function simply calls 38 * <code>getDecoderMemoryUsage()</code> for every filter 39 * in the array and returns the sum of the returned values. 40 */ getDecoderMemoryUsage(FilterOptions[] options)41 public static int getDecoderMemoryUsage(FilterOptions[] options) { 42 int m = 0; 43 44 for (int i = 0; i < options.length; ++i) 45 m += options[i].getDecoderMemoryUsage(); 46 47 return m; 48 } 49 50 /** 51 * Gets how much memory the encoder will need with these options. 52 */ getEncoderMemoryUsage()53 public abstract int getEncoderMemoryUsage(); 54 55 /** 56 * Gets a raw (no XZ headers) encoder output stream using these options. 57 * Raw streams are an advanced feature. In most cases you want to store 58 * the compressed data in the .xz container format instead of using 59 * a raw stream. To use this filter in a .xz file, pass this object 60 * to XZOutputStream. 61 */ getOutputStream( FinishableOutputStream out)62 public abstract FinishableOutputStream getOutputStream( 63 FinishableOutputStream out); 64 65 /** 66 * Gets how much memory the decoder will need to decompress the data 67 * that was encoded with these options. 68 */ getDecoderMemoryUsage()69 public abstract int getDecoderMemoryUsage(); 70 71 /** 72 * Gets a raw (no XZ headers) decoder input stream using these options. 73 */ getInputStream(InputStream in)74 public abstract InputStream getInputStream(InputStream in) 75 throws IOException; 76 getFilterEncoder()77 abstract FilterEncoder getFilterEncoder(); 78 FilterOptions()79 FilterOptions() {} 80 } 81