while ((bytesRead = getInputStream().read(readBuf)) != -1) {
baos.write(readBuf, 0, bytesRead);
}
} catch (final IOException ex) {
this.setValid(false);
throw new GraphicException("Error loading image:\n " +
getUrl().toString()
+ "\n " + ex.getClass() + " - " + ex.getMessage());
}
final byte[] contentBytes = baos.toByteArray();
/* The image size is normally computed in parseBasics(), which instead
* here calls this method, loadImage().
* See parseBasics() for a comment explaining why. */
findImageSize(contentBytes);
setBitDepth(WKConstants.BITS_PER_BYTE);
if (contentBytes.length > (index + 2) &&
contentBytes[index] == JPEGGraphic.MARK &&
contentBytes[index + 1] == JPEGGraphic.SOI) {
processRemainder(contentBytes, iccStream, index);
} else {
this.setValid(false);
throw new GraphicException("Error loading image:\n "
+ getUrl().toString()
+ "\n JpegImage - Invalid JPEG Header.");
}
if (iccStream.size() > 0) {
final byte[] align = new byte[((iccStream.size())
% WKConstants.BITS_PER_BYTE) + WKConstants.BITS_PER_BYTE];
try {
iccStream.write(align);
} catch (final IOException e) {
throw new GraphicException("\n1 Error while loading image " +
getUrl().toString() + " : " + e.getMessage());
}
final ICC_Profile icc = ICC_Profile.getInstance(
iccStream.toByteArray());
this.colorSpace = new ICC_ColorSpace(icc);