libcore
Revision | f241d462634527692b7d99335cdc8c11883ac966 (tree) |
---|---|
Time | 2011-03-30 03:23:46 |
Author | Jesse Wilson <jessewilson@goog...> |
Commiter | Jesse Wilson |
Don't read from the delegate stream after we close it.
Change-Id: I9a018ca88373d5f317335e35fc6ca43c5473490e
http://b/4188137
@@ -34,7 +34,7 @@ final class UnknownLengthHttpInputStream extends AbstractHttpInputStream { | ||
34 | 34 | @Override public int read(byte[] buffer, int offset, int count) throws IOException { |
35 | 35 | checkBounds(buffer, offset, count); |
36 | 36 | checkNotClosed(); |
37 | - if (in == null) { | |
37 | + if (in == null || inputExhausted) { | |
38 | 38 | return -1; |
39 | 39 | } |
40 | 40 | int read = in.read(buffer, offset, count); |
@@ -1501,6 +1501,24 @@ public class URLConnectionTest extends junit.framework.TestCase { | ||
1501 | 1501 | } |
1502 | 1502 | |
1503 | 1503 | /** |
1504 | + * http://code.google.com/p/android/issues/detail?id=14562 | |
1505 | + */ | |
1506 | + public void testReadAfterLastByte() throws Exception { | |
1507 | + server.enqueue(new MockResponse() | |
1508 | + .setBody("ABC") | |
1509 | + .clearHeaders() | |
1510 | + .addHeader("Connection: close") | |
1511 | + .setDisconnectAtEnd(true)); | |
1512 | + server.play(); | |
1513 | + | |
1514 | + HttpURLConnection connection = (HttpURLConnection) server.getUrl("/").openConnection(); | |
1515 | + InputStream in = connection.getInputStream(); | |
1516 | + assertEquals("ABC", readAscii(in, 3)); | |
1517 | + assertEquals(-1, in.read()); | |
1518 | + assertEquals(-1, in.read()); // throws IOException in Gingerbread | |
1519 | + } | |
1520 | + | |
1521 | + /** | |
1504 | 1522 | * Encodes the response body using GZIP and adds the corresponding header. |
1505 | 1523 | */ |
1506 | 1524 | public byte[] gzip(byte[] bytes) throws IOException { |
@@ -32,12 +32,12 @@ import java.net.URL; | ||
32 | 32 | import java.net.UnknownHostException; |
33 | 33 | import java.util.ArrayList; |
34 | 34 | import java.util.Collections; |
35 | -import java.util.HashSet; | |
36 | 35 | import java.util.Iterator; |
37 | 36 | import java.util.List; |
38 | 37 | import java.util.Set; |
39 | 38 | import java.util.concurrent.BlockingQueue; |
40 | 39 | import java.util.concurrent.Callable; |
40 | +import java.util.concurrent.ConcurrentHashMap; | |
41 | 41 | import java.util.concurrent.ExecutorService; |
42 | 42 | import java.util.concurrent.Executors; |
43 | 43 | import java.util.concurrent.LinkedBlockingDeque; |
@@ -59,7 +59,7 @@ public final class MockWebServer { | ||
59 | 59 | private final BlockingQueue<MockResponse> responseQueue |
60 | 60 | = new LinkedBlockingDeque<MockResponse>(); |
61 | 61 | private final Set<Socket> openClientSockets |
62 | - = Collections.synchronizedSet(new HashSet<Socket>()); | |
62 | + = Collections.newSetFromMap(new ConcurrentHashMap<Socket, Boolean>()); | |
63 | 63 | private boolean singleResponse; |
64 | 64 | private final AtomicInteger requestCount = new AtomicInteger(); |
65 | 65 | private int bodyLimit = Integer.MAX_VALUE; |