24
24
import java .util .ArrayList ;
25
25
import java .util .List ;
26
26
27
+ import org .apache .commons .compress .archivers .ArchiveException ;
27
28
import org .apache .commons .compress .archivers .ArchiveStreamFactory ;
28
29
import org .apache .commons .compress .archivers .zip .UnsupportedZipFeatureException ;
29
30
import org .apache .commons .compress .archivers .zip .ZipArchiveEntry ;
30
31
import org .apache .commons .compress .archivers .zip .ZipArchiveInputStream ;
31
32
import org .apache .commons .compress .archivers .zip .ZipFile ;
33
+ import org .apache .commons .compress .compressors .CompressorException ;
32
34
import org .apache .commons .compress .compressors .CompressorStreamFactory ;
33
35
import org .apache .commons .io .IOUtils ;
34
36
import org .apache .commons .io .input .CloseShieldInputStream ;
@@ -119,9 +121,15 @@ static MediaType detectArchiveFormat(byte[] prefix, int length) {
119
121
return TIFF ;
120
122
}
121
123
try {
122
- String name = ArchiveStreamFactory .detect (
123
- UnsynchronizedByteArrayInputStream .builder ().setByteArray (prefix ).setLength (length ).get ());
124
+ String name = ArchiveStreamFactory .detect (UnsynchronizedByteArrayInputStream
125
+ .builder ()
126
+ .setByteArray (prefix )
127
+ .setLength (length )
128
+ .get ());
124
129
return PackageConstants .getMediaType (name );
130
+ } catch (ArchiveException e ) {
131
+ //compress versions before 1.28.0 need this
132
+ return MediaType .OCTET_STREAM ;
125
133
} catch (IOException e ) {
126
134
return MediaType .OCTET_STREAM ;
127
135
}
@@ -133,6 +141,9 @@ static MediaType detectCompressorFormat(byte[] prefix, int length) {
133
141
CompressorStreamFactory .detect (
134
142
UnsynchronizedByteArrayInputStream .builder ().setByteArray (prefix ).setLength (length ).get ());
135
143
return CompressorConstants .getMediaType (type );
144
+ } catch (CompressorException e ) {
145
+ //compress versions before 1.28.0 need this
146
+ return MediaType .OCTET_STREAM ;
136
147
} catch (IOException e ) {
137
148
return MediaType .OCTET_STREAM ;
138
149
}
0 commit comments