Search in sources :

Example 1 with OkUrlFactory

use of com.squareup.okhttp.OkUrlFactory in project markdown-doclet by Abnaxos.

the class GithubAccessor method createCachedHttpConnector.

private OkHttpConnector createCachedHttpConnector() {
    final File cacheDirectory = getCacheDirectory();
    final Cache cache = new Cache(cacheDirectory, this.cacheSize);
    return new OkHttpConnector(new OkUrlFactory(new OkHttpClient().setCache(cache)));
}
Also used : OkUrlFactory(com.squareup.okhttp.OkUrlFactory) OkHttpClient(com.squareup.okhttp.OkHttpClient) OkHttpConnector(org.kohsuke.github.extras.OkHttpConnector) File(java.io.File) Cache(com.squareup.okhttp.Cache)

Example 2 with OkUrlFactory

use of com.squareup.okhttp.OkUrlFactory in project AndroidNetworkDemo by dodocat.

the class SelfSignSslOkHttpStack method createConnection.

@Override
protected HttpURLConnection createConnection(URL url) throws IOException {
    if ("https".equals(url.getProtocol()) && socketFactoryMap.containsKey(url.getHost())) {
        HttpsURLConnection connection = (HttpsURLConnection) new OkUrlFactory(okHttpClient).open(url);
        connection.setSSLSocketFactory(socketFactoryMap.get(url.getHost()));
        return connection;
    } else {
        return new OkUrlFactory(okHttpClient).open(url);
    }
}
Also used : OkUrlFactory(com.squareup.okhttp.OkUrlFactory) HttpsURLConnection(javax.net.ssl.HttpsURLConnection)

Example 3 with OkUrlFactory

use of com.squareup.okhttp.OkUrlFactory in project robospice by stephanenicolas.

the class OkHttpBinaryRequest method loadDataFromNetwork.

@Override
public final InputStream loadDataFromNetwork() throws Exception {
    try {
        OkUrlFactory urlFactory = new OkUrlFactory(getOkHttpClient());
        HttpURLConnection connection = urlFactory.open(new URL(url));
        return processStream(connection.getContentLength(), connection.getInputStream());
    } catch (final MalformedURLException e) {
        Ln.e(e, "Unable to create URL");
        throw e;
    } catch (final IOException e) {
        Ln.e(e, "Unable to download binary");
        throw e;
    }
}
Also used : OkUrlFactory(com.squareup.okhttp.OkUrlFactory) MalformedURLException(java.net.MalformedURLException) HttpURLConnection(java.net.HttpURLConnection) IOException(java.io.IOException) URL(java.net.URL)

Example 4 with OkUrlFactory

use of com.squareup.okhttp.OkUrlFactory in project robospice by stephanenicolas.

the class OkHttpBitmapRequest method loadDataFromNetwork.

@Override
public Bitmap loadDataFromNetwork() throws Exception {
    try {
        OkUrlFactory urlFactory = new OkUrlFactory(getOkHttpClient());
        HttpURLConnection connection = urlFactory.open(new URL(url));
        processStream(connection.getContentLength(), connection.getInputStream());
        if (width != -1 && height != -1) {
            this.options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;
            BitmapFactory.decodeFile(cacheFile.getAbsolutePath(), options);
            options.inSampleSize = calculateInSampleSize(options, width, height);
            options.inJustDecodeBounds = false;
            options.inPurgeable = true;
            return BitmapFactory.decodeFile(cacheFile.getAbsolutePath(), options);
        } else {
            return BitmapFactory.decodeFile(cacheFile.getAbsolutePath(), options);
        }
    } catch (final MalformedURLException e) {
        Ln.e(e, "Unable to create URL");
        throw e;
    } catch (final IOException e) {
        Ln.e(e, "Unable to download binary");
        throw e;
    }
}
Also used : OkUrlFactory(com.squareup.okhttp.OkUrlFactory) MalformedURLException(java.net.MalformedURLException) HttpURLConnection(java.net.HttpURLConnection) BitmapFactory(android.graphics.BitmapFactory) IOException(java.io.IOException) URL(java.net.URL)

Example 5 with OkUrlFactory

use of com.squareup.okhttp.OkUrlFactory in project robospice by stephanenicolas.

the class OkHttpSimpleTextRequest method loadDataFromNetwork.

// can't use activity here or any non serializable field
// will be invoked in remote service
@Override
public String loadDataFromNetwork() throws Exception {
    try {
        Ln.d("Call web service " + url);
        OkUrlFactory urlFactory = new OkUrlFactory(getOkHttpClient());
        HttpURLConnection connection = urlFactory.open(new URL(url));
        return IOUtils.toString(connection.getInputStream());
    } catch (final MalformedURLException e) {
        Ln.e(e, "Unable to create URL");
        throw e;
    } catch (final IOException e) {
        Ln.e(e, "Unable to download content");
        throw e;
    }
}
Also used : OkUrlFactory(com.squareup.okhttp.OkUrlFactory) MalformedURLException(java.net.MalformedURLException) HttpURLConnection(java.net.HttpURLConnection) IOException(java.io.IOException) URL(java.net.URL)

Aggregations

OkUrlFactory (com.squareup.okhttp.OkUrlFactory)5 IOException (java.io.IOException)3 HttpURLConnection (java.net.HttpURLConnection)3 MalformedURLException (java.net.MalformedURLException)3 URL (java.net.URL)3 BitmapFactory (android.graphics.BitmapFactory)1 Cache (com.squareup.okhttp.Cache)1 OkHttpClient (com.squareup.okhttp.OkHttpClient)1 File (java.io.File)1 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)1 OkHttpConnector (org.kohsuke.github.extras.OkHttpConnector)1