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