Java Code Examples for com.google.android.exoplayer2.upstream.DataSpec#HTTP_METHOD_GET
The following examples show how to use
com.google.android.exoplayer2.upstream.DataSpec#HTTP_METHOD_GET .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CacheDataSource.java From MediaSDK with Apache License 2.0 | 6 votes |
@Override public void close() throws IOException { uri = null; actualUri = null; httpMethod = DataSpec.HTTP_METHOD_GET; httpBody = null; httpRequestHeaders = Collections.emptyMap(); flags = 0; readPosition = 0; key = null; notifyBytesRead(); try { closeCurrentSource(); } catch (Throwable e) { handleBeforeThrow(e); throw e; } }
Example 2
Source File: CacheDataSource.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
@Override public void close() throws IOException { uri = null; actualUri = null; httpMethod = DataSpec.HTTP_METHOD_GET; notifyBytesRead(); try { closeCurrentSource(); } catch (Throwable e) { handleBeforeThrow(e); throw e; } }
Example 3
Source File: CacheDataSource.java From Telegram with GNU General Public License v2.0 | 5 votes |
@Override public void close() throws IOException { uri = null; actualUri = null; httpMethod = DataSpec.HTTP_METHOD_GET; notifyBytesRead(); try { closeCurrentSource(); } catch (Throwable e) { handleBeforeThrow(e); throw e; } }
Example 4
Source File: GSYDefaultHttpDataSource.java From GSYVideoPlayer with Apache License 2.0 | 4 votes |
/** * Establishes a connection, following redirects to do so where permitted. */ private HttpURLConnection makeConnection(DataSpec dataSpec) throws IOException { URL url = new URL(dataSpec.uri.toString()); @HttpMethod int httpMethod = dataSpec.httpMethod; byte[] httpBody = dataSpec.httpBody; long position = dataSpec.position; long length = dataSpec.length; boolean allowGzip = dataSpec.isFlagSet(DataSpec.FLAG_ALLOW_GZIP); if (!allowCrossProtocolRedirects) { // HttpURLConnection disallows cross-protocol redirects, but otherwise performs redirection // automatically. This is the behavior we want, so use it. return makeConnection( url, httpMethod, httpBody, position, length, allowGzip, /* followRedirects= */ true, dataSpec.httpRequestHeaders); } // We need to handle redirects ourselves to allow cross-protocol redirects. int redirectCount = 0; while (redirectCount++ <= MAX_REDIRECTS) { HttpURLConnection connection = makeConnection( url, httpMethod, httpBody, position, length, allowGzip, /* followRedirects= */ false, dataSpec.httpRequestHeaders); int responseCode = connection.getResponseCode(); String location = connection.getHeaderField("Location"); if ((httpMethod == DataSpec.HTTP_METHOD_GET || httpMethod == DataSpec.HTTP_METHOD_HEAD) && (responseCode == HttpURLConnection.HTTP_MULT_CHOICE || responseCode == HttpURLConnection.HTTP_MOVED_PERM || responseCode == HttpURLConnection.HTTP_MOVED_TEMP || responseCode == HttpURLConnection.HTTP_SEE_OTHER || responseCode == HTTP_STATUS_TEMPORARY_REDIRECT || responseCode == HTTP_STATUS_PERMANENT_REDIRECT)) { connection.disconnect(); url = handleRedirect(url, location); } else if (httpMethod == DataSpec.HTTP_METHOD_POST && (responseCode == HttpURLConnection.HTTP_MULT_CHOICE || responseCode == HttpURLConnection.HTTP_MOVED_PERM || responseCode == HttpURLConnection.HTTP_MOVED_TEMP || responseCode == HttpURLConnection.HTTP_SEE_OTHER)) { // POST request follows the redirect and is transformed into a GET request. connection.disconnect(); httpMethod = DataSpec.HTTP_METHOD_GET; httpBody = null; url = handleRedirect(url, location); } else { return connection; } } // If we get here we've been redirected more times than are permitted. throw new NoRouteToHostException("Too many redirects: " + redirectCount); }