Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
4d84c1eb
Commit
4d84c1eb
authored
Aug 01, 2017
by
Filipe de Lima Brito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add getContentType(...) and getDefaultHttpClient() method.
parent
0c75c04f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
0 deletions
+39
-0
OkHttpHelper.java
...rc/main/java/chat/rocket/android/helper/OkHttpHelper.java
+39
-0
No files found.
app/src/main/java/chat/rocket/android/helper/OkHttpHelper.java
View file @
4d84c1eb
package
chat
.
rocket
.
android
.
helper
;
import
android.content.Context
;
import
android.support.annotation.NonNull
;
import
com.facebook.stetho.okhttp3.StethoInterceptor
;
import
java.io.IOException
;
import
java.util.concurrent.TimeUnit
;
import
chat.rocket.android.RocketChatCache
;
import
chat.rocket.android.api.rest.CookieInterceptor
;
import
chat.rocket.android.api.rest.DefaultCookieProvider
;
import
okhttp3.Call
;
import
okhttp3.Callback
;
import
okhttp3.OkHttpClient
;
import
okhttp3.Request
;
import
okhttp3.Response
;
/**
* Helper class for OkHttp client.
*/
public
class
OkHttpHelper
{
private
static
OkHttpClient
defaultHttpClient
;
private
static
OkHttpClient
httpClientForUploadFile
;
private
static
OkHttpClient
httpClientForDownloadFile
;
private
static
OkHttpClient
httpClientForWS
;
private
static
String
contentType
;
public
static
OkHttpClient
getDefaultHttpClient
()
{
if
(
defaultHttpClient
==
null
)
{
defaultHttpClient
=
new
OkHttpClient
();
}
return
defaultHttpClient
;
}
public
static
OkHttpClient
getClientForDownloadFile
(
Context
context
)
{
if
(
httpClientForDownloadFile
==
null
)
{
...
...
@@ -48,4 +63,28 @@ public class OkHttpHelper {
}
return
httpClientForWS
;
}
public
static
String
getContentType
(
String
uri
)
{
Request
request
=
new
Request
.
Builder
()
.
url
(
uri
)
.
head
()
.
build
();
getDefaultHttpClient
().
newCall
(
request
).
enqueue
(
new
Callback
()
{
@Override
public
void
onFailure
(
@NonNull
Call
call
,
@NonNull
IOException
ioException
)
{
ioException
.
printStackTrace
();
}
@Override
public
void
onResponse
(
@NonNull
Call
call
,
@NonNull
final
Response
response
)
throws
IOException
{
if
(!
response
.
isSuccessful
())
{
throw
new
IOException
(
"Unexpected code: "
+
response
);
}
else
{
contentType
=
response
.
header
(
"Content-Type"
);
}
}
});
return
contentType
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment