Skip to content

Commit

Permalink
Extend IOException (#605)
Browse files Browse the repository at this point in the history
* CompressorException now extends IOException instead of Exception

ArchiveException now extends IOException instead of Exception

* Update ArchiveStreamFactoryTest.java
  • Loading branch information
garydgregory authored Nov 16, 2024
1 parent 81e13f0 commit 6afdc3f
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
*/
package org.apache.commons.compress.archivers;

import java.io.IOException;

/**
* Signals that an Archive exception of some sort has occurred.
*/
public class ArchiveException extends Exception {
public class ArchiveException extends IOException {

/** Serial. */
private static final long serialVersionUID = 2772690708123267100L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public static String detect(final InputStream in) throws ArchiveException {
signatureLength = IOUtils.readFully(in, signature);
in.reset();
} catch (final IOException e) {
throw new ArchiveException("IOException while reading signature.", e);
throw new ArchiveException("Failure reading signature.", e);
}

// For now JAR files are detected as ZIP files.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
*/
package org.apache.commons.compress.compressors;

import java.io.IOException;

/**
* Signals that an Compressor exception of some sort has occurred.
*/
public class CompressorException extends Exception {
public class CompressorException extends IOException {

/** Serial. */
private static final long serialVersionUID = -2932901310255908814L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ static String detect(final InputStream inputStream, final Set<String> compressor
signatureLength = IOUtils.readFully(inputStream, signature);
inputStream.reset();
} catch (final IOException e) {
throw new CompressorException("IOException while reading signature.", e);
throw new CompressorException("Failed to read signature.", e);
}
if (compressorNames.contains(BZIP2) && BZip2CompressorInputStream.matches(signature, signatureLength)) {
return BZIP2;
Expand Down Expand Up @@ -632,7 +632,7 @@ public CompressorOutputStream<?> createCompressorOutputStream(final String name,
return new ZstdCompressorOutputStream(out);
}
} catch (final IOException e) {
throw new CompressorException("Could not create CompressorOutputStream", e);
throw new CompressorException("Could not create CompressorOutputStream.", e);
}
final CompressorStreamProvider compressorStreamProvider = getCompressorOutputStreamProviders().get(toKey(name));
if (compressorStreamProvider != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public void testDetect() throws Exception {

final ArchiveException e3 = assertThrows(ArchiveException.class, () -> ArchiveStreamFactory.detect(new BufferedInputStream(new BrokenInputStream())),
"Expected ArchiveException");
assertEquals("IOException while reading signature.", e3.getMessage());
assertEquals("Failure reading signature.", e3.getMessage());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public void testDetect() throws Exception {

final CompressorException ce = assertThrows(CompressorException.class,
() -> CompressorStreamFactory.detect(new BufferedInputStream(new BrokenInputStream())), "Expected IOException");
assertEquals("IOException while reading signature.", ce.getMessage());
assertEquals("Failed to read signature.", ce.getMessage());
}

@ParameterizedTest
Expand Down

0 comments on commit 6afdc3f

Please sign in to comment.