mirror of
https://github.com/moparisthebest/davmail
synced 2025-01-10 05:08:08 -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 contactPictureUrl = URIUtil.encodePath(getHref() + "/ContactPicture.jpg");
|
||||||
String photo = get("photo");
|
String photo = get("photo");
|
||||||
if (photo != null) {
|
if (photo != null) {
|
||||||
// need to update photo
|
|
||||||
byte[] resizedImageBytes = IOUtil.resizeImage(IOUtil.decodeBase64(photo), 90);
|
|
||||||
|
|
||||||
final PutMethod putmethod = new PutMethod(contactPictureUrl);
|
final PutMethod putmethod = new PutMethod(contactPictureUrl);
|
||||||
putmethod.setRequestHeader("Overwrite", "t");
|
|
||||||
putmethod.setRequestHeader("Content-Type", "image/jpeg");
|
|
||||||
putmethod.setRequestEntity(new ByteArrayRequestEntity(resizedImageBytes, "image/jpeg"));
|
|
||||||
try {
|
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);
|
status = httpClient.executeMethod(putmethod);
|
||||||
if (status != HttpStatus.SC_OK && status != HttpStatus.SC_CREATED) {
|
if (status != HttpStatus.SC_OK && status != HttpStatus.SC_CREATED) {
|
||||||
throw new IOException("Unable to update contact picture: " + status + ' ' + putmethod.getStatusLine());
|
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 {
|
public static byte[] resizeImage(byte[] inputBytes, int max) throws IOException {
|
||||||
BufferedImage inputImage = ImageIO.read(new ByteArrayInputStream(inputBytes));
|
BufferedImage inputImage = ImageIO.read(new ByteArrayInputStream(inputBytes));
|
||||||
|
if (inputImage == null) {
|
||||||
|
throw new IOException("Unable to decode image data");
|
||||||
|
}
|
||||||
BufferedImage outputImage = resizeImage(inputImage, max);
|
BufferedImage outputImage = resizeImage(inputImage, max);
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
ImageIO.write(outputImage, "jpg", baos);
|
ImageIO.write(outputImage, "jpg", baos);
|
||||||
|
Loading…
Reference in New Issue
Block a user