/** * Probes the given file by delegating to {@link DataStores#probeContentType(Object)}. * * @param path the path to the file to probe. * @return the content type or {@code null} if the file type is not recognized. * @throws IOException if an I/O error occurs while reading the file. * * @see java.nio.file.Files#probeContentType(Path) */ @Override public String probeContentType(final Path path) throws IOException { try { return DataStores.probeContentType(path); } catch (DataStoreException e) { final Throwable cause = e.getCause(); if (cause instanceof IOException) { throw (IOException) cause; } throw new IOException(e); } } }
/** * Probes the given file by delegating to {@link DataStores#probeContentType(Object)}. * * @param path the path to the file to probe. * @return the content type or {@code null} if the file type is not recognized. * @throws IOException if an I/O error occurs while reading the file. * * @see java.nio.file.Files#probeContentType(Path) */ @Override public String probeContentType(final Path path) throws IOException { try { return DataStores.probeContentType(path); } catch (DataStoreException e) { final Throwable cause = e.getCause(); if (cause instanceof IOException) { throw (IOException) cause; } throw new IOException(e); } } }
type = DataStores.probeContentType(file); } else try { type = Files.probeContentType(Paths.get(uri)); } catch (IllegalArgumentException | FileSystemNotFoundException e) { type = DataStores.probeContentType(uri); } catch (NoSuchFileException e) { error(Errors.format(Errors.Keys.CanNotOpen_1, uri), e);
/** * Tests {@link DataStores#probeContentType(Object)}. * * @throws DataStoreException Should never happen. */ @Test public void testProbeContentType() throws DataStoreException { final String type = DataStores.probeContentType(new StringReader(StoreTest.XML)); assertEquals("application/vnd.iso.19139+xml", type); }