Class UnsupportedAudioFormatException
- All Implemented Interfaces:
Serializable
AudioSourceProvider can open a given input, or when
a provider that scored non-negative on
AudioSourceProvider.canOpen(java.nio.file.Path) cannot in fact
decode the file once it opens it (structural mismatch, unsupported
compression code, malformed header after the magic-byte prefix, etc.).
This exception exists to distinguish "the bytes are not valid audio in
a recognised format" from bare IOException ("the disk is broken,"
"the network timed out," "the file was deleted between stat and open").
Callers can catch UnsupportedAudioFormatException on its own to
surface a helpful "unsupported format" message to end users, and let real
I/O failures propagate to a separate handler (Requirement 6, Requirement
12.4). Because it extends IOException, code that only cares about
the generic I/O failure case can still catch IOException and pick
both up in one handler.
Diagnostics
WhenAudioSources.open(java.nio.file.Path) (or its
InputStream/URL overloads) throws this
exception because no provider was willing to open the input,
providersConsulted() lists the AudioSourceProvider.formatName()
of every provider that was asked to score the input, in discovery order,
and providerScores() maps each consulted provider's format name
to the SPI Priority Score it returned (Requirements 6.4, 6.5, 6.6). A
provider whose canOpen threw an IOException is recorded
with a score of -1. Providers that were not consulted (e.g.
because none are registered on the classpath) do not appear in either
collection.
When a AudioSourceProvider constructs and throws this
exception itself from inside open(...) — for example, the WAV
provider rejecting a μ-law compressed file after the magic bytes
matched — providersConsulted() and providerScores()
are both empty (Requirement 6.4: "empty list when no providers were
consulted"). Only AudioSources populates the diagnostics
collections; they are not part of the public constructor surface.
Thread safety and immutability
Instances are immutable after construction. The collections returned fromprovidersConsulted() and providerScores() are
unmodifiable views over defensively-copied snapshots, so handing a
caught exception to multiple consumers is safe; attempting to mutate
the returned collections throws UnsupportedOperationException.- Since:
- 2.1.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionUnsupportedAudioFormatException(String message) Construct anUnsupportedAudioFormatExceptionwith the given detail message and no cause.UnsupportedAudioFormatException(String message, Throwable cause) Construct anUnsupportedAudioFormatExceptionwrapping an underlying cause. -
Method Summary
Modifier and TypeMethodDescriptionFormat names of everyAudioSourceProviderthat was asked to score the input, inServiceLoaderdiscovery order (Requirement 6.4).Score returned by each consultedAudioSourceProvider, keyed byformatName()(Requirement 6.5).Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
UnsupportedAudioFormatException
Construct anUnsupportedAudioFormatExceptionwith the given detail message and no cause.providersConsulted()andproviderScores()are both empty immutable collections (Requirement 6.4: "empty list when no providers were consulted").- Parameters:
message- detail message; may benull
-
UnsupportedAudioFormatException
Construct anUnsupportedAudioFormatExceptionwrapping an underlying cause.providersConsulted()andproviderScores()are both empty immutable collections.- Parameters:
message- detail message; may benullcause- underlying cause; may benull
-
-
Method Details
-
providersConsulted
Format names of everyAudioSourceProviderthat was asked to score the input, inServiceLoaderdiscovery order (Requirement 6.4).Returns an empty list when this exception was constructed via one of the public constructors (e.g. thrown from inside a provider's
open(...)method) rather than byAudioSources.- Returns:
- immutable list of consulted provider format names; never
null
-
providerScores
Score returned by each consultedAudioSourceProvider, keyed byformatName()(Requirement 6.5).A provider whose
canOpenthrew anIOExceptionis recorded here with a value of-1(the scoreAudioSourcesassigns to any failing or not-applicable provider). Returns an empty map when this exception was not constructed byAudioSources.- Returns:
- immutable map of provider format name to SPI Priority Score;
never
null
-