Example usage for com.squareup.okhttp.internal Util closeQuietly

List of usage examples for com.squareup.okhttp.internal Util closeQuietly

Introduction

In this page you can find the example usage for com.squareup.okhttp.internal Util closeQuietly.

Prototype

public static void closeQuietly(ServerSocket serverSocket) 

Source Link

Document

Closes serverSocket , ignoring any checked exceptions.

Usage

From source file:co.paralleluniverse.fibers.okhttp.SocksProxy.java

License:Open Source License

private void service(final Socket from) {
    executor.execute(new NamedRunnable("SocksProxy %s", from.getRemoteSocketAddress()) {
        @Override//from www  .  ja  va  2  s.c  om
        protected void execute() {
            try {
                BufferedSource fromSource = Okio.buffer(Okio.source(from));
                BufferedSink fromSink = Okio.buffer(Okio.sink(from));
                hello(fromSource, fromSink);
                acceptCommand(from.getInetAddress(), fromSource, fromSink);
            } catch (IOException e) {
                logger.log(Level.WARNING, name + " failed", e);
                Util.closeQuietly(from);
            }
        }
    });
}

From source file:codetoanalyze.java.infer.ReaderLeaks.java

License:Open Source License

private String strictLineReaderClosed(String journalFile) throws IOException {
    FileInputStream fs = new FileInputStream(journalFile);
    StrictLineReader reader = null;/*w w  w.  jav  a  2  s.  c om*/
    try {
        reader = new StrictLineReader(fs, Util.US_ASCII);
        String magic = reader.readLine();
        return magic;

    } finally {
        if (reader != null)
            Util.closeQuietly(reader);
        else
            fs.close();
        return null;
    }
}

From source file:codetoanalyze.java.infer.ReaderLeaks.java

License:Open Source License

private String strictLineReaderNoLeak(String journalFile) throws IOException {

    StrictLineReader reader = new StrictLineReader(new FileInputStream(journalFile), Util.US_ASCII);
    try {//  w w  w  .j ava2  s.c o m
        String magic = reader.readLine();
        return magic;

    } finally {
        Util.closeQuietly(reader);
        return null;
    }
}

From source file:com.android.cloudfiles.cloudfilesforandroid.CountingFileRequestBody.java

License:Apache License

@Override
public void writeTo(BufferedSink sink) throws IOException {
    Source source = null;// w w w. j a v  a  2  s.  co m
    try {
        source = Okio.source(inputStream);
        long total = 0;
        long read;

        while ((read = source.read(sink.buffer(), SEGMENT_SIZE)) != -1) {
            total += read;
            sink.flush();
            this.listener.percentageTransferred((int) ((total / (float) size) * 100));

        }
    } finally {
        Util.closeQuietly(source);
    }
}

From source file:com.facebook.react.modules.network.RequestBodyUtil.java

License:Open Source License

/**
 * Creates a RequestBody from a mediaType and inputStream given.
 *///from  w ww .j av  a 2s .com
public static RequestBody create(final MediaType mediaType, final InputStream inputStream) {
    return new RequestBody() {
        @Override
        public MediaType contentType() {
            return mediaType;
        }

        @Override
        public long contentLength() {
            try {
                return inputStream.available();
            } catch (IOException e) {
                return 0;
            }
        }

        @Override
        public void writeTo(BufferedSink sink) throws IOException {
            Source source = null;
            try {
                source = Okio.source(inputStream);
                sink.writeAll(source);
            } finally {
                Util.closeQuietly(source);
            }
        }
    };
}

From source file:com.google.android.exoplayer.ext.okhttp.OkHttpDataSource.java

License:Apache License

/**
 * Closes the current connection quietly, if there is one.
 *//*www  .  java2  s  .c om*/
private void closeConnectionQuietly() {
    Util.closeQuietly(response.body());
    response = null;
    responseByteStream = null;
}

From source file:com.ibm.watson.developer_cloud.http.InputStreamRequestBody.java

License:Open Source License

@Override
public void writeTo(BufferedSink sink) throws IOException {
    Source source = null;//from w ww  .  j ava  2  s .c  om
    try {
        source = Okio.source(inputStream);
        sink.writeAll(source);
    } finally {
        Util.closeQuietly(source);
    }
}

From source file:com.liferay.mobile.android.http.file.FileProgressUtil.java

License:Open Source License

public static void transfer(InputStream is, FileProgressCallback callback, Object tag, BufferedSink sink)
        throws IOException {

    Source source = null;/*from w w w .j  a va 2 s .  co  m*/

    try {
        source = Okio.source(is);
        Buffer os = new Buffer();

        while ((source.read(os, 2048) != -1) && !isCancelled(callback)) {
            byte[] bytes = os.readByteArray();

            if (sink != null) {
                sink.write(bytes);
            }

            if (callback != null) {
                callback.onBytes(bytes);
                callback.increment(bytes.length);
            }
        }

        if (isCancelled(callback)) {
            HttpUtil.cancel(tag);
        }
    } finally {
        Util.closeQuietly(source);
    }
}

From source file:com.liferay.mobile.sdk.file.FileTransfer.java

License:Open Source License

public static void transfer(InputStream is, FileProgressCallback callback, Object tag, BufferedSink sink)
        throws IOException {

    Source source = null;/*from  w ww. j a va2s  .c o  m*/

    try {
        source = Okio.source(is);
        Buffer os = new Buffer();

        while ((source.read(os, 2048) != -1) && !isCancelled(callback)) {
            byte[] bytes = os.readByteArray();

            if (sink != null) {
                sink.write(bytes);
            }

            if (callback != null) {
                callback.onBytes(bytes);
                callback.increment(bytes.length);
            }
        }

        if (isCancelled(callback)) {
            Call.cancel(tag);
        }
    } finally {
        Util.closeQuietly(source);
    }
}

From source file:com.nbs.ppm.contactapp.converter.GsonResponseBodyConverter.java

License:Apache License

@Override
public T convert(ResponseBody value) throws IOException {
    Reader reader = value.charStream();
    try {/* w  w w. j a v a  2  s. c o  m*/
        return adapter.fromJson(reader);
    } finally {
        Util.closeQuietly(reader);
    }
}