Commit 36841d4f by aquilescanta Committed by bachinger

Replace one of the ParserException constructors with factory method

PiperOrigin-RevId: 377281961
parent bb2e0bc0
......@@ -24,6 +24,19 @@ public class ParserException extends IOException {
/**
* Creates a new instance for which {@link #contentIsMalformed} is true and {@link #dataType} is
* {@link C#DATA_TYPE_UNKNOWN}.
*
* @param message See {@link #getMessage()}.
* @param cause See {@link #getCause()}.
* @return The created instance.
*/
public static ParserException createForMalformedDataOfUnknownType(
@Nullable String message, @Nullable Throwable cause) {
return new ParserException(message, cause, /* contentIsMalformed= */ true, C.DATA_TYPE_UNKNOWN);
}
/**
* Creates a new instance for which {@link #contentIsMalformed} is true and {@link #dataType} is
* {@link C#DATA_TYPE_MEDIA}.
*
* @param message See {@link #getMessage()}.
......@@ -91,7 +104,11 @@ public class ParserException extends IOException {
*/
@Deprecated
public ParserException() {
this(/* message= */ null, /* cause= */ null);
this(
/* message= */ null,
/* cause= */ null,
/* contentIsMalformed= */ true,
C.DATA_TYPE_UNKNOWN);
}
/**
......@@ -103,7 +120,7 @@ public class ParserException extends IOException {
*/
@Deprecated
public ParserException(String message) {
this(message, /* cause= */ null);
this(message, /* cause= */ null, /* contentIsMalformed= */ true, C.DATA_TYPE_UNKNOWN);
}
/**
......@@ -115,20 +132,7 @@ public class ParserException extends IOException {
*/
@Deprecated
public ParserException(Throwable cause) {
this(/* message= */ null, cause);
}
/**
* Creates a new instance.
*
* @param message The detail message for the exception.
* @param cause The cause for the exception.
* @deprecated Use a factory method which initializes {@link #contentIsMalformed}, and {@link
* #dataType} instead.
*/
@Deprecated
public ParserException(@Nullable String message, @Nullable Throwable cause) {
this(message, cause, /* contentIsMalformed= */ true, C.DATA_TYPE_UNKNOWN);
this(/* message= */ null, cause, /* contentIsMalformed= */ true, C.DATA_TYPE_UNKNOWN);
}
private ParserException(
......
......@@ -85,7 +85,7 @@ public final class AvcConfig {
pixelWidthAspectRatio,
codecs);
} catch (ArrayIndexOutOfBoundsException e) {
throw new ParserException("Error parsing AVC config", e);
throw ParserException.createForMalformedContainer("Error parsing AVC config", e);
}
}
......
......@@ -90,7 +90,7 @@ public final class HevcConfig {
List<byte[]> initializationData = csdLength == 0 ? null : Collections.singletonList(buffer);
return new HevcConfig(initializationData, lengthSizeMinusOne + 1, codecs);
} catch (ArrayIndexOutOfBoundsException e) {
throw new ParserException("Error parsing HEVC config", e);
throw ParserException.createForMalformedContainer("Error parsing HEVC config", e);
}
}
......
......@@ -60,7 +60,8 @@ public final class DataSchemeDataSource extends BaseDataSource {
try {
data = Base64.decode(dataString, /* flags= */ Base64.DEFAULT);
} catch (IllegalArgumentException e) {
throw new ParserException("Error while parsing Base64 encoded string: " + dataString, e);
throw ParserException.createForMalformedDataOfUnknownType(
"Error while parsing Base64 encoded string: " + dataString, e);
}
} else {
// TODO: Add support for other charsets.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment