mirror of
https://github.com/androidx/media.git
synced 2025-05-10 09:12:16 +08:00
Add open/read http exception classes.
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=121871799
This commit is contained in:
parent
9f2707cfa3
commit
d2c524d726
@ -161,7 +161,7 @@ public class OkHttpDataSource implements HttpDataSource {
|
||||
responseByteStream = response.body().byteStream();
|
||||
} catch (IOException e) {
|
||||
throw new HttpDataSourceException("Unable to connect to " + dataSpec.uri.toString(), e,
|
||||
dataSpec);
|
||||
dataSpec, HttpDataSourceException.TYPE_OPEN);
|
||||
}
|
||||
|
||||
int responseCode = response.code();
|
||||
@ -206,7 +206,7 @@ public class OkHttpDataSource implements HttpDataSource {
|
||||
skipInternal();
|
||||
return readInternal(buffer, offset, readLength);
|
||||
} catch (IOException e) {
|
||||
throw new HttpDataSourceException(e, dataSpec);
|
||||
throw new HttpDataSourceException(e, dataSpec, HttpDataSourceException.TYPE_READ);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -192,7 +192,7 @@ public class DefaultHttpDataSource implements HttpDataSource {
|
||||
connection = makeConnection(dataSpec);
|
||||
} catch (IOException e) {
|
||||
throw new HttpDataSourceException("Unable to connect to " + dataSpec.uri.toString(), e,
|
||||
dataSpec);
|
||||
dataSpec, HttpDataSourceException.TYPE_OPEN);
|
||||
}
|
||||
|
||||
int responseCode;
|
||||
@ -201,7 +201,7 @@ public class DefaultHttpDataSource implements HttpDataSource {
|
||||
} catch (IOException e) {
|
||||
closeConnectionQuietly();
|
||||
throw new HttpDataSourceException("Unable to connect to " + dataSpec.uri.toString(), e,
|
||||
dataSpec);
|
||||
dataSpec, HttpDataSourceException.TYPE_OPEN);
|
||||
}
|
||||
|
||||
// Check for a valid response code.
|
||||
@ -241,7 +241,7 @@ public class DefaultHttpDataSource implements HttpDataSource {
|
||||
inputStream = connection.getInputStream();
|
||||
} catch (IOException e) {
|
||||
closeConnectionQuietly();
|
||||
throw new HttpDataSourceException(e, dataSpec);
|
||||
throw new HttpDataSourceException(e, dataSpec, HttpDataSourceException.TYPE_OPEN);
|
||||
}
|
||||
|
||||
opened = true;
|
||||
@ -258,7 +258,7 @@ public class DefaultHttpDataSource implements HttpDataSource {
|
||||
skipInternal();
|
||||
return readInternal(buffer, offset, readLength);
|
||||
} catch (IOException e) {
|
||||
throw new HttpDataSourceException(e, dataSpec);
|
||||
throw new HttpDataSourceException(e, dataSpec, HttpDataSourceException.TYPE_READ);
|
||||
}
|
||||
}
|
||||
|
||||
@ -270,7 +270,7 @@ public class DefaultHttpDataSource implements HttpDataSource {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
throw new HttpDataSourceException(e, dataSpec);
|
||||
throw new HttpDataSourceException(e, dataSpec, HttpDataSourceException.TYPE_CLOSE);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
|
@ -49,29 +49,39 @@ public interface HttpDataSource extends DataSource {
|
||||
*/
|
||||
class HttpDataSourceException extends IOException {
|
||||
|
||||
/*
|
||||
public static final int TYPE_OPEN = 1;
|
||||
public static final int TYPE_READ = 2;
|
||||
public static final int TYPE_CLOSE = 3;
|
||||
|
||||
public final int type;
|
||||
|
||||
/**
|
||||
* The {@link DataSpec} associated with the current connection.
|
||||
*/
|
||||
public final DataSpec dataSpec;
|
||||
|
||||
public HttpDataSourceException(DataSpec dataSpec) {
|
||||
public HttpDataSourceException(DataSpec dataSpec, int type) {
|
||||
super();
|
||||
this.dataSpec = dataSpec;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public HttpDataSourceException(String message, DataSpec dataSpec) {
|
||||
public HttpDataSourceException(String message, DataSpec dataSpec, int type) {
|
||||
super(message);
|
||||
this.dataSpec = dataSpec;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public HttpDataSourceException(IOException cause, DataSpec dataSpec) {
|
||||
public HttpDataSourceException(IOException cause, DataSpec dataSpec, int type) {
|
||||
super(cause);
|
||||
this.dataSpec = dataSpec;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public HttpDataSourceException(String message, IOException cause, DataSpec dataSpec) {
|
||||
public HttpDataSourceException(String message, IOException cause, DataSpec dataSpec, int type) {
|
||||
super(message, cause);
|
||||
this.dataSpec = dataSpec;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
}
|
||||
@ -84,7 +94,7 @@ public interface HttpDataSource extends DataSource {
|
||||
public final String contentType;
|
||||
|
||||
public InvalidContentTypeException(String contentType, DataSpec dataSpec) {
|
||||
super("Invalid content type: " + contentType, dataSpec);
|
||||
super("Invalid content type: " + contentType, dataSpec, TYPE_OPEN);
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
@ -107,7 +117,7 @@ public interface HttpDataSource extends DataSource {
|
||||
|
||||
public InvalidResponseCodeException(int responseCode, Map<String, List<String>> headerFields,
|
||||
DataSpec dataSpec) {
|
||||
super("Response code: " + responseCode, dataSpec);
|
||||
super("Response code: " + responseCode, dataSpec, TYPE_OPEN);
|
||||
this.responseCode = responseCode;
|
||||
this.headerFields = headerFields;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user