Commit 4f59394f by claincly Committed by Oliver Woodman

Use factory method to create ParserException.

ParserException's constructor methods are deprecated.

#minor-release

PiperOrigin-RevId: 376127494
parent c3531512
......@@ -36,6 +36,20 @@ public class ParserException extends IOException {
}
/**
* Creates a new instance for which {@link #contentIsMalformed} is true and {@link #dataType} is
* {@link C#DATA_TYPE_MANIFEST}.
*
* @param message See {@link #getMessage()}.
* @param cause See {@link #getCause()}.
* @return The created instance.
*/
public static ParserException createForMalformedManifest(
@Nullable String message, @Nullable Throwable cause) {
return new ParserException(
message, cause, /* contentIsMalformed= */ true, C.DATA_TYPE_MANIFEST);
}
/**
* Creates a new instance for which {@link #contentIsMalformed} is false and {@link #dataType} is
* {@link C#DATA_TYPE_MEDIA}.
*
......
......@@ -456,7 +456,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
@Nullable String sessionHeaderString = response.headers.get(RtspHeaders.SESSION);
@Nullable String transportHeaderString = response.headers.get(RtspHeaders.TRANSPORT);
if (sessionHeaderString == null || transportHeaderString == null) {
throw new ParserException();
throw ParserException.createForMalformedManifest(
"Missing mandatory session or transport header", /* cause= */ null);
}
RtspSessionHeader sessionHeader =
......
......@@ -339,7 +339,7 @@ import java.util.regex.Pattern;
return C.LENGTH_UNSET;
}
} catch (NumberFormatException e) {
throw new ParserException(e);
throw ParserException.createForMalformedManifest(line, e);
}
}
......@@ -378,7 +378,7 @@ import java.util.regex.Pattern;
public static RtspSessionHeader parseSessionHeader(String headerValue) throws ParserException {
Matcher matcher = SESSION_HEADER_PATTERN.matcher(headerValue);
if (!matcher.matches()) {
throw new ParserException(headerValue);
throw ParserException.createForMalformedManifest(headerValue, /* cause= */ null);
}
String sessionId = checkNotNull(matcher.group(1));
......@@ -389,7 +389,7 @@ import java.util.regex.Pattern;
try {
timeoutMs = Integer.parseInt(timeoutString) * C.MILLIS_PER_SECOND;
} catch (NumberFormatException e) {
throw new ParserException(e);
throw ParserException.createForMalformedManifest(headerValue, e);
}
}
......@@ -468,7 +468,7 @@ import java.util.regex.Pattern;
try {
return Integer.parseInt(intString);
} catch (NumberFormatException e) {
throw new ParserException(e);
throw ParserException.createForMalformedManifest(intString, e);
}
}
......
......@@ -61,7 +61,7 @@ import java.util.regex.Pattern;
try {
stopTimeMs = (long) (Float.parseFloat(stopTimeString) * C.MILLIS_PER_SECOND);
} catch (NumberFormatException e) {
throw new ParserException(e);
throw ParserException.createForMalformedManifest(stopTimeString, e);
}
checkArgument(stopTimeMs > startTimeMs);
} else {
......
......@@ -80,17 +80,17 @@ import com.google.common.collect.ImmutableList;
rtpTime = Long.parseLong(attributeValue);
break;
default:
throw new ParserException();
throw ParserException.createForMalformedManifest(attributeName, /* cause= */ null);
}
} catch (Exception e) {
throw new ParserException(attributePair, e);
throw ParserException.createForMalformedManifest(attributePair, e);
}
}
if (uri == null
|| uri.getScheme() == null // Checks if the URI is a URL.
|| (sequenceNumber == C.INDEX_UNSET && rtpTime == C.TIME_UNSET)) {
throw new ParserException(perTrackTimingString);
throw ParserException.createForMalformedManifest(perTrackTimingString, /* cause= */ null);
}
listBuilder.add(new RtspTrackTiming(rtpTime, sequenceNumber, uri));
......
......@@ -78,7 +78,8 @@ import java.util.regex.Pattern;
Matcher matcher = SDP_LINE_PATTERN.matcher(line);
if (!matcher.matches()) {
throw new ParserException("Malformed SDP line: " + line);
throw ParserException.createForMalformedManifest(
"Malformed SDP line: " + line, /* cause= */ null);
}
String sdpType = checkNotNull(matcher.group(1));
......@@ -87,7 +88,8 @@ import java.util.regex.Pattern;
switch (sdpType) {
case VERSION_TYPE:
if (!SUPPORTED_SDP_VERSION.equals(sdpValue)) {
throw new ParserException(String.format("SDP version %s is not supported.", sdpValue));
throw ParserException.createForMalformedManifest(
String.format("SDP version %s is not supported.", sdpValue), /* cause= */ null);
}
break;
......@@ -155,7 +157,8 @@ import java.util.regex.Pattern;
case ATTRIBUTE_TYPE:
matcher = ATTRIBUTE_PATTERN.matcher(sdpValue);
if (!matcher.matches()) {
throw new ParserException("Malformed Attribute line: " + line);
throw ParserException.createForMalformedManifest(
"Malformed Attribute line: " + line, /* cause= */ null);
}
String attributeName = checkNotNull(matcher.group(1));
......@@ -189,7 +192,7 @@ import java.util.regex.Pattern;
try {
return sessionDescriptionBuilder.build();
} catch (IllegalStateException e) {
throw new ParserException(e);
throw ParserException.createForMalformedManifest(/* message= */ null, e);
}
}
......@@ -200,7 +203,7 @@ import java.util.regex.Pattern;
try {
sessionDescriptionBuilder.addMediaDescription(mediaDescriptionBuilder.build());
} catch (IllegalStateException e) {
throw new ParserException(e);
throw ParserException.createForMalformedManifest(/* message= */ null, e);
}
}
......@@ -208,7 +211,8 @@ import java.util.regex.Pattern;
throws ParserException {
Matcher matcher = MEDIA_DESCRIPTION_PATTERN.matcher(line);
if (!matcher.matches()) {
throw new ParserException("Malformed SDP media description line: " + line);
throw ParserException.createForMalformedManifest(
"Malformed SDP media description line: " + line, /* cause= */ null);
}
String mediaType = checkNotNull(matcher.group(1));
String portString = checkNotNull(matcher.group(2));
......@@ -222,7 +226,8 @@ import java.util.regex.Pattern;
transportProtocol,
Integer.parseInt(payloadTypeString));
} catch (NumberFormatException e) {
throw new ParserException("Malformed SDP media description line: " + line, e);
throw ParserException.createForMalformedManifest(
"Malformed SDP media description line: " + line, e);
}
}
......
......@@ -95,7 +95,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
// RFC6184 Section 5.6, 5.7 and 5.8.
rtpH264PacketMode = data.getData()[0] & 0x1F;
} catch (IndexOutOfBoundsException e) {
throw new ParserException(e);
throw ParserException.createForMalformedManifest(/* message= */ null, e);
}
checkStateNotNull(trackOutput);
......@@ -106,8 +106,9 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
} else if (rtpH264PacketMode == RTP_PACKET_TYPE_FU_A) {
processFragmentationUnitPacket(data, sequenceNumber);
} else {
throw new ParserException(
String.format("RTP H264 packetization mode [%d] not supported.", rtpH264PacketMode));
throw ParserException.createForMalformedManifest(
String.format("RTP H264 packetization mode [%d] not supported.", rtpH264PacketMode),
/* cause= */ null);
}
if (isAuBoundary) {
......
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