< prev index next >

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

Print this page

        

*** 1292,1302 **** * @return a {@code BufferedImage} containing the decoded * contents of the input, or {@code null}. * * @exception IllegalArgumentException if {@code input} is * {@code null}. ! * @exception IOException if an error occurs during reading. */ public static BufferedImage read(File input) throws IOException { if (input == null) { throw new IllegalArgumentException("input == null!"); } --- 1292,1303 ---- * @return a {@code BufferedImage} containing the decoded * contents of the input, or {@code null}. * * @exception IllegalArgumentException if {@code input} is * {@code null}. ! * @exception IOException if an error occurs during reading or when not ! * able to create required ImageInputStream. */ public static BufferedImage read(File input) throws IOException { if (input == null) { throw new IllegalArgumentException("input == null!"); }
*** 1342,1359 **** * @return a {@code BufferedImage} containing the decoded * contents of the input, or {@code null}. * * @exception IllegalArgumentException if {@code input} is * {@code null}. ! * @exception IOException if an error occurs during reading. */ public static BufferedImage read(InputStream input) throws IOException { if (input == null) { throw new IllegalArgumentException("input == null!"); } ImageInputStream stream = createImageInputStream(input); BufferedImage bi = read(stream); if (bi == null) { stream.close(); } return bi; --- 1343,1364 ---- * @return a {@code BufferedImage} containing the decoded * contents of the input, or {@code null}. * * @exception IllegalArgumentException if {@code input} is * {@code null}. ! * @exception IOException if an error occurs during reading or when not ! * able to create required ImageInputStream. */ public static BufferedImage read(InputStream input) throws IOException { if (input == null) { throw new IllegalArgumentException("input == null!"); } 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;
*** 1382,1392 **** * @return a {@code BufferedImage} containing the decoded * contents of the input, or {@code null}. * * @exception IllegalArgumentException if {@code input} is * {@code null}. ! * @exception IOException if an error occurs during reading. */ public static BufferedImage read(URL input) throws IOException { if (input == null) { throw new IllegalArgumentException("input == null!"); } --- 1387,1398 ---- * @return a {@code BufferedImage} containing the decoded * contents of the input, or {@code null}. * * @exception IllegalArgumentException if {@code input} is * {@code null}. ! * @exception IOException if an error occurs during reading or when not ! * able to create required ImageInputStream. */ public static BufferedImage read(URL input) throws IOException { if (input == null) { throw new IllegalArgumentException("input == null!"); }
*** 1396,1405 **** --- 1402,1419 ---- istream = input.openStream(); } catch (IOException e) { throw new IIOException("Can't get input stream from URL!", e); } ImageInputStream stream = createImageInputStream(istream); + if (stream == null) { + /* close the istream when stream is null so that if user has + * given filepath as URL he can delete it, otherwise stream will + * be open to that file and he will not be able to delete it. + */ + istream.close(); + throw new IIOException("Can't create an ImageInputStream!"); + } BufferedImage bi; try { bi = read(stream); if (bi == null) { stream.close();
*** 1508,1518 **** * * @return {@code false} if no appropriate writer is found. * * @exception IllegalArgumentException if any parameter is * {@code null}. ! * @exception IOException if an error occurs during writing. */ public static boolean write(RenderedImage im, String formatName, File output) throws IOException { if (output == null) { --- 1522,1533 ---- * * @return {@code false} if no appropriate writer is found. * * @exception IllegalArgumentException if any parameter is * {@code null}. ! * @exception IOException if an error occurs during writing or when not ! * able to create required ImageOutputStream. */ public static boolean write(RenderedImage im, String formatName, File output) throws IOException { if (output == null) {
*** 1530,1542 **** try { output.delete(); stream = createImageOutputStream(output); } catch (IOException e) { ! throw new IIOException("Can't create output stream!", e); } - try { return doWrite(im, writer, stream); } finally { stream.close(); } --- 1545,1559 ---- try { output.delete(); stream = createImageOutputStream(output); } catch (IOException e) { ! throw e; ! } ! if (stream == null) { ! throw new IIOException("Can't create an ImageOutputStream!"); } try { return doWrite(im, writer, stream); } finally { stream.close(); }
*** 1560,1570 **** * * @return {@code false} if no appropriate writer is found. * * @exception IllegalArgumentException if any parameter is * {@code null}. ! * @exception IOException if an error occurs during writing. */ public static boolean write(RenderedImage im, String formatName, OutputStream output) throws IOException { if (output == null) { --- 1577,1588 ---- * * @return {@code false} if no appropriate writer is found. * * @exception IllegalArgumentException if any parameter is * {@code null}. ! * @exception IOException if an error occurs during writing or when not ! * able to create required ImageOutputStream. */ public static boolean write(RenderedImage im, String formatName, OutputStream output) throws IOException { if (output == null) {
*** 1572,1584 **** } ImageOutputStream stream = null; try { stream = createImageOutputStream(output); } catch (IOException e) { ! throw new IIOException("Can't create output stream!", e); } - try { return doWrite(im, getWriter(im, formatName), stream); } finally { stream.close(); } --- 1590,1604 ---- } ImageOutputStream stream = null; try { stream = createImageOutputStream(output); } catch (IOException e) { ! throw e; ! } ! if (stream == null) { ! throw new IIOException("Can't create an ImageOutputStream!"); } try { return doWrite(im, getWriter(im, formatName), stream); } finally { stream.close(); }
< prev index next >