Path: blob/master/test/jdk/java/net/URLConnection/TIFFContentGuesser.java
41152 views
/*1* Copyright (c) 2016, 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 814604126* @summary java.net.URLConnection.guessContentTypeFromStream() does not27* recognize TIFF streams28*/2930import java.io.ByteArrayInputStream;31import java.io.InputStream;32import java.net.URLConnection;3334public class TIFFContentGuesser {35private static final byte[] LITTLE_ENDIAN_MAGIC =36new byte[] {(byte)0x49, (byte)0x49, (byte)0x2a, (byte)0};37private static final byte[] BIG_ENDIAN_MAGIC =38new byte[] {(byte)0x4d, (byte)0x4d, (byte)0, (byte)0x2a};3940private static final String TIFF_MIME_TYPE = "image/tiff";4142public static void main(String[] args) throws Throwable {43int failures = 0;4445InputStream stream = new ByteArrayInputStream(LITTLE_ENDIAN_MAGIC);46String contentType = URLConnection.guessContentTypeFromStream(stream);47if (contentType == null || !contentType.equals(TIFF_MIME_TYPE)) {48failures++;49System.err.println("Test failed for little endian magic");50}5152stream = new ByteArrayInputStream(BIG_ENDIAN_MAGIC);53contentType = URLConnection.guessContentTypeFromStream(stream);54if (contentType == null || !contentType.equals(TIFF_MIME_TYPE)) {55failures++;56System.err.println("Test failed for big endian magic");57}5859if (failures != 0) {60throw new RuntimeException61("Test failed with " + failures + " error(s)");62}63}64}65666768