aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2017-10-12 20:18:18 +0300
committerLasse Collin <lasse.collin@tukaani.org>2017-12-16 17:34:30 +0200
commita0d189d655b7cb34792bbda4b1a8b0230c541b34 (patch)
tree8e71eb558cb247a477a854055c951dfa5bb800ee
parent718d2a32cf3d5c850daf16d7461bceb6a753692a (diff)
downloadxz-java-a0d189d655b7cb34792bbda4b1a8b0230c541b34.tar.gz
Add ArrayCache support to XZOutputStream.
-rw-r--r--src/org/tukaani/xz/BCJEncoder.java5
-rw-r--r--src/org/tukaani/xz/BlockOutputStream.java5
-rw-r--r--src/org/tukaani/xz/DeltaEncoder.java5
-rw-r--r--src/org/tukaani/xz/FilterEncoder.java3
-rw-r--r--src/org/tukaani/xz/LZMA2Encoder.java5
-rw-r--r--src/org/tukaani/xz/XZOutputStream.java120
6 files changed, 133 insertions, 10 deletions
diff --git a/src/org/tukaani/xz/BCJEncoder.java b/src/org/tukaani/xz/BCJEncoder.java
index 136bbb7..90cde79 100644
--- a/src/org/tukaani/xz/BCJEncoder.java
+++ b/src/org/tukaani/xz/BCJEncoder.java
@@ -42,7 +42,8 @@ class BCJEncoder extends BCJCoder implements FilterEncoder {
return false;
}
- public FinishableOutputStream getOutputStream(FinishableOutputStream out) {
- return options.getOutputStream(out);
+ public FinishableOutputStream getOutputStream(FinishableOutputStream out,
+ ArrayCache arrayCache) {
+ return options.getOutputStream(out, arrayCache);
}
}
diff --git a/src/org/tukaani/xz/BlockOutputStream.java b/src/org/tukaani/xz/BlockOutputStream.java
index 03fd0a9..8ac4407 100644
--- a/src/org/tukaani/xz/BlockOutputStream.java
+++ b/src/org/tukaani/xz/BlockOutputStream.java
@@ -28,7 +28,8 @@ class BlockOutputStream extends FinishableOutputStream {
private final byte[] tempBuf = new byte[1];
public BlockOutputStream(OutputStream out, FilterEncoder[] filters,
- Check check) throws IOException {
+ Check check, ArrayCache arrayCache)
+ throws IOException {
this.out = out;
this.check = check;
@@ -36,7 +37,7 @@ class BlockOutputStream extends FinishableOutputStream {
outCounted = new CountingOutputStream(out);
filterChain = outCounted;
for (int i = filters.length - 1; i >= 0; --i)
- filterChain = filters[i].getOutputStream(filterChain);
+ filterChain = filters[i].getOutputStream(filterChain, arrayCache);
// Prepare to encode the Block Header field.
ByteArrayOutputStream bufStream = new ByteArrayOutputStream();
diff --git a/src/org/tukaani/xz/DeltaEncoder.java b/src/org/tukaani/xz/DeltaEncoder.java
index 384afe4..86ba9ea 100644
--- a/src/org/tukaani/xz/DeltaEncoder.java
+++ b/src/org/tukaani/xz/DeltaEncoder.java
@@ -30,7 +30,8 @@ class DeltaEncoder extends DeltaCoder implements FilterEncoder {
return true;
}
- public FinishableOutputStream getOutputStream(FinishableOutputStream out) {
- return options.getOutputStream(out);
+ public FinishableOutputStream getOutputStream(FinishableOutputStream out,
+ ArrayCache arrayCache) {
+ return options.getOutputStream(out, arrayCache);
}
}
diff --git a/src/org/tukaani/xz/FilterEncoder.java b/src/org/tukaani/xz/FilterEncoder.java
index 4558aad..b40575e 100644
--- a/src/org/tukaani/xz/FilterEncoder.java
+++ b/src/org/tukaani/xz/FilterEncoder.java
@@ -13,5 +13,6 @@ interface FilterEncoder extends FilterCoder {
long getFilterID();
byte[] getFilterProps();
boolean supportsFlushing();
- FinishableOutputStream getOutputStream(FinishableOutputStream out);
+ FinishableOutputStream getOutputStream(FinishableOutputStream out,
+ ArrayCache arrayCache);
}
diff --git a/src/org/tukaani/xz/LZMA2Encoder.java b/src/org/tukaani/xz/LZMA2Encoder.java
index 7c7facc..6f3cab4 100644
--- a/src/org/tukaani/xz/LZMA2Encoder.java
+++ b/src/org/tukaani/xz/LZMA2Encoder.java
@@ -44,7 +44,8 @@ class LZMA2Encoder extends LZMA2Coder implements FilterEncoder {
return true;
}
- public FinishableOutputStream getOutputStream(FinishableOutputStream out) {
- return options.getOutputStream(out);
+ public FinishableOutputStream getOutputStream(FinishableOutputStream out,
+ ArrayCache arrayCache) {
+ return options.getOutputStream(out, arrayCache);
}
}
diff --git a/src/org/tukaani/xz/XZOutputStream.java b/src/org/tukaani/xz/XZOutputStream.java
index 6a37fed..107ef7f 100644
--- a/src/org/tukaani/xz/XZOutputStream.java
+++ b/src/org/tukaani/xz/XZOutputStream.java
@@ -52,6 +52,8 @@ import org.tukaani.xz.index.IndexEncoder;
* </pre></blockquote>
*/
public class XZOutputStream extends FinishableOutputStream {
+ private final ArrayCache arrayCache;
+
private OutputStream out;
private final StreamFlags streamFlags = new StreamFlags();
private final Check check;
@@ -95,6 +97,33 @@ public class XZOutputStream extends FinishableOutputStream {
}
/**
+ * Creates a new XZ compressor using one filter and CRC64 as
+ * the integrity check. This constructor is equivalent to passing
+ * a single-member FilterOptions array to
+ * <code>XZOutputStream(OutputStream, FilterOptions[], ArrayCache)</code>.
+ *
+ * @param out output stream to which the compressed data
+ * will be written
+ *
+ * @param filterOptions
+ * filter options to use
+ *
+ * @param arrayCache cache to be used for allocating large arrays
+ *
+ * @throws UnsupportedOptionsException
+ * invalid filter chain
+ *
+ * @throws IOException may be thrown from <code>out</code>
+ *
+ * @since 1.7
+ */
+ public XZOutputStream(OutputStream out, FilterOptions filterOptions,
+ ArrayCache arrayCache)
+ throws IOException {
+ this(out, filterOptions, XZ.CHECK_CRC64, arrayCache);
+ }
+
+ /**
* Creates a new XZ compressor using one filter and the specified
* integrity check type. This constructor is equivalent to
* passing a single-member FilterOptions array to
@@ -120,6 +149,38 @@ public class XZOutputStream extends FinishableOutputStream {
}
/**
+ * Creates a new XZ compressor using one filter and the specified
+ * integrity check type. This constructor is equivalent to
+ * passing a single-member FilterOptions array to
+ * <code>XZOutputStream(OutputStream, FilterOptions[], int,
+ * ArrayCache)</code>.
+ *
+ * @param out output stream to which the compressed data
+ * will be written
+ *
+ * @param filterOptions
+ * filter options to use
+ *
+ * @param checkType type of the integrity check,
+ * for example XZ.CHECK_CRC32
+ *
+ * @param arrayCache cache to be used for allocating large arrays
+ *
+ * @throws UnsupportedOptionsException
+ * invalid filter chain
+ *
+ * @throws IOException may be thrown from <code>out</code>
+ *
+ * @since 1.7
+ */
+ public XZOutputStream(OutputStream out, FilterOptions filterOptions,
+ int checkType, ArrayCache arrayCache)
+ throws IOException {
+ this(out, new FilterOptions[] { filterOptions }, checkType,
+ arrayCache);
+ }
+
+ /**
* Creates a new XZ compressor using 1-4 filters and CRC64 as
* the integrity check. This constructor is equivalent
* <code>XZOutputStream(out, filterOptions, XZ.CHECK_CRC64)</code>.
@@ -141,6 +202,33 @@ public class XZOutputStream extends FinishableOutputStream {
}
/**
+ * Creates a new XZ compressor using 1-4 filters and CRC64 as
+ * the integrity check. This constructor is equivalent
+ * <code>XZOutputStream(out, filterOptions, XZ.CHECK_CRC64,
+ * arrayCache)</code>.
+ *
+ * @param out output stream to which the compressed data
+ * will be written
+ *
+ * @param filterOptions
+ * array of filter options to use
+ *
+ * @param arrayCache cache to be used for allocating large arrays
+ *
+ * @throws UnsupportedOptionsException
+ * invalid filter chain
+ *
+ * @throws IOException may be thrown from <code>out</code>
+ *
+ * @since 1.7
+ */
+ public XZOutputStream(OutputStream out, FilterOptions[] filterOptions,
+ ArrayCache arrayCache)
+ throws IOException {
+ this(out, filterOptions, XZ.CHECK_CRC64, arrayCache);
+ }
+
+ /**
* Creates a new XZ compressor using 1-4 filters and the specified
* integrity check type.
*
@@ -160,6 +248,35 @@ public class XZOutputStream extends FinishableOutputStream {
*/
public XZOutputStream(OutputStream out, FilterOptions[] filterOptions,
int checkType) throws IOException {
+ this(out, filterOptions, checkType, ArrayCache.getDefaultCache());
+ }
+
+ /**
+ * Creates a new XZ compressor using 1-4 filters and the specified
+ * integrity check type.
+ *
+ * @param out output stream to which the compressed data
+ * will be written
+ *
+ * @param filterOptions
+ * array of filter options to use
+ *
+ * @param checkType type of the integrity check,
+ * for example XZ.CHECK_CRC32
+ *
+ * @param arrayCache cache to be used for allocating large arrays
+ *
+ * @throws UnsupportedOptionsException
+ * invalid filter chain
+ *
+ * @throws IOException may be thrown from <code>out</code>
+ *
+ * @since 1.7
+ */
+ public XZOutputStream(OutputStream out, FilterOptions[] filterOptions,
+ int checkType, ArrayCache arrayCache)
+ throws IOException {
+ this.arrayCache = arrayCache;
this.out = out;
updateFilters(filterOptions);
@@ -277,7 +394,8 @@ public class XZOutputStream extends FinishableOutputStream {
try {
if (blockEncoder == null)
- blockEncoder = new BlockOutputStream(out, filters, check);
+ blockEncoder = new BlockOutputStream(out, filters, check,
+ arrayCache);
blockEncoder.write(buf, off, len);
} catch (IOException e) {