You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by py...@apache.org on 2007/06/07 08:03:26 UTC
svn commit: r545077 - in
/harmony/enhanced/classlib/branches/java6/modules/luni/src:
main/java/java/io/PipedInputStream.java
main/java/java/io/PipedOutputStream.java
test/java/tests/api/java/io/PipedInputStreamTest.java
Author: pyang
Date: Wed Jun 6 23:03:25 2007
New Revision: 545077
URL: http://svn.apache.org/viewvc?view=rev&rev=545077
Log:
Apply patch for HARMONY-4059([classlib][luni][java6]new constructors of java.io.PipedInputStream)
Modified:
harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/io/PipedInputStream.java
harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/io/PipedOutputStream.java
harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/tests/api/java/io/PipedInputStreamTest.java
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/io/PipedInputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/io/PipedInputStream.java?view=diff&rev=545077&r1=545076&r2=545077
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/io/PipedInputStream.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/io/PipedInputStream.java Wed Jun 6 23:03:25 2007
@@ -80,6 +80,45 @@
public PipedInputStream(PipedOutputStream out) throws IOException {
connect(out);
}
+
+ /**
+ * Constructs a new PipedInputStream connected to the PipedOutputStream
+ * <code>out</code> and uses the specified buffer size. Any data written
+ * to the output stream can be read from this input stream.
+ *
+ * @param out
+ * the PipedOutputStream to connect to.
+ * @param pipeSize
+ * the size of the buffer.
+ * @throws IOException
+ * if an I/O error occurs.
+ * @throws IllegalArgumentException
+ * if pipeSize is less than or equal to zero.
+ * @since 1.6
+ */
+ public PipedInputStream(PipedOutputStream out, int pipeSize)
+ throws IOException {
+ this(pipeSize);
+ connect(out);
+ }
+
+ /**
+ * Constructs a new unconnected PipedInputStream and uses the specified
+ * buffer size. The resulting Stream must be connected to a
+ * PipedOutputStream before data may be read from it.
+ *
+ * @param pipeSize
+ * the size of the buffer.
+ * @throws IllegalArgumentException
+ * if pipeSize is less than or equal to zero.
+ * @since 1.6
+ */
+ public PipedInputStream(int pipeSize) {
+ if (pipeSize <= 0) {
+ throw new IllegalArgumentException();
+ }
+ buffer = new byte[pipeSize];
+ }
/**
* Answers a int representing the number of bytes that are available before
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/io/PipedOutputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/io/PipedOutputStream.java?view=diff&rev=545077&r1=545076&r2=545077
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/io/PipedOutputStream.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/io/PipedOutputStream.java Wed Jun 6 23:03:25 2007
@@ -96,7 +96,9 @@
if (stream.isConnected) {
throw new IOException(Msg.getString("K007a")); //$NON-NLS-1$
}
- stream.buffer = new byte[PipedInputStream.PIPE_SIZE];
+ if (stream.buffer == null) {
+ stream.buffer = new byte[PipedInputStream.PIPE_SIZE];
+ }
stream.isConnected = true;
this.dest = stream;
}
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/tests/api/java/io/PipedInputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/tests/api/java/io/PipedInputStreamTest.java?view=diff&rev=545077&r1=545076&r2=545077
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/tests/api/java/io/PipedInputStreamTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/java/tests/api/java/io/PipedInputStreamTest.java Wed Jun 6 23:03:25 2007
@@ -46,6 +46,22 @@
bytes[i] = (byte) (System.currentTimeMillis() % 9);
}
}
+
+ static class MockPipedInputStream extends PipedInputStream {
+
+ public MockPipedInputStream(java.io.PipedOutputStream src,
+ int bufferSize) throws IOException {
+ super(src, bufferSize);
+ }
+
+ public MockPipedInputStream(int bufferSize) {
+ super(bufferSize);
+ }
+
+ public int bufferLength() {
+ return super.buffer.length;
+ }
+ }
Thread t;
@@ -71,6 +87,60 @@
pis = new PipedInputStream(new PipedOutputStream());
pis.available();
}
+
+ /**
+ * @tests java.io.PipedInputStream#PipedInputStream(java.io.PipedOutputStream,
+ * int)
+ * @since 1.6
+ */
+ public void test_Constructor_LPipedOutputStream_I() throws Exception {
+ // Test for method java.io.PipedInputStream(java.io.PipedOutputStream,
+ // int)
+ MockPipedInputStream mpis = new MockPipedInputStream(
+ new PipedOutputStream(), 100);
+ int bufferLength = mpis.bufferLength();
+ assertEquals(100, bufferLength);
+
+ try {
+ pis = new PipedInputStream(null, -1);
+ fail("Should throw IllegalArgumentException"); //$NON-NLS-1$
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ try {
+ pis = new PipedInputStream(null, 0);
+ fail("Should throw IllegalArgumentException"); //$NON-NLS-1$
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ /**
+ * @tests java.io.PipedInputStream#PipedInputStream(int)
+ * @since 1.6
+ */
+ public void test_Constructor_I() throws Exception {
+ // Test for method java.io.PipedInputStream(int)
+ MockPipedInputStream mpis = new MockPipedInputStream(100);
+ int bufferLength = mpis.bufferLength();
+ assertEquals(100, bufferLength);
+
+ try {
+ pis = new PipedInputStream(-1);
+ fail("Should throw IllegalArgumentException"); //$NON-NLS-1$
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ try {
+ pis = new PipedInputStream(0);
+ fail("Should throw IllegalArgumentException"); //$NON-NLS-1$
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
/**
* @tests java.io.PipedInputStream#available()