8299025: BMPImageReader.java readColorPalette could use staggeredReadByteStream

Reviewed-by: clanger
This commit is contained in:
Matthias Baesken 2022-12-21 08:05:37 +00:00
parent f56285c361
commit f36e144923

@ -226,30 +226,7 @@ public class BMPImageReader extends ImageReader implements BMPConstants {
}
private void readColorPalette(int sizeOfPalette) throws IOException {
final int UNIT_SIZE = 1024000;
if (sizeOfPalette < UNIT_SIZE) {
palette = new byte[sizeOfPalette];
iis.readFully(palette, 0, sizeOfPalette);
} else {
int bytesToRead = sizeOfPalette;
int bytesRead = 0;
List<byte[]> bufs = new ArrayList<>();
while (bytesToRead != 0) {
int sz = Math.min(bytesToRead, UNIT_SIZE);
byte[] unit = new byte[sz];
iis.readFully(unit, 0, sz);
bufs.add(unit);
bytesRead += sz;
bytesToRead -= sz;
}
byte[] paletteData = new byte[bytesRead];
int copiedBytes = 0;
for (byte[] ba : bufs) {
System.arraycopy(ba, 0, paletteData, copiedBytes, ba.length);
copiedBytes += ba.length;
}
palette = paletteData;
}
palette = ReaderUtil.staggeredReadByteStream(iis, sizeOfPalette);
}
/**