Remove usage of HttpRequest from StreamProxy.

Apache http client classes was removed since api 23. And actually this
HttpRequest doesn't required here at all.

Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
Yahor Berdnikau 2017-12-21 10:00:10 +01:00
parent ed78fce31c
commit 2e9935e182
1 changed files with 50 additions and 68 deletions

View File

@ -6,9 +6,6 @@ import org.moire.ultrasonic.domain.MusicDirectory;
import org.moire.ultrasonic.service.DownloadFile; import org.moire.ultrasonic.service.DownloadFile;
import org.moire.ultrasonic.service.DownloadService; import org.moire.ultrasonic.service.DownloadService;
import org.apache.http.HttpRequest;
import org.apache.http.message.BasicHttpRequest;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
@ -108,81 +105,66 @@ public class StreamProxy implements Runnable
Log.i(TAG, "Proxy interrupted. Shutting down."); Log.i(TAG, "Proxy interrupted. Shutting down.");
} }
private class StreamToMediaPlayerTask implements Runnable private class StreamToMediaPlayerTask implements Runnable {
{ String localPath;
Socket client;
int cbSkip;
String localPath; StreamToMediaPlayerTask(Socket client) {
Socket client; this.client = client;
int cbSkip; }
public StreamToMediaPlayerTask(Socket client) private String readRequest() {
{ InputStream is;
this.client = client; String firstLine;
} try {
is = client.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is), 8192);
firstLine = reader.readLine();
} catch (IOException e) {
Log.e(TAG, "Error parsing request", e);
return null;
}
private HttpRequest readRequest() if (firstLine == null) {
{ Log.i(TAG, "Proxy client closed connection without a request.");
HttpRequest request; return null;
InputStream is; }
String firstLine;
try
{
is = client.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is), 8192);
firstLine = reader.readLine();
}
catch (IOException e)
{
Log.e(TAG, "Error parsing request", e);
return null;
}
if (firstLine == null) StringTokenizer st = new StringTokenizer(firstLine);
{ st.nextToken(); // method
Log.i(TAG, "Proxy client closed connection without a request."); String uri = st.nextToken();
return null; String realUri = uri.substring(1);
} Log.i(TAG, realUri);
StringTokenizer st = new StringTokenizer(firstLine); return realUri;
String method = st.nextToken(); }
String uri = st.nextToken();
String realUri = uri.substring(1);
Log.i(TAG, realUri);
request = new BasicHttpRequest(method, realUri);
return request;
}
public boolean processRequest() boolean processRequest() {
{ final String uri = readRequest();
HttpRequest request = readRequest(); if (uri == null || uri.isEmpty()) {
if (request == null) return false;
{ }
return false;
}
// Read HTTP headers // Read HTTP headers
Log.i(TAG, "Processing request"); Log.i(TAG, "Processing request: " + uri);
try try {
{ localPath = URLDecoder.decode(uri, Constants.UTF_8);
localPath = URLDecoder.decode(request.getRequestLine().getUri(), Constants.UTF_8); } catch (UnsupportedEncodingException e) {
} Log.e(TAG, "Unsupported encoding", e);
catch (UnsupportedEncodingException e) return false;
{ }
Log.e(TAG, "Unsupported encoding", e);
return false;
}
Log.i(TAG, String.format("Processing request for file %s", localPath)); Log.i(TAG, String.format("Processing request for file %s", localPath));
File file = new File(localPath); File file = new File(localPath);
if (!file.exists()) if (!file.exists()) {
{ Log.e(TAG, String.format("File %s does not exist", localPath));
Log.e(TAG, String.format("File %s does not exist", localPath)); return false;
return false; }
}
return true; return true;
} }
@Override @Override
public void run() public void run()