Path: blob/master/test/jdk/javax/imageio/plugins/gif/WriterResetTest.java
41155 views
/*1* Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 627525126* @summary Verifies that GIF image writer throws IllegalStateException if27* assigned output stream was cleared by reset() method28*/2930import java.awt.Color;31import java.awt.Graphics2D;32import java.awt.image.BufferedImage;33import java.io.ByteArrayOutputStream;34import java.io.IOException;3536import javax.imageio.ImageIO;37import javax.imageio.ImageWriter;38import javax.imageio.stream.ImageOutputStream;3940public class WriterResetTest {41public static void main(String[] args) throws IOException {42ImageWriter w = ImageIO.getImageWritersByFormatName("GIF").next();43if (w == null) {44throw new RuntimeException("No writers available!");45}4647ByteArrayOutputStream baos =48new ByteArrayOutputStream();4950ImageOutputStream ios =51ImageIO.createImageOutputStream(baos);5253w.setOutput(ios);5455BufferedImage img = createTestImage();5657try {58w.reset();59w.write(img);60} catch (IllegalStateException e) {61System.out.println("Test passed");62} catch (Throwable e) {63throw new RuntimeException("Test failed", e);64}65}6667private static BufferedImage createTestImage() {68BufferedImage img = new BufferedImage(100, 100,69BufferedImage.TYPE_INT_RGB);70Graphics2D g = img.createGraphics();71g.setColor(Color.white);72g.fillRect(0, 0, 100, 100);73g.setColor(Color.black);74g.fillRect(20, 20, 60, 60);7576return img;77}78}798081