Skip to content
This repository has been archived by the owner on Oct 28, 2023. It is now read-only.

Commit

Permalink
No double buffered stream reading
Browse files Browse the repository at this point in the history
  • Loading branch information
HaarigerHarald committed Dec 17, 2015
1 parent 477f409 commit c4a0c06
Showing 1 changed file with 8 additions and 21 deletions.
@@ -1,13 +1,11 @@
package at.huber.youtubeExtractor;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
Expand Down Expand Up @@ -176,18 +174,15 @@ private SparseArray<YtFile> getStreamUrls() throws IOException, InterruptedExcep
String dashMpdUrl = null;
String streamMap = null;
BufferedReader reader = null;
InputStream in = null;
URL getUrl = new URL(ytInfoUrl);
HttpURLConnection urlConnection = (HttpURLConnection) getUrl.openConnection();
urlConnection.setRequestProperty("User-Agent", USER_AGENT);
try {
in = new BufferedInputStream(urlConnection.getInputStream());
reader = new BufferedReader(new InputStreamReader(in));
reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
streamMap = reader.readLine();

} finally {
if (in != null && reader != null) {
in.close();
if (reader != null) {
reader.close();
}
urlConnection.disconnect();
Expand All @@ -210,8 +205,7 @@ private SparseArray<YtFile> getStreamUrls() throws IOException, InterruptedExcep
urlConnection = (HttpURLConnection) getUrl.openConnection();
urlConnection.setRequestProperty("User-Agent", USER_AGENT);
try {
in = new BufferedInputStream(urlConnection.getInputStream());
reader = new BufferedReader(new InputStreamReader(in));
reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
// Log.d("line", line);
Expand All @@ -221,8 +215,7 @@ private SparseArray<YtFile> getStreamUrls() throws IOException, InterruptedExcep
}
}
} finally {
if (in != null && reader != null) {
in.close();
if (reader != null) {
reader.close();
}
urlConnection.disconnect();
Expand Down Expand Up @@ -378,24 +371,21 @@ private boolean decipherSignature(final SparseArray<String> encSignatures) throw
if (decipherFunctionName == null || decipherFunctions == null) {
String decipherFunctUrl = "https://s.ytimg.com/yts/jsbin/" + decipherJsFileName;

InputStream in = null;
BufferedReader reader = null;
String javascriptFile = null;
URL url = new URL(decipherFunctUrl);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestProperty("User-Agent", USER_AGENT);
try {
in = new BufferedInputStream(urlConnection.getInputStream());
reader = new BufferedReader(new InputStreamReader(in));
reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
StringBuilder sb = new StringBuilder("");
String line;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
javascriptFile = sb.toString();
} finally {
if (in != null && reader != null) {
in.close();
if (reader != null) {
reader.close();
}
urlConnection.disconnect();
Expand Down Expand Up @@ -490,19 +480,16 @@ private void parseDashManifest(String dashMpdUrl, SparseArray<YtFile> ytFiles) t
Pattern patBaseUrl = Pattern.compile("<BaseURL yt:contentLength=\"[0-9]+?\">(.+?)</BaseURL>");
String dashManifest;
BufferedReader reader = null;
InputStream in = null;
URL getUrl = new URL(dashMpdUrl);
HttpURLConnection urlConnection = (HttpURLConnection) getUrl.openConnection();
urlConnection.setRequestProperty("User-Agent", USER_AGENT);
try {
in = new BufferedInputStream(urlConnection.getInputStream());
reader = new BufferedReader(new InputStreamReader(in));
reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
reader.readLine();
dashManifest = reader.readLine();

} finally {
if (in != null && reader != null) {
in.close();
if (reader != null) {
reader.close();
}
urlConnection.disconnect();
Expand Down

0 comments on commit c4a0c06

Please sign in to comment.