< prev index next >

test/java/nio/file/Files/probeContentType/Basic.java

Print this page
rev 14565 : 8146215: (fs) java/nio/file/Files/probeContentType/Basic.java failed frequently on Solaris-sparc with Unexpected type: text/plain
Summary: Append a FileTypeDetector using java.net.FileNameMap as a fallback on all platforms
Reviewed-by: alanb, rriggs, naoto

*** 20,30 **** * or visit www.oracle.com if you need additional information or have any * questions. */ /* @test ! * @bug 4313887 * @summary Unit test for probeContentType method * @library ../.. * @build Basic SimpleFileTypeDetector * @run main/othervm Basic */ --- 20,30 ---- * or visit www.oracle.com if you need additional information or have any * questions. */ /* @test ! * @bug 4313887 8129632 8129633 8162624 8146215 * @summary Unit test for probeContentType method * @library ../.. * @build Basic SimpleFileTypeDetector * @run main/othervm Basic */
*** 36,46 **** /** * Uses Files.probeContentType to probe html file, custom file type, and minimal * set of file extension to content type mappings. */ public class Basic { - private static final boolean IS_UNIX = ! System.getProperty("os.name").startsWith("Windows"); static Path createHtmlFile() throws IOException { Path file = Files.createTempFile("foo", ".html"); --- 36,45 ----
*** 53,100 **** static Path createGrapeFile() throws IOException { return Files.createTempFile("red", ".grape"); } private static int checkContentTypes(String expected, String actual) { assert expected != null; assert actual != null; if (!expected.equals(actual)) { if (IS_UNIX) { Path userMimeTypes = Paths.get(System.getProperty("user.home"), ".mime.types"); ! if (!Files.exists(userMimeTypes)) { ! System.out.println(userMimeTypes + " does not exist"); ! } else if (!Files.isReadable(userMimeTypes)) { ! System.out.println(userMimeTypes + " is not readable"); ! } else { ! System.out.println(userMimeTypes + " contents:"); ! try (Stream<String> lines = Files.lines(userMimeTypes)) { ! lines.forEach(System.out::println); ! System.out.println(""); ! } catch (IOException ioe) { ! System.err.println("Problem reading " ! + userMimeTypes); ! } ! } Path etcMimeTypes = Paths.get("/etc/mime.types"); ! if (!Files.exists(etcMimeTypes)) { ! System.out.println(etcMimeTypes + " does not exist"); ! } else if (!Files.isReadable(etcMimeTypes)) { ! System.out.println(etcMimeTypes + " is not readable"); ! } else { ! System.out.println(etcMimeTypes + " contents:"); ! try (Stream<String> lines = Files.lines(etcMimeTypes)) { ! lines.forEach(System.out::println); ! System.out.println(""); ! } catch (IOException ioe) { ! System.err.println("Problem reading " ! + etcMimeTypes); ! } ! } } System.err.println("Expected \"" + expected + "\" but obtained \"" + actual + "\""); --- 52,90 ---- static Path createGrapeFile() throws IOException { return Files.createTempFile("red", ".grape"); } + private static void checkMimeTypesFile(Path mimeTypes) { + if (!Files.exists(mimeTypes)) { + System.out.println(mimeTypes + " does not exist"); + } else if (!Files.isReadable(mimeTypes)) { + System.out.println(mimeTypes + " is not readable"); + } else { + System.out.println(mimeTypes + " contents:"); + try (Stream<String> lines = Files.lines(mimeTypes)) { + lines.forEach(System.out::println); + System.out.println(""); + } catch (IOException ioe) { + System.err.printf("Problem reading %s: %s%n", + mimeTypes, ioe.getMessage()); + } + } + } + private static int checkContentTypes(String expected, String actual) { assert expected != null; assert actual != null; if (!expected.equals(actual)) { if (IS_UNIX) { Path userMimeTypes = Paths.get(System.getProperty("user.home"), ".mime.types"); ! checkMimeTypesFile(userMimeTypes); Path etcMimeTypes = Paths.get("/etc/mime.types"); ! checkMimeTypesFile(etcMimeTypes); } System.err.println("Expected \"" + expected + "\" but obtained \"" + actual + "\"");
*** 123,135 **** // exercise custom file type detector file = createGrapeFile(); try { String type = Files.probeContentType(file); ! if (type == null) ! throw new RuntimeException("Custom file type detector not installed?"); failures += checkContentTypes("grape/unknown", type); } finally { Files.delete(file); } if (failures > 0) { --- 113,128 ---- // exercise custom file type detector file = createGrapeFile(); try { String type = Files.probeContentType(file); ! if (type == null) { ! System.err.println("Custom file type detector not installed?"); ! failures++; ! } else { failures += checkContentTypes("grape/unknown", type); + } } finally { Files.delete(file); } if (failures > 0) {
< prev index next >