diff options
author | Koushik Dutta <koushd@gmail.com> | 2014-07-28 02:20:11 -0700 |
---|---|---|
committer | Koushik Dutta <koushd@gmail.com> | 2014-07-28 02:20:11 -0700 |
commit | bbc47ab4b3b093f09d96a6dee1a0b460e2f903ea (patch) | |
tree | 172e74d05604373ae0355584837242e786e80ddb /AndroidAsync | |
parent | c5d92d36e9613a47e54a8591484900277a2137fb (diff) | |
download | AndroidAsync-bbc47ab4b3b093f09d96a6dee1a0b460e2f903ea.tar.gz AndroidAsync-bbc47ab4b3b093f09d96a6dee1a0b460e2f903ea.tar.bz2 AndroidAsync-bbc47ab4b3b093f09d96a6dee1a0b460e2f903ea.zip |
remove cruft
Diffstat (limited to 'AndroidAsync')
7 files changed, 1 insertions, 428 deletions
diff --git a/AndroidAsync/src/com/koushikdutta/async/http/spdy/AsyncSpdyConnection.java b/AndroidAsync/src/com/koushikdutta/async/http/spdy/AsyncSpdyConnection.java index a961cbf..5c5f95c 100644 --- a/AndroidAsync/src/com/koushikdutta/async/http/spdy/AsyncSpdyConnection.java +++ b/AndroidAsync/src/com/koushikdutta/async/http/spdy/AsyncSpdyConnection.java @@ -40,21 +40,10 @@ public class AsyncSpdyConnection implements FrameReader.Handler { FrameReader reader; FrameWriter writer; Variant variant; - ByteBufferListSink sink = new ByteBufferListSink() { - @Override - public void flush() throws IOException { - AsyncSpdyConnection.this.flush(); - } - }; - BufferedSink bufferedSink; Hashtable<Integer, SpdySocket> sockets = new Hashtable<Integer, SpdySocket>(); Protocol protocol; boolean client = true; - public void flush() { - bufferedSocket.write(sink); - } - /** * Returns a new locally-initiated stream. * @@ -123,7 +112,7 @@ public class AsyncSpdyConnection implements FrameReader.Handler { CompletedCallback closedCallback; CompletedCallback endCallback; DataCallback dataCallback; - ByteBufferListSink pending = new ByteBufferListSink(); + ByteBufferList pending = new ByteBufferList(); SimpleFuture<List<Header>> headers = new SimpleFuture<List<Header>>(); boolean isOpen = true; int totalWindowRead; diff --git a/AndroidAsync/src/com/koushikdutta/async/http/spdy/ByteBufferListSink.java b/AndroidAsync/src/com/koushikdutta/async/http/spdy/ByteBufferListSink.java deleted file mode 100644 index aa9da9a..0000000 --- a/AndroidAsync/src/com/koushikdutta/async/http/spdy/ByteBufferListSink.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.koushikdutta.async.http.spdy; - -import com.koushikdutta.async.ByteBufferList; -import com.koushikdutta.async.http.spdy.okio.Buffer; -import com.koushikdutta.async.http.spdy.okio.Segment; -import com.koushikdutta.async.http.spdy.okio.SegmentPool; -import com.koushikdutta.async.http.spdy.okio.Sink; -import com.koushikdutta.async.http.spdy.okio.Timeout; - -import java.io.IOException; -import java.nio.ByteBuffer; - -/** - * Created by koush on 7/25/14. - */ -public class ByteBufferListSink extends ByteBufferList implements Sink { - @Override - public void write(Buffer source, long byteCount) throws IOException { - Segment s = source.head; - while (byteCount > 0) { - int toCopy = (int) Math.min(byteCount, s.limit - s.pos); - ByteBuffer b = obtain(toCopy); - b.put(s.data, s.pos, toCopy); - b.flip(); - add(b); - - s.pos += toCopy; - source.size -= toCopy; - byteCount -= toCopy; - - if (s.pos == s.limit) { - Segment toRecycle = s; - source.head = s = toRecycle.pop(); - SegmentPool.getInstance().recycle(toRecycle); - } - } - } - - @Override - public void flush() throws IOException { - } - - @Override - public Timeout timeout() { - return Timeout.NONE; - } - - @Override - public void close() throws IOException { - recycle(); - } -} diff --git a/AndroidAsync/src/com/koushikdutta/async/http/spdy/ByteBufferListSource.java b/AndroidAsync/src/com/koushikdutta/async/http/spdy/ByteBufferListSource.java deleted file mode 100644 index 13803b3..0000000 --- a/AndroidAsync/src/com/koushikdutta/async/http/spdy/ByteBufferListSource.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.koushikdutta.async.http.spdy; - -import com.koushikdutta.async.ByteBufferList; -import com.koushikdutta.async.http.spdy.okio.Buffer; -import com.koushikdutta.async.http.spdy.okio.Source; -import com.koushikdutta.async.http.spdy.okio.Timeout; - -import java.io.IOException; -import java.nio.ByteBuffer; - -/** - * Created by koush on 7/25/14. - */ -public class ByteBufferListSource extends ByteBufferList implements Source { - @Override - public long read(Buffer sink, long byteCount) throws IOException { - if (!hasRemaining()) - throw new AssertionError("empty!"); - int total = 0; - while (total < byteCount && hasRemaining()) { - ByteBuffer b = remove(); - int toRead = (int)Math.min(byteCount - total, b.remaining()); - total += toRead; - sink.write(b.array(), b.arrayOffset() + b.position(), toRead); - b.position(b.position() + toRead); - addFirst(b); - } - return total; - } - - @Override - public Timeout timeout() { - return Timeout.NONE; - } - - @Override - public void close() throws IOException { - recycle(); - } -} diff --git a/AndroidAsync/src/com/koushikdutta/async/http/spdy/SpdyMiddleware.java b/AndroidAsync/src/com/koushikdutta/async/http/spdy/SpdyMiddleware.java index 0e09fdd..b97f261 100644 --- a/AndroidAsync/src/com/koushikdutta/async/http/spdy/SpdyMiddleware.java +++ b/AndroidAsync/src/com/koushikdutta/async/http/spdy/SpdyMiddleware.java @@ -83,7 +83,6 @@ public class SpdyMiddleware extends AsyncSSLSocketMiddleware { } final AsyncSpdyConnection connection = new AsyncSpdyConnection(socket, Protocol.get(protoString)); connection.sendConnectionPreface(); - connection.flush(); connections.put(data.request.getUri().getHost(), connection); @@ -123,7 +122,6 @@ public class SpdyMiddleware extends AsyncSSLSocketMiddleware { } AsyncSpdyConnection.SpdySocket spdy = connection.newStream(headers, false, true); - connection.flush(); callback.onConnectCompleted(null, spdy); } diff --git a/AndroidAsync/src/com/koushikdutta/async/http/spdy/okio/DeflaterSink.java b/AndroidAsync/src/com/koushikdutta/async/http/spdy/okio/DeflaterSink.java deleted file mode 100644 index 960ee80..0000000 --- a/AndroidAsync/src/com/koushikdutta/async/http/spdy/okio/DeflaterSink.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (C) 2014 Square, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.koushikdutta.async.http.spdy.okio; - -import java.io.IOException; -import java.util.zip.Deflater; - -import static com.koushikdutta.async.http.spdy.okio.Util.checkOffsetAndCount; - -/** - * A sink that uses <a href="http://tools.ietf.org/html/rfc1951">DEFLATE</a> to - * compress data written to another source. - * - * <h3>Sync flush</h3> - * Aggressive flushing of this stream may result in reduced compression. Each - * call to {@link #flush} immediately compresses all currently-buffered data; - * this early compression may be less effective than compression performed - * without flushing. - * - * <p>This is equivalent to using {@link java.util.zip.Deflater} with the sync flush option. - * This class does not offer any partial flush mechanism. For best performance, - * only call {@link #flush} when application behavior requires it. - */ -public final class DeflaterSink implements Sink { - private final BufferedSink sink; - private final Deflater deflater; - private boolean closed; - - public DeflaterSink(Sink sink, Deflater deflater) { - this(Okio.buffer(sink), deflater); - } - - /** - * This package-private constructor shares a buffer with its trusted caller. - * In general we can't share a BufferedSource because the deflater holds input - * bytes until they are inflated. - */ - DeflaterSink(BufferedSink sink, Deflater deflater) { - if (sink == null) throw new IllegalArgumentException("source == null"); - if (deflater == null) throw new IllegalArgumentException("inflater == null"); - this.sink = sink; - this.deflater = deflater; - } - - @Override public void write(Buffer source, long byteCount) - throws IOException { - checkOffsetAndCount(source.size, 0, byteCount); - while (byteCount > 0) { - // Share bytes from the head segment of 'source' with the deflater. - Segment head = source.head; - int toDeflate = (int) Math.min(byteCount, head.limit - head.pos); - deflater.setInput(head.data, head.pos, toDeflate); - - // Deflate those bytes into sink. - deflate(false); - - // Mark those bytes as read. - source.size -= toDeflate; - head.pos += toDeflate; - if (head.pos == head.limit) { - source.head = head.pop(); - SegmentPool.getInstance().recycle(head); - } - - byteCount -= toDeflate; - } - } - - private void deflate(boolean syncFlush) throws IOException { - Buffer buffer = sink.buffer(); - while (true) { - Segment s = buffer.writableSegment(1); - - // The 4-parameter overload of deflate() doesn't exist in the RI until - // Java 1.7, and is public (although with @hide) on Android since 2.3. - // The @hide tag means that this code won't compile against the Android - // 2.3 SDK, but it will run fine there. - int deflated = syncFlush - ? deflater.deflate(s.data, s.limit, Segment.SIZE - s.limit, Deflater.SYNC_FLUSH) - : deflater.deflate(s.data, s.limit, Segment.SIZE - s.limit); - - if (deflated > 0) { - s.limit += deflated; - buffer.size += deflated; - sink.emitCompleteSegments(); - } else if (deflater.needsInput()) { - return; - } - } - } - - @Override public void flush() throws IOException { - deflate(true); - sink.flush(); - } - - void finishDeflate() throws IOException { - deflater.finish(); - deflate(false); - } - - @Override public void close() throws IOException { - if (closed) return; - - // Emit deflated data to the underlying sink. If this fails, we still need - // to close the deflater and the sink; otherwise we risk leaking resources. - Throwable thrown = null; - try { - finishDeflate(); - } catch (Throwable e) { - thrown = e; - } - - try { - deflater.end(); - } catch (Throwable e) { - if (thrown == null) thrown = e; - } - - try { - sink.close(); - } catch (Throwable e) { - if (thrown == null) thrown = e; - } - closed = true; - - if (thrown != null) Util.sneakyRethrow(thrown); - } - - @Override public Timeout timeout() { - return sink.timeout(); - } - - @Override public String toString() { - return "DeflaterSink(" + sink + ")"; - } -} diff --git a/AndroidAsync/src/com/koushikdutta/async/http/spdy/okio/ForwardingSource.java b/AndroidAsync/src/com/koushikdutta/async/http/spdy/okio/ForwardingSource.java deleted file mode 100644 index 5e48dfd..0000000 --- a/AndroidAsync/src/com/koushikdutta/async/http/spdy/okio/ForwardingSource.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2014 Square, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.koushikdutta.async.http.spdy.okio; - -import java.io.IOException; - -/** A {@link Source} which forwards calls to another. Useful for subclassing. */ -public abstract class ForwardingSource implements Source { - private final Source delegate; - - public ForwardingSource(Source delegate) { - if (delegate == null) throw new IllegalArgumentException("delegate == null"); - this.delegate = delegate; - } - - /** {@link Source} to which this instance is delegating. */ - public final Source delegate() { - return delegate; - } - - @Override public long read(Buffer sink, long byteCount) throws IOException { - return delegate.read(sink, byteCount); - } - - @Override public Timeout timeout() { - return delegate.timeout(); - } - - @Override public void close() throws IOException { - delegate.close(); - } - - @Override public String toString() { - return getClass().getSimpleName() + "(" + delegate.toString() + ")"; - } -} diff --git a/AndroidAsync/src/com/koushikdutta/async/http/spdy/okio/InflaterSource.java b/AndroidAsync/src/com/koushikdutta/async/http/spdy/okio/InflaterSource.java deleted file mode 100644 index 76f7cc0..0000000 --- a/AndroidAsync/src/com/koushikdutta/async/http/spdy/okio/InflaterSource.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (C) 2014 Square, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.koushikdutta.async.http.spdy.okio; - -import java.io.EOFException; -import java.io.IOException; -import java.util.zip.DataFormatException; -import java.util.zip.Inflater; - -/** - * A source that uses <a href="http://tools.ietf.org/html/rfc1951">DEFLATE</a> - * to decompress data read from another source. - */ -public final class InflaterSource implements Source { - private final BufferedSource source; - private final Inflater inflater; - - /** - * When we call Inflater.setInput(), the inflater keeps our byte array until - * it needs input again. This tracks how many bytes the inflater is currently - * holding on to. - */ - private int bufferBytesHeldByInflater; - private boolean closed; - - public InflaterSource(Source source, Inflater inflater) { - this(Okio.buffer(source), inflater); - } - - /** - * This package-private constructor shares a buffer with its trusted caller. - * In general we can't share a BufferedSource because the inflater holds input - * bytes until they are inflated. - */ - InflaterSource(BufferedSource source, Inflater inflater) { - if (source == null) throw new IllegalArgumentException("source == null"); - if (inflater == null) throw new IllegalArgumentException("inflater == null"); - this.source = source; - this.inflater = inflater; - } - - @Override public long read( - Buffer sink, long byteCount) throws IOException { - if (byteCount < 0) throw new IllegalArgumentException("byteCount < 0: " + byteCount); - if (closed) throw new IllegalStateException("closed"); - if (byteCount == 0) return 0; - - while (true) { - boolean sourceExhausted = refill(); - - // Decompress the inflater's compressed data into the sink. - try { - Segment tail = sink.writableSegment(1); - int bytesInflated = inflater.inflate(tail.data, tail.limit, Segment.SIZE - tail.limit); - if (bytesInflated > 0) { - tail.limit += bytesInflated; - sink.size += bytesInflated; - return bytesInflated; - } - if (inflater.finished() || inflater.needsDictionary()) { - releaseInflatedBytes(); - return -1; - } - if (sourceExhausted) throw new EOFException("source exhausted prematurely"); - } catch (DataFormatException e) { - throw new IOException(e); - } - } - } - - /** - * Refills the inflater with compressed data if it needs input. (And only if - * it needs input). Returns true if the inflater required input but the source - * was exhausted. - */ - public boolean refill() throws IOException { - if (!inflater.needsInput()) return false; - - releaseInflatedBytes(); - if (inflater.getRemaining() != 0) throw new IllegalStateException("?"); // TODO: possible? - - // If there are compressed bytes in the source, assign them to the inflater. - if (source.exhausted()) return true; - - // Assign buffer bytes to the inflater. - Segment head = source.buffer().head; - bufferBytesHeldByInflater = head.limit - head.pos; - inflater.setInput(head.data, head.pos, bufferBytesHeldByInflater); - return false; - } - - /** When the inflater has processed compressed data, remove it from the buffer. */ - private void releaseInflatedBytes() throws IOException { - if (bufferBytesHeldByInflater == 0) return; - int toRelease = bufferBytesHeldByInflater - inflater.getRemaining(); - bufferBytesHeldByInflater -= toRelease; - source.skip(toRelease); - } - - @Override public Timeout timeout() { - return source.timeout(); - } - - @Override public void close() throws IOException { - if (closed) return; - inflater.end(); - closed = true; - source.close(); - } -} |