Make HttpDataSourceException subclass DataSourceException.
PiperOrigin-RevId: 382551642
This commit is contained in:
parent
b0ddef5bcf
commit
dda1d37368
@ -15,11 +15,31 @@
|
|||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.upstream;
|
package com.google.android.exoplayer2.upstream;
|
||||||
|
|
||||||
|
import androidx.annotation.IntDef;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.annotation.Documented;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
||||||
/** Used to specify reason of a DataSource error. */
|
/** Used to specify reason of a DataSource error. */
|
||||||
public final class DataSourceException extends IOException {
|
public class DataSourceException extends IOException {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type of operation that produced the error. One of {@link #TYPE_READ}, {@link #TYPE_OPEN}
|
||||||
|
* {@link #TYPE_CLOSE}.
|
||||||
|
*/
|
||||||
|
@Documented
|
||||||
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
|
@IntDef({TYPE_OPEN, TYPE_READ, TYPE_CLOSE})
|
||||||
|
public @interface Type {}
|
||||||
|
|
||||||
|
/** The error occurred reading data from a {@link DataSource}. */
|
||||||
|
public static final int TYPE_OPEN = 1;
|
||||||
|
/** The error occurred in opening a {@link DataSource}. */
|
||||||
|
public static final int TYPE_READ = 2;
|
||||||
|
/** The error occurred in closing a {@link DataSource}. */
|
||||||
|
public static final int TYPE_CLOSE = 3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the given {@link IOException} was caused by a {@link DataSourceException} whose
|
* Returns whether the given {@link IOException} was caused by a {@link DataSourceException} whose
|
||||||
@ -45,17 +65,83 @@ public final class DataSourceException extends IOException {
|
|||||||
*/
|
*/
|
||||||
public static final int POSITION_OUT_OF_RANGE = 0;
|
public static final int POSITION_OUT_OF_RANGE = 0;
|
||||||
|
|
||||||
|
/** Indicates that the error reason is unknown. */
|
||||||
|
public static final int REASON_UNKNOWN = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The reason of this {@link DataSourceException}. It can only be {@link #POSITION_OUT_OF_RANGE}.
|
* The reason of this {@link DataSourceException}. It can only be {@link #POSITION_OUT_OF_RANGE},
|
||||||
|
* or {@link #REASON_UNKNOWN}.
|
||||||
*/
|
*/
|
||||||
public final int reason;
|
public final int reason;
|
||||||
|
|
||||||
|
/** The {@link Type} of the operation that caused the playback failure. */
|
||||||
|
@Type public final int type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a DataSourceException with type {@link #TYPE_READ}.
|
||||||
|
*
|
||||||
|
* @deprecated Use the constructor {@link #DataSourceException(String, Throwable, int, int)}.
|
||||||
|
* @param reason Reason of the error. It can only be {@link #POSITION_OUT_OF_RANGE} or {@link
|
||||||
|
* #REASON_UNKNOWN}.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public DataSourceException(int reason) {
|
||||||
|
this.reason = reason;
|
||||||
|
this.type = TYPE_READ;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a DataSourceException.
|
* Constructs a DataSourceException.
|
||||||
*
|
*
|
||||||
* @param reason Reason of the error. It can only be {@link #POSITION_OUT_OF_RANGE}.
|
* @param message The error message.
|
||||||
|
* @param cause The error cause.
|
||||||
|
* @param reason Reason of the error. It can only be {@link #POSITION_OUT_OF_RANGE} or {@link
|
||||||
|
* #REASON_UNKNOWN}.
|
||||||
|
* @param type See {@link Type}.
|
||||||
*/
|
*/
|
||||||
public DataSourceException(int reason) {
|
public DataSourceException(String message, Throwable cause, int reason, @Type int type) {
|
||||||
|
super(message, cause);
|
||||||
this.reason = reason;
|
this.reason = reason;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a DataSourceException.
|
||||||
|
*
|
||||||
|
* @param cause The error cause.
|
||||||
|
* @param reason Reason of the error. It can only be {@link #POSITION_OUT_OF_RANGE} or {@link
|
||||||
|
* #REASON_UNKNOWN}.
|
||||||
|
* @param type See {@link Type}.
|
||||||
|
*/
|
||||||
|
public DataSourceException(Throwable cause, int reason, @Type int type) {
|
||||||
|
super(cause);
|
||||||
|
this.reason = reason;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a DataSourceException.
|
||||||
|
*
|
||||||
|
* @param message The error message.
|
||||||
|
* @param reason Reason of the error. It can only be {@link #POSITION_OUT_OF_RANGE} or {@link
|
||||||
|
* #REASON_UNKNOWN}.
|
||||||
|
* @param type See {@link Type}.
|
||||||
|
*/
|
||||||
|
public DataSourceException(String message, int reason, @Type int type) {
|
||||||
|
super(message);
|
||||||
|
this.reason = reason;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a DataSourceException.
|
||||||
|
*
|
||||||
|
* @param reason Reason of the error. It can only be {@link #POSITION_OUT_OF_RANGE} or {@link
|
||||||
|
* #REASON_UNKNOWN}.
|
||||||
|
* @param type See {@link Type}.
|
||||||
|
*/
|
||||||
|
public DataSourceException(int reason, @Type int type) {
|
||||||
|
this.reason = reason;
|
||||||
|
this.type = type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,15 +16,11 @@
|
|||||||
package com.google.android.exoplayer2.upstream;
|
package com.google.android.exoplayer2.upstream;
|
||||||
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import androidx.annotation.IntDef;
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.util.Util;
|
import com.google.android.exoplayer2.util.Util;
|
||||||
import com.google.common.base.Ascii;
|
import com.google.common.base.Ascii;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.annotation.Documented;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -188,45 +184,30 @@ public interface HttpDataSource extends DataSource {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/** Thrown when an error is encountered when trying to read from a {@link HttpDataSource}. */
|
/** Thrown when an error is encountered when trying to read from a {@link HttpDataSource}. */
|
||||||
class HttpDataSourceException extends IOException {
|
class HttpDataSourceException extends DataSourceException {
|
||||||
|
|
||||||
@Documented
|
|
||||||
@Retention(RetentionPolicy.SOURCE)
|
|
||||||
@IntDef({TYPE_OPEN, TYPE_READ, TYPE_CLOSE})
|
|
||||||
public @interface Type {}
|
|
||||||
|
|
||||||
public static final int TYPE_OPEN = 1;
|
|
||||||
public static final int TYPE_READ = 2;
|
|
||||||
public static final int TYPE_CLOSE = 3;
|
|
||||||
|
|
||||||
@Type public final int type;
|
|
||||||
|
|
||||||
/** The {@link DataSpec} associated with the current connection. */
|
/** The {@link DataSpec} associated with the current connection. */
|
||||||
public final DataSpec dataSpec;
|
public final DataSpec dataSpec;
|
||||||
|
|
||||||
public HttpDataSourceException(DataSpec dataSpec, @Type int type) {
|
public HttpDataSourceException(DataSpec dataSpec, @Type int type) {
|
||||||
super();
|
super(REASON_UNKNOWN, type);
|
||||||
this.dataSpec = dataSpec;
|
this.dataSpec = dataSpec;
|
||||||
this.type = type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpDataSourceException(String message, DataSpec dataSpec, @Type int type) {
|
public HttpDataSourceException(String message, DataSpec dataSpec, @Type int type) {
|
||||||
super(message);
|
super(message, REASON_UNKNOWN, type);
|
||||||
this.dataSpec = dataSpec;
|
this.dataSpec = dataSpec;
|
||||||
this.type = type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpDataSourceException(IOException cause, DataSpec dataSpec, @Type int type) {
|
public HttpDataSourceException(IOException cause, DataSpec dataSpec, @Type int type) {
|
||||||
super(cause);
|
super(cause, REASON_UNKNOWN, type);
|
||||||
this.dataSpec = dataSpec;
|
this.dataSpec = dataSpec;
|
||||||
this.type = type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpDataSourceException(
|
public HttpDataSourceException(
|
||||||
String message, IOException cause, DataSpec dataSpec, @Type int type) {
|
String message, IOException cause, DataSpec dataSpec, @Type int type) {
|
||||||
super(message, cause);
|
super(message, cause, REASON_UNKNOWN, type);
|
||||||
this.dataSpec = dataSpec;
|
this.dataSpec = dataSpec;
|
||||||
this.type = type;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user