< 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,1542 ****
*
* @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) {
throw new IllegalArgumentException("output == null!");
}
- ImageOutputStream stream = null;
ImageWriter writer = getWriter(im, formatName);
if (writer == null) {
/* Do not make changes in the file system if we have
* no appropriate writer.
*/
return false;
}
- 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();
}
--- 1522,1554 ----
*
* @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) {
throw new IllegalArgumentException("output == null!");
}
ImageWriter writer = getWriter(im, formatName);
if (writer == null) {
/* Do not make changes in the file system if we have
* no appropriate writer.
*/
return false;
}
output.delete();
! ImageOutputStream stream = createImageOutputStream(output);
! if (stream == null) {
! throw new IIOException("Can't create an ImageOutputStream!");
}
try {
return doWrite(im, writer, stream);
} finally {
stream.close();
}
*** 1560,1584 ****
*
* @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) {
throw new IllegalArgumentException("output == null!");
}
! 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();
}
--- 1572,1594 ----
*
* @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) {
throw new IllegalArgumentException("output == null!");
}
! ImageOutputStream stream = createImageOutputStream(output);
! 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 >