source: josm/trunk/src/org/tukaani/xz/FilterOptions.java@ 13350

Last change on this file since 13350 was 13350, checked in by stoecker, 6 years ago

see #15816 - add XZ support

File size: 3.3 KB
Line 
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
11package org.tukaani.xz;
12
13import java.io.InputStream;
14import java.io.IOException;
15
16/**
17 * Base class for filter-specific options classes.
18 */
19public 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 */
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 */
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 */
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 * <p>
62 * This is uses ArrayCache.getDefaultCache() as the ArrayCache.
63 */
64 public FinishableOutputStream getOutputStream(FinishableOutputStream out) {
65 return getOutputStream(out, ArrayCache.getDefaultCache());
66 }
67
68 /**
69 * Gets a raw (no XZ headers) encoder output stream using these options
70 * and the given ArrayCache.
71 * Raw streams are an advanced feature. In most cases you want to store
72 * the compressed data in the .xz container format instead of using
73 * a raw stream. To use this filter in a .xz file, pass this object
74 * to XZOutputStream.
75 */
76 public abstract FinishableOutputStream getOutputStream(
77 FinishableOutputStream out, ArrayCache arrayCache);
78
79 /**
80 * Gets how much memory the decoder will need to decompress the data
81 * that was encoded with these options.
82 */
83 public abstract int getDecoderMemoryUsage();
84
85 /**
86 * Gets a raw (no XZ headers) decoder input stream using these options.
87 * <p>
88 * This is uses ArrayCache.getDefaultCache() as the ArrayCache.
89 */
90 public InputStream getInputStream(InputStream in) throws IOException {
91 return getInputStream(in, ArrayCache.getDefaultCache());
92 }
93
94 /**
95 * Gets a raw (no XZ headers) decoder input stream using these options
96 * and the given ArrayCache.
97 */
98 public abstract InputStream getInputStream(
99 InputStream in, ArrayCache arrayCache) throws IOException;
100
101 abstract FilterEncoder getFilterEncoder();
102
103 FilterOptions() {}
104}
Note: See TracBrowser for help on using the repository browser.