From 35ead0f5d17b0c53610b0947aa9bd8fee6da50fa Mon Sep 17 00:00:00 2001 From: "lingming.yb" Date: Mon, 23 Dec 2013 17:02:52 +0800 Subject: [PATCH] extract a method --- .../java/com/squareup/okhttp/Connection.java | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/okhttp/src/main/java/com/squareup/okhttp/Connection.java b/okhttp/src/main/java/com/squareup/okhttp/Connection.java index 95a644311..f89930bb7 100644 --- a/okhttp/src/main/java/com/squareup/okhttp/Connection.java +++ b/okhttp/src/main/java/com/squareup/okhttp/Connection.java @@ -107,12 +107,7 @@ public final class Connection implements Closeable { upgradeToTls(tunnelRequest); } else{ - // Use MTU-sized buffers to send fewer packets. - int mtu = Platform.get().getMtu(socket); - if (mtu < 1024) mtu = 1024; - if (mtu > 8192) mtu = 8192; - in = new BufferedInputStream(in, mtu); - out = new BufferedOutputStream(out, mtu); + streamWrapper(); } } @@ -153,13 +148,7 @@ public final class Connection implements Closeable { out = sslSocket.getOutputStream(); in = sslSocket.getInputStream(); - - // Use MTU-sized buffers to send fewer packets. - int mtu = Platform.get().getMtu(socket); - if (mtu < 1024) mtu = 1024; - if (mtu > 8192) mtu = 8192; - in = new BufferedInputStream(in, mtu); - out = new BufferedOutputStream(out, mtu); + streamWrapper(); byte[] selectedProtocol; if (useNpn && (selectedProtocol = platform.getNpnSelectedProtocol(sslSocket)) != null) { @@ -340,4 +329,13 @@ public final class Connection implements Closeable { } } } + + private void streamWrapper(){ + //Use MTU-sized buffers to send fewer packets. + int mtu = Platform.get().getMtu(socket); + if (mtu < 1024) mtu = 1024; + if (mtu > 8192) mtu = 8192; + in = new BufferedInputStream(in, mtu); + out = new BufferedOutputStream(out, mtu); + } }