Name: rm29839 Date: 02/17/98
I reported a bug with java.io.BufferInputStream
when it is used in conjunction with
java.io.DataInputStream. It was given the Bug Id
4109067. I now find that 4109067 has been closed
as being a duplicate of 4030995. 4030995 has in turn
been closed as being "not a bug".
Yet, as demonstrated by the code attached to
4109067, BufferInputStream DOES NOT WORK when
used in conjunction with DataInputStream
(as confirmed by your own reviewer on 02/03/98)!
Who are you kidding? Nothing in the specification or any JDK doco
says that BufferedInputStream should not be used
in conjunction with DataInputStream!
If you persist in not treating this problem as a
bug could please treat it as a "Feature Request".
How can Java be taken seriously if there isn't a
class that can reliably read non-text data using
buffering?
//////////////////////////////////////////////////////////////////
// This class demonstrates a bug in BufferedInputStream. If the //
// DataInputStream (dIn)is created using a FileInputStream then no //
// errors are detected. If it is created with a //
// BufferedInputStream then errors are detected. //
//////////////////////////////////////////////////////////////////
import java.io.*;
class BufferedInputTest {
static String TEST_FILE = "testFile";
static int REPETITIONS = 395;
static byte testByte = 'X';
static byte[] testByteArray = {'A','B','C','D','E','F'};
static short testShort = 1;
static int testInt = 2;
static long testLong = 3L;
public static void main(String[] args) {
DataOutputStream dOut = null;
DataInputStream dIn = null;
//1st create a test file...
try {
dOut = new DataOutputStream(new FileOutputStream(TEST_FILE));
for (int i=0; i < REPETITIONS; i++) {
dOut.write(testByte);
dOut.write(testByteArray,0,testByteArray.length);
dOut.writeShort(testShort);
dOut.writeInt(testInt);
dOut.writeLong(testLong);
}
//dIn = new DataInputStream(new FileInputStream(TEST_FILE));
dIn = new DataInputStream(new BufferedInputStream(new FileInputStream(TEST_FILE)));
System.out.println(dIn.available() + " bytes in file");
//Now read the test file and test it's correctness...
for (int i=0; i < REPETITIONS; i++) {
byte[] buf = new byte[testByteArray.length];
byte readByte = dIn.readByte();
if (readByte != testByte) {
System.out.println("byte different at " + i + " " + readByte);
}
dIn.read(buf);
for (int j=0; j < buf.length; j++) {
if (buf[j] != testByteArray[j]) {
System.out.println("byte array different at " + i);
for (int k=0; k < buf.length; k++) {
System.out.print((char)(buf[k]));
}
System.out.println("\n");
break;
}
}
short readShort = dIn.readShort();
if (readShort != testShort) {
System.out.println("testShort different at " + i + " " + readShort);
}
int readInt = dIn.readInt();
if (readInt != testInt) {
System.out.println("testInt different at " + i + " " + readInt);
}
long readLong = dIn.readLong();
if (readLong != testLong) {
System.out.println("testLong different at " + i + " " + readLong);
}
}
}
catch(IOException e) {
System.out.println(e);
}
finally {
if (dOut != null) {
try {dOut.close();} catch(IOException e) {};
}
if (dIn != null) {
try {dIn.close();} catch(IOException e) {};
}
}
}
}
(Review ID: 24959)
======================================================================