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();
|
responseByteStream = response.body().byteStream();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new HttpDataSourceException("Unable to connect to " + dataSpec.uri.toString(), e,
|
throw new HttpDataSourceException("Unable to connect to " + dataSpec.uri.toString(), e,
|
||||||
dataSpec);
|
dataSpec, HttpDataSourceException.TYPE_OPEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
int responseCode = response.code();
|
int responseCode = response.code();
|
||||||
@ -206,7 +206,7 @@ public class OkHttpDataSource implements HttpDataSource {
|
|||||||
skipInternal();
|
skipInternal();
|
||||||
return readInternal(buffer, offset, readLength);
|
return readInternal(buffer, offset, readLength);
|
||||||
} catch (IOException e) {
|
} 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);
|
connection = makeConnection(dataSpec);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new HttpDataSourceException("Unable to connect to " + dataSpec.uri.toString(), e,
|
throw new HttpDataSourceException("Unable to connect to " + dataSpec.uri.toString(), e,
|
||||||
dataSpec);
|
dataSpec, HttpDataSourceException.TYPE_OPEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
int responseCode;
|
int responseCode;
|
||||||
@ -201,7 +201,7 @@ public class DefaultHttpDataSource implements HttpDataSource {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
closeConnectionQuietly();
|
closeConnectionQuietly();
|
||||||
throw new HttpDataSourceException("Unable to connect to " + dataSpec.uri.toString(), e,
|
throw new HttpDataSourceException("Unable to connect to " + dataSpec.uri.toString(), e,
|
||||||
dataSpec);
|
dataSpec, HttpDataSourceException.TYPE_OPEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for a valid response code.
|
// Check for a valid response code.
|
||||||
@ -241,7 +241,7 @@ public class DefaultHttpDataSource implements HttpDataSource {
|
|||||||
inputStream = connection.getInputStream();
|
inputStream = connection.getInputStream();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
closeConnectionQuietly();
|
closeConnectionQuietly();
|
||||||
throw new HttpDataSourceException(e, dataSpec);
|
throw new HttpDataSourceException(e, dataSpec, HttpDataSourceException.TYPE_OPEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
opened = true;
|
opened = true;
|
||||||
@ -258,7 +258,7 @@ public class DefaultHttpDataSource implements HttpDataSource {
|
|||||||
skipInternal();
|
skipInternal();
|
||||||
return readInternal(buffer, offset, readLength);
|
return readInternal(buffer, offset, readLength);
|
||||||
} catch (IOException e) {
|
} 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 {
|
try {
|
||||||
inputStream.close();
|
inputStream.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new HttpDataSourceException(e, dataSpec);
|
throw new HttpDataSourceException(e, dataSpec, HttpDataSourceException.TYPE_CLOSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -49,29 +49,39 @@ public interface HttpDataSource extends DataSource {
|
|||||||
*/
|
*/
|
||||||
class HttpDataSourceException extends IOException {
|
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.
|
* The {@link DataSpec} associated with the current connection.
|
||||||
*/
|
*/
|
||||||
public final DataSpec dataSpec;
|
public final DataSpec dataSpec;
|
||||||
|
|
||||||
public HttpDataSourceException(DataSpec dataSpec) {
|
public HttpDataSourceException(DataSpec dataSpec, int type) {
|
||||||
super();
|
super();
|
||||||
this.dataSpec = dataSpec;
|
this.dataSpec = dataSpec;
|
||||||
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpDataSourceException(String message, DataSpec dataSpec) {
|
public HttpDataSourceException(String message, DataSpec dataSpec, int type) {
|
||||||
super(message);
|
super(message);
|
||||||
this.dataSpec = dataSpec;
|
this.dataSpec = dataSpec;
|
||||||
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpDataSourceException(IOException cause, DataSpec dataSpec) {
|
public HttpDataSourceException(IOException cause, DataSpec dataSpec, int type) {
|
||||||
super(cause);
|
super(cause);
|
||||||
this.dataSpec = dataSpec;
|
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);
|
super(message, cause);
|
||||||
this.dataSpec = dataSpec;
|
this.dataSpec = dataSpec;
|
||||||
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -84,7 +94,7 @@ public interface HttpDataSource extends DataSource {
|
|||||||
public final String contentType;
|
public final String contentType;
|
||||||
|
|
||||||
public InvalidContentTypeException(String contentType, DataSpec dataSpec) {
|
public InvalidContentTypeException(String contentType, DataSpec dataSpec) {
|
||||||
super("Invalid content type: " + contentType, dataSpec);
|
super("Invalid content type: " + contentType, dataSpec, TYPE_OPEN);
|
||||||
this.contentType = contentType;
|
this.contentType = contentType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +117,7 @@ public interface HttpDataSource extends DataSource {
|
|||||||
|
|
||||||
public InvalidResponseCodeException(int responseCode, Map<String, List<String>> headerFields,
|
public InvalidResponseCodeException(int responseCode, Map<String, List<String>> headerFields,
|
||||||
DataSpec dataSpec) {
|
DataSpec dataSpec) {
|
||||||
super("Response code: " + responseCode, dataSpec);
|
super("Response code: " + responseCode, dataSpec, TYPE_OPEN);
|
||||||
this.responseCode = responseCode;
|
this.responseCode = responseCode;
|
||||||
this.headerFields = headerFields;
|
this.headerFields = headerFields;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user