Prevent NullPinterException. Thank's to Felix!

This commit is contained in:
trifonnt 2009-09-24 13:50:28 +00:00
parent 4170996e85
commit bd1ac8583a
1 changed files with 18 additions and 16 deletions

View File

@ -89,22 +89,24 @@ public class MediaBroadcast extends HttpServletCM
} else { } else {
response.setContentType(thisMedia.getMediaType()); response.setContentType(thisMedia.getMediaType());
// Binary / Image content will get handled here // Binary / Image content will get handled here
MImage thisImage = thisMedia.getImage(); MImage thisImage = thisMedia.getImage();
response.setContentLength(thisImage.getData().length); if (thisImage != null) {
response.setContentLength(thisImage.getData().length);
// Open the file and output streams
byte[] buffer = thisImage.getData(); // Open the file and output streams
ByteArrayInputStream in = new ByteArrayInputStream(buffer); byte[] buffer = thisImage.getData();
OutputStream out = response.getOutputStream(); ByteArrayInputStream in = new ByteArrayInputStream(buffer);
OutputStream out = response.getOutputStream();
// Copy the contents of the file to the output stream
byte[] buf = new byte[1024]; // Copy the contents of the file to the output stream
int count = 0; byte[] buf = new byte[1024];
while ((count = in.read(buf)) >= 0) { int count = 0;
out.write(buf, 0, count); while ((count = in.read(buf)) >= 0) {
} out.write(buf, 0, count);
in.close(); }
out.close(); in.close();
out.close();
}
} }
} else { } else {
response.sendError(404); response.sendError(404);