From d2c524d726ceb13c6d2a4f01eb5c24dfe443c1e5 Mon Sep 17 00:00:00 2001 From: cblay Date: Mon, 9 May 2016 13:39:05 -0700 Subject: [PATCH] Add open/read http exception classes. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=121871799 --- .../ext/okhttp/OkHttpDataSource.java | 4 ++-- .../upstream/DefaultHttpDataSource.java | 10 ++++---- .../exoplayer/upstream/HttpDataSource.java | 24 +++++++++++++------ 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/extensions/okhttp/src/main/java/com/google/android/exoplayer/ext/okhttp/OkHttpDataSource.java b/extensions/okhttp/src/main/java/com/google/android/exoplayer/ext/okhttp/OkHttpDataSource.java index 64e1c05ee8..7ed77aebe2 100644 --- a/extensions/okhttp/src/main/java/com/google/android/exoplayer/ext/okhttp/OkHttpDataSource.java +++ b/extensions/okhttp/src/main/java/com/google/android/exoplayer/ext/okhttp/OkHttpDataSource.java @@ -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); } } diff --git a/library/src/main/java/com/google/android/exoplayer/upstream/DefaultHttpDataSource.java b/library/src/main/java/com/google/android/exoplayer/upstream/DefaultHttpDataSource.java index 18546480a0..24d6d6e29b 100644 --- a/library/src/main/java/com/google/android/exoplayer/upstream/DefaultHttpDataSource.java +++ b/library/src/main/java/com/google/android/exoplayer/upstream/DefaultHttpDataSource.java @@ -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 { diff --git a/library/src/main/java/com/google/android/exoplayer/upstream/HttpDataSource.java b/library/src/main/java/com/google/android/exoplayer/upstream/HttpDataSource.java index 4d8e4af1be..0ebaeaba39 100644 --- a/library/src/main/java/com/google/android/exoplayer/upstream/HttpDataSource.java +++ b/library/src/main/java/com/google/android/exoplayer/upstream/HttpDataSource.java @@ -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> headerFields, DataSpec dataSpec) { - super("Response code: " + responseCode, dataSpec); + super("Response code: " + responseCode, dataSpec, TYPE_OPEN); this.responseCode = responseCode; this.headerFields = headerFields; }