< prev index next >

src/java.desktop/share/classes/javax/imageio/ImageIO.java

Print this page

        

*** 1288,1298 **** * <code>IIORegistry</code> and <code>ImageReaderSpi</code>. * * @param input a <code>File</code> to read from. * * @return a <code>BufferedImage</code> containing the decoded ! * contents of the input, or <code>null</code>. * * @exception IllegalArgumentException if <code>input</code> is * <code>null</code>. * @exception IOException if an error occurs during reading. */ --- 1288,1299 ---- * <code>IIORegistry</code> and <code>ImageReaderSpi</code>. * * @param input a <code>File</code> to read from. * * @return a <code>BufferedImage</code> containing the decoded ! * contents of the input, or <code>null</code> when we are not ! * able to decode the input or cannot create required ImageInputStream. * * @exception IllegalArgumentException if <code>input</code> is * <code>null</code>. * @exception IOException if an error occurs during reading. */
*** 1303,1315 **** if (!input.canRead()) { throw new IIOException("Can't read input file!"); } ImageInputStream stream = createImageInputStream(input); ! if (stream == null) { ! throw new IIOException("Can't create an ImageInputStream!"); ! } BufferedImage bi = read(stream); if (bi == null) { stream.close(); } return bi; --- 1304,1315 ---- if (!input.canRead()) { throw new IIOException("Can't read input file!"); } ImageInputStream stream = createImageInputStream(input); ! if (stream == null) ! return null; BufferedImage bi = read(stream); if (bi == null) { stream.close(); } return bi;
*** 1338,1348 **** * it is the responsibility of the caller to close the stream, if desired. * * @param input an <code>InputStream</code> to read from. * * @return a <code>BufferedImage</code> containing the decoded ! * contents of the input, or <code>null</code>. * * @exception IllegalArgumentException if <code>input</code> is * <code>null</code>. * @exception IOException if an error occurs during reading. */ --- 1338,1349 ---- * it is the responsibility of the caller to close the stream, if desired. * * @param input an <code>InputStream</code> to read from. * * @return a <code>BufferedImage</code> containing the decoded ! * contents of the input, or <code>null</code> when we are not ! * able to decode the input or cannot create required ImageInputStream. * * @exception IllegalArgumentException if <code>input</code> is * <code>null</code>. * @exception IOException if an error occurs during reading. */
*** 1350,1359 **** --- 1351,1362 ---- if (input == null) { throw new IllegalArgumentException("input == null!"); } ImageInputStream stream = createImageInputStream(input); + if (stream == null) + return null; BufferedImage bi = read(stream); if (bi == null) { stream.close(); } return bi;
*** 1378,1388 **** * <code>IIORegistry</code> and <code>ImageReaderSpi</code>. * * @param input a <code>URL</code> to read from. * * @return a <code>BufferedImage</code> containing the decoded ! * contents of the input, or <code>null</code>. * * @exception IllegalArgumentException if <code>input</code> is * <code>null</code>. * @exception IOException if an error occurs during reading. */ --- 1381,1392 ---- * <code>IIORegistry</code> and <code>ImageReaderSpi</code>. * * @param input a <code>URL</code> to read from. * * @return a <code>BufferedImage</code> containing the decoded ! * contents of the input, or <code>null</code> when we are not ! * able to decode the input or cannot create required ImageInputStream. * * @exception IllegalArgumentException if <code>input</code> is * <code>null</code>. * @exception IOException if an error occurs during reading. */
*** 1396,1405 **** --- 1400,1418 ---- istream = input.openStream(); } catch (IOException e) { throw new IIOException("Can't get input stream from URL!", e); } ImageInputStream stream = createImageInputStream(istream); + if (stream == null) { + /* We have to close istream when we are not able to create + * ImageInputStream otherwise it will cause memory leak, also if + * user has referenced the URL from a File then user will not be + * able to delete it as it will be alive with istream reference. + */ + istream.close(); + return null; + } BufferedImage bi; try { bi = read(stream); if (bi == null) { stream.close();
*** 1504,1514 **** * @param im a <code>RenderedImage</code> to be written. * @param formatName a <code>String</code> containing the informal * name of the format. * @param output a <code>File</code> to be written to. * ! * @return <code>false</code> if no appropriate writer is found. * * @exception IllegalArgumentException if any parameter is * <code>null</code>. * @exception IOException if an error occurs during writing. */ --- 1517,1528 ---- * @param im a <code>RenderedImage</code> to be written. * @param formatName a <code>String</code> containing the informal * name of the format. * @param output a <code>File</code> to be written to. * ! * @return <code>false</code> if no appropriate writer is found or ! * not able to create required ImageOutputStream. * * @exception IllegalArgumentException if any parameter is * <code>null</code>. * @exception IOException if an error occurs during writing. */
*** 1536,1545 **** --- 1550,1560 ---- } try { return doWrite(im, writer, stream); } finally { + if (stream != null) stream.close(); } } /**
*** 1556,1566 **** * @param im a <code>RenderedImage</code> to be written. * @param formatName a <code>String</code> containing the informal * name of the format. * @param output an <code>OutputStream</code> to be written to. * ! * @return <code>false</code> if no appropriate writer is found. * * @exception IllegalArgumentException if any parameter is * <code>null</code>. * @exception IOException if an error occurs during writing. */ --- 1571,1582 ---- * @param im a <code>RenderedImage</code> to be written. * @param formatName a <code>String</code> containing the informal * name of the format. * @param output an <code>OutputStream</code> to be written to. * ! * @return <code>false</code> if no appropriate writer is found or ! * not able to create required ImageOutputStream. * * @exception IllegalArgumentException if any parameter is * <code>null</code>. * @exception IOException if an error occurs during writing. */
*** 1578,1587 **** --- 1594,1604 ---- } try { return doWrite(im, getWriter(im, formatName), stream); } finally { + if (stream != null) stream.close(); } } /**
*** 1608,1617 **** --- 1625,1637 ---- private static boolean doWrite(RenderedImage im, ImageWriter writer, ImageOutputStream output) throws IOException { if (writer == null) { return false; } + if (output == null) { + return false; + } writer.setOutput(output); try { writer.write(im); } finally { writer.dispose();
< prev index next >