-
Bug
-
Resolution: Duplicate
-
P4
-
1.4.0, 5.0
-
None
-
generic
-
generic
I noticed while working on
4986239: DeflaterOutputStream is memory inefficient
that this code
private byte[] deflate(String s) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DeflaterOutputStream dos = new DeflaterOutputStream(baos);
int len = s.length();
for (int i = 0; i < len; i++) {
dos.write((int)s.charAt(i));
}
dos.close();
return baos.toByteArray();
}
might be quite inefficient (in analagous code, I measured a 20-fold speedup).
It is likely that passing the data as a
block would be an order of magnitude more efficient.
In Java, it is the user's responsibility to buffer data when writing to
an expensive stream like FileOutputStream or DeflaterOutputStream.
Either a block could be writting at a time, or the DeflaterOutputStream
could be wrapped with a BufferedOutputStream.
I haven't tested the suggested fix; I don't know how to use these classes.
###@###.### 2004-02-01
4986239: DeflaterOutputStream is memory inefficient
that this code
private byte[] deflate(String s) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DeflaterOutputStream dos = new DeflaterOutputStream(baos);
int len = s.length();
for (int i = 0; i < len; i++) {
dos.write((int)s.charAt(i));
}
dos.close();
return baos.toByteArray();
}
might be quite inefficient (in analagous code, I measured a 20-fold speedup).
It is likely that passing the data as a
block would be an order of magnitude more efficient.
In Java, it is the user's responsibility to buffer data when writing to
an expensive stream like FileOutputStream or DeflaterOutputStream.
Either a block could be writting at a time, or the DeflaterOutputStream
could be wrapped with a BufferedOutputStream.
I haven't tested the suggested fix; I don't know how to use these classes.
###@###.### 2004-02-01
- duplicates
-
JDK-6782079 PNG: reading metadata may cause OOM on truncated images.
-
- Closed
-