< prev index next >
test/javax/imageio/plugins/shared/CanWriteSequence.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
--- 1,7 ----
/*
! * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*** 21,30 ****
--- 21,31 ----
* questions.
*/
import java.io.File;
import java.io.FileOutputStream;
+ import java.nio.file.Files;
import java.util.Iterator;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriter;
import javax.imageio.metadata.IIOMetadata;
*** 32,46 ****
import javax.imageio.spi.ImageWriterSpi;
import javax.imageio.stream.ImageOutputStream;
/**
* @test
! * @bug 4958064
! * @author Sergey Bylokhov
*/
public final class CanWriteSequence {
public static void main(final String[] args) throws Exception {
final IIORegistry registry = IIORegistry.getDefaultInstance();
final Iterator<ImageWriterSpi> iter =
registry.getServiceProviders(ImageWriterSpi.class,
provider -> true, true);
--- 33,54 ----
import javax.imageio.spi.ImageWriterSpi;
import javax.imageio.stream.ImageOutputStream;
/**
* @test
! * @bug 4958064 8183349
! * @summary Test verifies that when we try to forcefully run
! * prepareWriteSequence() where it is not supported
! * will ImageIO throws an UnsupportedOperationException
! * or not.
! * @run main CanWriteSequence
*/
public final class CanWriteSequence {
+ private static File file;
+ private static FileOutputStream fos;
+
public static void main(final String[] args) throws Exception {
final IIORegistry registry = IIORegistry.getDefaultInstance();
final Iterator<ImageWriterSpi> iter =
registry.getServiceProviders(ImageWriterSpi.class,
provider -> true, true);
*** 52,64 ****
}
System.out.println("Test passed");
}
private static void test(final ImageWriter writer) throws Exception {
! final File file = File.createTempFile("temp", ".img");
! file.deleteOnExit();
! final FileOutputStream fos = new FileOutputStream(file);
final ImageOutputStream ios = ImageIO.createImageOutputStream(fos);
writer.setOutput(ios);
final IIOMetadata data = writer.getDefaultStreamMetadata(null);
if (writer.canWriteSequence()) {
--- 60,72 ----
}
System.out.println("Test passed");
}
private static void test(final ImageWriter writer) throws Exception {
! try {
! file = File.createTempFile("temp", ".img");
! fos = new FileOutputStream(file);
final ImageOutputStream ios = ImageIO.createImageOutputStream(fos);
writer.setOutput(ios);
final IIOMetadata data = writer.getDefaultStreamMetadata(null);
if (writer.canWriteSequence()) {
*** 70,78 ****
"UnsupportedOperationException was not thrown");
} catch (final UnsupportedOperationException ignored) {
// expected
}
}
writer.dispose();
! ios.close();
}
}
--- 78,90 ----
"UnsupportedOperationException was not thrown");
} catch (final UnsupportedOperationException ignored) {
// expected
}
}
+ } finally {
writer.dispose();
! fos.close();
! Files.delete(file.toPath());
! }
}
}
+
< prev index next >