I have the following class subclass of FilterInputStream with only one method overrided. However the performance of this class is so poor. It performs at 1/10 the speed of its superclass. I even took the same source code from InputStream of javasrc and used it in my subclass. Same performance hit. Is there something wrong with overriding classes?
public class NewLineStream extends FilterInputStream {
public NewLineStream(InputStream in) {
super(in);
}
public int read(byte[] b, int off, int len) throws IOException {
if (b == null) {
throw new NullPointerException ();
} else if ((off < 0) || (off > b.length) || (len < 0) ||
((off + len) > b.length) || ((off + len) < 0)) {
throw new IndexOutOfBoundsException ();
} else if (len == 0) {
return 0;
}
int c = read();
if (c == -1) {
return -1;
}
b[off] = (byte)c;
int i = 1;
try {
for (; i < len ; i++) {
c = read();
if (c == -1) {
break;
}
if (b != null) {
b[off + i] = (byte)c;
}
}
} catch (IOException ee) {
}
return i;
}
}