Path: blob/master/test/jdk/javax/imageio/ImageStreamFromRAF.java
41144 views
/*1* Copyright (c) 2001, 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 439537826* @summary Checks that ImageIO.createImageInputStream and27* createImageOutputStream produce correct output when given a28* RandomAccessFile29*/3031import java.io.File;32import java.io.IOException;33import java.io.RandomAccessFile;3435import javax.imageio.ImageIO;36import javax.imageio.stream.FileImageInputStream;37import javax.imageio.stream.FileImageOutputStream;38import javax.imageio.stream.ImageInputStream;39import javax.imageio.stream.ImageOutputStream;4041public class ImageStreamFromRAF {4243public static void main(String[] args) {44try {45File f = new File("ImageInputStreamFromRAF.tmp");46RandomAccessFile raf = new RandomAccessFile(f, "rw");47ImageInputStream istream = ImageIO.createImageInputStream(raf);48ImageOutputStream ostream = ImageIO.createImageOutputStream(raf);49f.delete();50if (istream == null) {51throw new RuntimeException("ImageIO.createImageInputStream(RandomAccessFile) returned null!");52}53if (ostream == null) {54throw new RuntimeException("ImageIO.createImageOutputStream(RandomAccessFile) returned null!");55}56if (!(istream instanceof FileImageInputStream)) {57throw new RuntimeException("ImageIO.createImageInputStream(RandomAccessFile) did not return a FileImageInputStream!");58}59if (!(ostream instanceof FileImageOutputStream)) {60throw new RuntimeException("ImageIO.createImageOutputStream(RandomAccessFile) did not return a FileImageOutputStream!");61}62} catch (IOException ioe) {63throw new RuntimeException("Unexpected IOException: " + ioe);64}65}66}676869