yakovsh commented on code in PR #433:
URL: https://github.com/apache/commons-compress/pull/433#discussion_r1388555944
##########
src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java:
##########
@@ -522,6 +524,39 @@ public CompressorInputStream
createCompressorInputStream(final InputStream in) t
return createCompressorInputStream(detect(in), in);
}
+ /**
+ * Create a compressor input stream from an input stream, auto-detecting
the
+ * compressor type from the first few bytes of the stream while
restricting the detected type
+ * against the provided set of compressor names. The InputStream must
support marks, like BufferedInputStream.
+ *
+ * The purpose of this method is to restrict autodetection to a smaller
set of compressor names
+ * for applications that don't need to support decompression of all file
types supported by the library.
+ *
+ * @param in
+ * the input stream
+ * @param compressorNames
+ * compressor names to limit autodetection
+ * @return the compressor input stream
+ * @throws CompressorException
+ * if the autodetected compressor is not in the provided set
of compressor names
+ * @throws IllegalArgumentException
+ * if the stream is null or does not support mark
+ * @since 1.25
+ */
+ public CompressorInputStream createCompressorInputStream(final InputStream
in, final Set<String> compressorNames)
+ throws CompressorException {
+ if (Objects.isNull(compressorNames) || compressorNames.isEmpty()) {
+ throw new IllegalArgumentException("Compressor names cannot be
null or empty");
+ }
+
+ String detectedName = detect(in);
Review Comment:
You are right, I am going to move the logic into the detect method and limit
the work being done
##########
src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java:
##########
@@ -522,6 +524,39 @@ public CompressorInputStream
createCompressorInputStream(final InputStream in) t
return createCompressorInputStream(detect(in), in);
}
+ /**
+ * Create a compressor input stream from an input stream, auto-detecting
the
+ * compressor type from the first few bytes of the stream while
restricting the detected type
+ * against the provided set of compressor names. The InputStream must
support marks, like BufferedInputStream.
+ *
+ * The purpose of this method is to restrict autodetection to a smaller
set of compressor names
+ * for applications that don't need to support decompression of all file
types supported by the library.
+ *
+ * @param in
+ * the input stream
+ * @param compressorNames
+ * compressor names to limit autodetection
+ * @return the compressor input stream
+ * @throws CompressorException
+ * if the autodetected compressor is not in the provided set
of compressor names
+ * @throws IllegalArgumentException
+ * if the stream is null or does not support mark
+ * @since 1.25
+ */
+ public CompressorInputStream createCompressorInputStream(final InputStream
in, final Set<String> compressorNames)
+ throws CompressorException {
+ if (Objects.isNull(compressorNames) || compressorNames.isEmpty()) {
+ throw new IllegalArgumentException("Compressor names cannot be
null or empty");
+ }
+
+ String detectedName = detect(in);
Review Comment:
You are right, I am going to move the logic into the detect method and limit
the work being done. Thank you for your patience.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]