You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@harmony.apache.org by Richard Liang <ri...@gmail.com> on 2006/08/17 04:16:26 UTC
[classlib][luni] Compatibility: Default buf size of BufferedOutputStream
Hello All,
One test case tests.api.java.io.BufferedOutputStreamTest.test_write$BII
fails on RI (passes on Harmony) because the default buf size between RI
and Harmony are different. The default buf size is not specified in the
Java Specification. If we can detect what the default buf size of RI is
by some test cases, shall we use the same default buf size as RI? Any
comments? Thanks a lot.
public void test_write$BII() {
// Test for method void java.io.BufferedOutputStream.write(byte
[], int,
// int)
try {
os = new java.io.BufferedOutputStream(
baos = new java.io.ByteArrayOutputStream());
os.write(fileString.getBytes(), 0, 500);
bais = new java.io.ByteArrayInputStream(baos.toByteArray());
assertEquals("Bytes written, not buffered", 0,
bais.available());
os.flush();
bais = new java.io.ByteArrayInputStream(baos.toByteArray());
assertEquals("Bytes not written after flush", 500,
bais.available());
os.write(fileString.getBytes(), 500, 513);
bais = new java.io.ByteArrayInputStream(baos.toByteArray());
assertTrue("Bytes not written when buffer full",
bais.available() >= 1000);
byte[] wbytes = new byte[1013];
bais.read(wbytes, 0, 1013);
assertTrue("Incorrect bytes written",
fileString.substring(0, 1013)
.equals(new String(wbytes, 0, wbytes.length)));
} catch (java.io.IOException e) {
fail("Flush test failed");
}
}
--
Richard Liang
China Software Development Lab, IBM
---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org
Re: [classlib][luni] Compatibility: Default buf size of BufferedOutputStream
Posted by Richard Liang <ri...@gmail.com>.
Stepan Mishura wrote:
> On 8/17/06, Richard Liang wrote:
>
>> Hello All,
>>
>> One test case tests.api.java.io.BufferedOutputStreamTest.test_write$BII
>> fails on RI (passes on Harmony) because the default buf size between RI
>> and Harmony are different. The default buf size is not specified in the
>> Java Specification. If we can detect what the default buf size of RI is
>> by some test cases, shall we use the same default buf size as RI? Any
>> comments? Thanks a lot.
>
>
> At first glance, the test is wrong - it shouldn't rely on default buffer
> size and it should explicitly specify what the buffer size is by using:
> BufferedOutputStream(OutputStream out, int size)
> Parameters:
> out - the underlying output stream.
> size - the buffer size.
>
Yes, we can fix the test case this way. Here I just want to confirm that
"the default buf size" is implementation detail, we are free to be
different with RI.
I will raise a JIRA to fix this test.
Thanks a lot.
> Thanks,
> Stepan.
>
>
>> public void test_write$BII() {
>> // Test for method void java.io.BufferedOutputStream.write(byte
>> [], int,
>> // int)
>> try {
>> os = new java.io.BufferedOutputStream(
>> baos = new java.io.ByteArrayOutputStream());
>> os.write(fileString.getBytes(), 0, 500);
>> bais = new java.io.ByteArrayInputStream(baos.toByteArray());
>> assertEquals("Bytes written, not buffered", 0,
>> bais.available());
>> os.flush();
>> bais = new java.io.ByteArrayInputStream(baos.toByteArray());
>> assertEquals("Bytes not written after flush", 500,
>> bais.available());
>> os.write(fileString.getBytes(), 500, 513);
>> bais = new java.io.ByteArrayInputStream(baos.toByteArray());
>> assertTrue("Bytes not written when buffer full",
>> bais.available() >= 1000);
>> byte[] wbytes = new byte[1013];
>> bais.read(wbytes, 0, 1013);
>> assertTrue("Incorrect bytes written",
>> fileString.substring(0, 1013)
>> .equals(new String(wbytes, 0, wbytes.length)));
>> } catch (java.io.IOException e) {
>> fail("Flush test failed");
>> }
>>
>> }
>>
>> --
>> Richard Liang
>> China Software Development Lab, IBM
>>
>>
> ------------------------------------------------------
> Terms of use : http://incubator.apache.org/harmony/mailing.html
> To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> For additional commands, e-mail: harmony-dev-help@incubator.apache.org
>
--
Richard Liang
China Software Development Lab, IBM
---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org
Re: [classlib][luni] Compatibility: Default buf size of BufferedOutputStream
Posted by Stepan Mishura <st...@gmail.com>.
On 8/17/06, Richard Liang wrote:
> Hello All,
>
> One test case tests.api.java.io.BufferedOutputStreamTest.test_write$BII
> fails on RI (passes on Harmony) because the default buf size between RI
> and Harmony are different. The default buf size is not specified in the
> Java Specification. If we can detect what the default buf size of RI is
> by some test cases, shall we use the same default buf size as RI? Any
> comments? Thanks a lot.
At first glance, the test is wrong - it shouldn't rely on default buffer
size and it should explicitly specify what the buffer size is by using:
BufferedOutputStream(OutputStream out, int size)
Parameters:
out - the underlying output stream.
size - the buffer size.
Thanks,
Stepan.
> public void test_write$BII() {
> // Test for method void java.io.BufferedOutputStream.write(byte
> [], int,
> // int)
> try {
> os = new java.io.BufferedOutputStream(
> baos = new java.io.ByteArrayOutputStream());
> os.write(fileString.getBytes(), 0, 500);
> bais = new java.io.ByteArrayInputStream(baos.toByteArray());
> assertEquals("Bytes written, not buffered", 0,
> bais.available());
> os.flush();
> bais = new java.io.ByteArrayInputStream(baos.toByteArray());
> assertEquals("Bytes not written after flush", 500,
> bais.available());
> os.write(fileString.getBytes(), 500, 513);
> bais = new java.io.ByteArrayInputStream(baos.toByteArray());
> assertTrue("Bytes not written when buffer full",
> bais.available() >= 1000);
> byte[] wbytes = new byte[1013];
> bais.read(wbytes, 0, 1013);
> assertTrue("Incorrect bytes written",
> fileString.substring(0, 1013)
> .equals(new String(wbytes, 0, wbytes.length)));
> } catch (java.io.IOException e) {
> fail("Flush test failed");
> }
>
> }
>
> --
> Richard Liang
> China Software Development Lab, IBM
>
>
------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org
Re: [classlib][luni] Compatibility: Default buf size of BufferedOutputStream
Posted by Richard Liang <ri...@gmail.com>.
Vijay Yellapragada wrote:
> Hi,
>
> Buffer Size is definitely implementation dependent.
>
> The test should be re done so that it doesn't assume the size of the
> buffer.
>
Yes. Just thinking about if there are any user applications depending on
this behavior :-)
> A simple way to structure the test would be :-
>
> - Create a Sub class of BufferedOutputStream.
> - Since count and buf have protected access in BufferedOutputStream,
> subclassing will allow us to get access to those values.
>
> Once you have the sub class it is now straight forward to determine
> the default size of the buffer and the test becomes much simpler in
> fact...
>
> Hope that helps..
It really helps. Thanks a lot.
>
> Thanks,
> Vijay
>
> Andrew Zhang wrote:
>> I think it's implementation detail. Any default buffer size is
>> acceptable as
>> long as complying with spec.
>>
>> Of course, if Harmony's default size is equal with RI's by accident,
>> it's
>> good. :)
>>
>> So the problem is test, not implementation code. I suggest modify the
>> test
>> even if we "fix" our default size in the code.
>>
>> And if some applications are heaviliy dependent on the default size and
>> refuse to fix their code, I guess they won't become popular. :)
>> Applications
>> can take the advantage of the default size, but not to be dependent
>> on them.
>> :)
>>
>> On 8/17/06, Richard Liang <ri...@gmail.com> wrote:
>>>
>>> Hello All,
>>>
>>> One test case tests.api.java.io.BufferedOutputStreamTest.test_write$BII
>>> fails on RI (passes on Harmony) because the default buf size between RI
>>> and Harmony are different. The default buf size is not specified in the
>>> Java Specification. If we can detect what the default buf size of
>>> RI is
>>> by some test cases, shall we use the same default buf size as RI? Any
>>> comments? Thanks a lot.
>>>
>>> public void test_write$BII() {
>>> // Test for method void java.io.BufferedOutputStream.write(byte
>>> [], int,
>>> // int)
>>> try {
>>> os = new java.io.BufferedOutputStream(
>>> baos = new java.io.ByteArrayOutputStream());
>>> os.write(fileString.getBytes(), 0, 500);
>>> bais = new java.io.ByteArrayInputStream(baos.toByteArray());
>>> assertEquals("Bytes written, not buffered", 0,
>>> bais.available());
>>> os.flush();
>>> bais = new java.io.ByteArrayInputStream(baos.toByteArray());
>>> assertEquals("Bytes not written after flush", 500,
>>> bais.available());
>>> os.write(fileString.getBytes(), 500, 513);
>>> bais = new java.io.ByteArrayInputStream(baos.toByteArray());
>>> assertTrue("Bytes not written when buffer full",
>>> bais.available() >= 1000);
>>> byte[] wbytes = new byte[1013];
>>> bais.read(wbytes, 0, 1013);
>>> assertTrue("Incorrect bytes written",
>>> fileString.substring(0, 1013)
>>> .equals(new String(wbytes, 0, wbytes.length)));
>>> } catch (java.io.IOException e) {
>>> fail("Flush test failed");
>>> }
>>>
>>> }
>>>
>>> --
>>> Richard Liang
>>> China Software Development Lab, IBM
>
> ---------------------------------------------------------------------
> Terms of use : http://incubator.apache.org/harmony/mailing.html
> To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> For additional commands, e-mail: harmony-dev-help@incubator.apache.org
>
>
--
Richard Liang
China Software Development Lab, IBM
---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org
Re: [classlib][luni] Compatibility: Default buf size of BufferedOutputStream
Posted by Vijay Yellapragada <ye...@earthlink.net>.
Hi,
Buffer Size is definitely implementation dependent.
The test should be re done so that it doesn't assume the size of the buffer.
A simple way to structure the test would be :-
- Create a Sub class of BufferedOutputStream.
- Since count and buf have protected access in BufferedOutputStream,
subclassing will allow us to get access to those values.
Once you have the sub class it is now straight forward to determine the
default size of the buffer and the test becomes much simpler in fact...
Hope that helps..
Thanks,
Vijay
Andrew Zhang wrote:
> I think it's implementation detail. Any default buffer size is
> acceptable as
> long as complying with spec.
>
> Of course, if Harmony's default size is equal with RI's by accident,
> it's
> good. :)
>
> So the problem is test, not implementation code. I suggest modify the
> test
> even if we "fix" our default size in the code.
>
> And if some applications are heaviliy dependent on the default size and
> refuse to fix their code, I guess they won't become popular. :)
> Applications
> can take the advantage of the default size, but not to be dependent on
> them.
> :)
>
> On 8/17/06, Richard Liang <ri...@gmail.com> wrote:
>>
>> Hello All,
>>
>> One test case tests.api.java.io.BufferedOutputStreamTest.test_write$BII
>> fails on RI (passes on Harmony) because the default buf size between RI
>> and Harmony are different. The default buf size is not specified in the
>> Java Specification. If we can detect what the default buf size of RI is
>> by some test cases, shall we use the same default buf size as RI? Any
>> comments? Thanks a lot.
>>
>> public void test_write$BII() {
>> // Test for method void java.io.BufferedOutputStream.write(byte
>> [], int,
>> // int)
>> try {
>> os = new java.io.BufferedOutputStream(
>> baos = new java.io.ByteArrayOutputStream());
>> os.write(fileString.getBytes(), 0, 500);
>> bais = new java.io.ByteArrayInputStream(baos.toByteArray());
>> assertEquals("Bytes written, not buffered", 0,
>> bais.available());
>> os.flush();
>> bais = new java.io.ByteArrayInputStream(baos.toByteArray());
>> assertEquals("Bytes not written after flush", 500,
>> bais.available());
>> os.write(fileString.getBytes(), 500, 513);
>> bais = new java.io.ByteArrayInputStream(baos.toByteArray());
>> assertTrue("Bytes not written when buffer full",
>> bais.available() >= 1000);
>> byte[] wbytes = new byte[1013];
>> bais.read(wbytes, 0, 1013);
>> assertTrue("Incorrect bytes written",
>> fileString.substring(0, 1013)
>> .equals(new String(wbytes, 0, wbytes.length)));
>> } catch (java.io.IOException e) {
>> fail("Flush test failed");
>> }
>>
>> }
>>
>> --
>> Richard Liang
>> China Software Development Lab, IBM
---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org
Re: [classlib][luni] Compatibility: Default buf size of BufferedOutputStream
Posted by Andrew Zhang <zh...@gmail.com>.
I think it's implementation detail. Any default buffer size is acceptable as
long as complying with spec.
Of course, if Harmony's default size is equal with RI's by accident, it's
good. :)
So the problem is test, not implementation code. I suggest modify the test
even if we "fix" our default size in the code.
And if some applications are heaviliy dependent on the default size and
refuse to fix their code, I guess they won't become popular. :) Applications
can take the advantage of the default size, but not to be dependent on them.
:)
On 8/17/06, Richard Liang <ri...@gmail.com> wrote:
>
> Hello All,
>
> One test case tests.api.java.io.BufferedOutputStreamTest.test_write$BII
> fails on RI (passes on Harmony) because the default buf size between RI
> and Harmony are different. The default buf size is not specified in the
> Java Specification. If we can detect what the default buf size of RI is
> by some test cases, shall we use the same default buf size as RI? Any
> comments? Thanks a lot.
>
> public void test_write$BII() {
> // Test for method void java.io.BufferedOutputStream.write(byte
> [], int,
> // int)
> try {
> os = new java.io.BufferedOutputStream(
> baos = new java.io.ByteArrayOutputStream());
> os.write(fileString.getBytes(), 0, 500);
> bais = new java.io.ByteArrayInputStream(baos.toByteArray());
> assertEquals("Bytes written, not buffered", 0,
> bais.available());
> os.flush();
> bais = new java.io.ByteArrayInputStream(baos.toByteArray());
> assertEquals("Bytes not written after flush", 500,
> bais.available());
> os.write(fileString.getBytes(), 500, 513);
> bais = new java.io.ByteArrayInputStream(baos.toByteArray());
> assertTrue("Bytes not written when buffer full",
> bais.available() >= 1000);
> byte[] wbytes = new byte[1013];
> bais.read(wbytes, 0, 1013);
> assertTrue("Incorrect bytes written",
> fileString.substring(0, 1013)
> .equals(new String(wbytes, 0, wbytes.length)));
> } catch (java.io.IOException e) {
> fail("Flush test failed");
> }
>
> }
>
> --
> Richard Liang
> China Software Development Lab, IBM
>
>
>
> ---------------------------------------------------------------------
> Terms of use : http://incubator.apache.org/harmony/mailing.html
> To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> For additional commands, e-mail: harmony-dev-help@incubator.apache.org
>
>
--
Andrew Zhang
China Software Development Lab, IBM