mirror of
https://github.com/moparisthebest/davmail
synced 2025-01-09 20:58:05 -05:00
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:
parent
ba7e4cc65b
commit
31f61af71b
@ -1237,14 +1237,15 @@ public class DavExchangeSession extends ExchangeSession {
|
||||
String contactPictureUrl = URIUtil.encodePath(getHref() + "/ContactPicture.jpg");
|
||||
String photo = get("photo");
|
||||
if (photo != null) {
|
||||
// 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 {
|
||||
// need to update photo
|
||||
byte[] resizedImageBytes = IOUtil.resizeImage(IOUtil.decodeBase64(photo), 90);
|
||||
|
||||
putmethod.setRequestHeader("Overwrite", "t");
|
||||
putmethod.setRequestHeader("Content-Type", "image/jpeg");
|
||||
putmethod.setRequestEntity(new ByteArrayRequestEntity(resizedImageBytes, "image/jpeg"));
|
||||
|
||||
status = httpClient.executeMethod(putmethod);
|
||||
if (status != HttpStatus.SC_OK && status != HttpStatus.SC_CREATED) {
|
||||
throw new IOException("Unable to update contact picture: " + status + ' ' + putmethod.getStatusLine());
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user