From coverity: ImageIO.read may return null

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@2260 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2014-03-17 23:11:30 +00:00
parent ba7e4cc65b
commit 31f61af71b
2 changed files with 10 additions and 6 deletions

View File

@ -1237,14 +1237,15 @@ public class DavExchangeSession extends ExchangeSession {
String contactPictureUrl = URIUtil.encodePath(getHref() + "/ContactPicture.jpg");
String photo = get("photo");
if (photo != null) {
final PutMethod putmethod = new PutMethod(contactPictureUrl);
try {
// need to update photo
byte[] resizedImageBytes = IOUtil.resizeImage(IOUtil.decodeBase64(photo), 90);
final PutMethod putmethod = new PutMethod(contactPictureUrl);
putmethod.setRequestHeader("Overwrite", "t");
putmethod.setRequestHeader("Content-Type", "image/jpeg");
putmethod.setRequestEntity(new ByteArrayRequestEntity(resizedImageBytes, "image/jpeg"));
try {
status = httpClient.executeMethod(putmethod);
if (status != HttpStatus.SC_OK && status != HttpStatus.SC_CREATED) {
throw new IOException("Unable to update contact picture: " + status + ' ' + putmethod.getStatusLine());

View File

@ -124,6 +124,9 @@ public final class IOUtil {
*/
public static byte[] resizeImage(byte[] inputBytes, int max) throws IOException {
BufferedImage inputImage = ImageIO.read(new ByteArrayInputStream(inputBytes));
if (inputImage == null) {
throw new IOException("Unable to decode image data");
}
BufferedImage outputImage = resizeImage(inputImage, max);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(outputImage, "jpg", baos);