You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ro...@apache.org on 2007/02/11 12:25:29 UTC
svn commit: r505890 - in /jakarta/commons/proper/httpclient/trunk:
release_notes.txt
src/java/org/apache/commons/httpclient/AutoCloseInputStream.java
src/test/org/apache/commons/httpclient/TestStreams.java
Author: rolandw
Date: Sun Feb 11 03:25:25 2007
New Revision: 505890
URL: http://svn.apache.org/viewvc?view=rev&rev=505890
Log:
HTTPCLIENT-628
Modified:
jakarta/commons/proper/httpclient/trunk/release_notes.txt
jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/AutoCloseInputStream.java
jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestStreams.java
Modified: jakarta/commons/proper/httpclient/trunk/release_notes.txt
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/httpclient/trunk/release_notes.txt?view=diff&rev=505890&r1=505889&r2=505890
==============================================================================
--- jakarta/commons/proper/httpclient/trunk/release_notes.txt (original)
+++ jakarta/commons/proper/httpclient/trunk/release_notes.txt Sun Feb 11 03:25:25 2007
@@ -1,5 +1,8 @@
Changes since Release 3.1 Beta 1:
+* [HTTPCLIENT-628] - IOException in AutoCloseInputStream.available()
+ Contributed by Roland Weber <rolandw at apache.org>
+
* [HTTPCLIENT-625] - revised shutdown of MultiThreadedHttpConnectionManager
Contributed by Roland Weber <rolandw at apache.org>
Modified: jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/AutoCloseInputStream.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/AutoCloseInputStream.java?view=diff&rev=505890&r1=505889&r2=505890
==============================================================================
--- jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/AutoCloseInputStream.java (original)
+++ jakarta/commons/proper/httpclient/trunk/src/java/org/apache/commons/httpclient/AutoCloseInputStream.java Sun Feb 11 03:25:25 2007
@@ -131,6 +131,23 @@
}
/**
+ * Obtains the number of bytes that can be read without blocking.
+ *
+ * @return the number of bytes available without blocking
+ * @throws IOException in case of a problem
+ */
+ public int available() throws IOException {
+ int a = 0; // not -1
+
+ if (isReadAllowed()) {
+ a = super.available();
+ // no checkClose() here, available() can't trigger EOF
+ }
+
+ return a;
+ }
+
+ /**
* Close the stream, and also close the underlying stream if it is not
* already closed.
* @throws IOException If an IO problem occurs.
Modified: jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestStreams.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestStreams.java?view=diff&rev=505890&r1=505889&r2=505890
==============================================================================
--- jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestStreams.java (original)
+++ jakarta/commons/proper/httpclient/trunk/src/test/org/apache/commons/httpclient/TestStreams.java Sun Feb 11 03:25:25 2007
@@ -270,5 +270,52 @@
String[] testCaseName = { TestStreams.class.getName() };
junit.textui.TestRunner.main(testCaseName);
}
+
+
+ public void testAutoCloseInputStream() throws IOException {
+ // The purpose of this test is to check EOF handling of ACIS with
+ // respect to exceptions being thrown. Putting it on top of a
+ // plain ByteArrayInputStream won't do, since BAIS can't be closed.
+ ByteArrayInputStream bais =
+ new ByteArrayInputStream("whatever".getBytes());
+ InputStream fbais = new java.io.FilterInputStream(bais) {
+ private boolean closed = false;
+ public void close() throws IOException {
+ closed = true;
+ super.close();
+ }
+ public int available() throws IOException {
+ if (closed)
+ throw new IOException("closed");
+ return super.available();
+ }
+ };
+
+ AutoCloseInputStream acis = new AutoCloseInputStream(fbais, null);
+ byte[] data = new byte[16];
+ int count = 0;
+ while (count >= 0) {
+ count = acis.read(data);
+ }
+ // We're at EOF. The underlying stream should be closed,
+ // but the ACIS itself not.
+ try {
+ fbais.available();
+ fail("underlying stream not auto-closed");
+ } catch (IOException x) {
+ // expected, pis should be closed
+ }
+
+ // don't want to see an exception being thrown here
+ acis.available();
+
+ acis.close();
+ try {
+ acis.available();
+ fail("auto-close stream not closed");
+ } catch (IOException x) {
+ // expected, acis should be closed
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org