@Override public void parse(InputStream inputStream, ContentHandler contentHandler, Metadata metadata, ParseContext parseContext) throws IOException, SAXException, TikaException { metadata.set(Metadata.CONTENT_TYPE,geoInfoType); DataStore dataStore= null; DefaultMetadata defaultMetadata=null; XHTMLContentHandler xhtmlContentHandler=new XHTMLContentHandler(contentHandler,metadata); TemporaryResources tmp = TikaInputStream.isTikaInputStream(inputStream) ? null : new TemporaryResources(); try { TikaInputStream tikaInputStream = TikaInputStream.get(inputStream,tmp); File file= tikaInputStream.getFile(); dataStore = DataStores.open(file); defaultMetadata=new DefaultMetadata(dataStore.getMetadata()); if(defaultMetadata!=null) extract(xhtmlContentHandler, metadata, defaultMetadata); } catch (UnsupportedStorageException e) { throw new TikaException("UnsupportedStorageException",e); } catch (DataStoreException e) { throw new TikaException("DataStoreException", e); } finally { if (tmp != null) { tmp.dispose(); } } }
/** * 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); } } }
/** * Returns the data store provider, or {@code null} if none. * * @todo on the JDK9 branch, use the {@code ServiceLoader} API that allows us * to filter by class without instantiation. */ final DataStoreProvider provider() throws InvalidOptionException { if (providerClass != null) { for (final DataStoreProvider provider : DataStores.providers()) { if (providerClass.isInstance(provider)) { return provider; } } } return null; } }
/** * Returns the list of data store providers available at this method invocation time. * More providers may be added later in a running JVM if new modules are added on the classpath. * * @return descriptions of available data stores. * * @since 0.8 */ public static Collection<DataStoreProvider> providers() { return registry().providers(); }
/** * Returns the set of data store providers available at this method invocation time. * More providers may be added later in a running JVM if new modules are added on the classpath. * * @return descriptions of available data stores. * * @since 0.8 */ public static Collection<DataStoreProvider> providers() { return registry().providers(); }
/** * If the given argument seems to be an authority code ("URN", "EPSG", "CRS", "AUTO", <i>etc.</i>), * delegates to {@link CRS#forCode(String)}. Otherwise reads the metadata using a datastore. * The input format is detected automatically (this is <strong>not</strong> {@link #outputFormat}). * * @return a {@link Metadata} or {@link CoordinateReferenceSystem} instance, or {@code null} if none. * @throws DataStoreException if an error occurred while reading the file. * @throws FactoryException if an error occurred while looking for a CRS identifier. */ final Object readMetadataOrCRS() throws DataStoreException, FactoryException { if (useStandardInput()) { try (DataStore store = DataStores.open(System.in)) { return store.getMetadata(); } } else if (hasUnexpectedFileCount(1, 1)) { hasUnexpectedFileCount = true; return null; } else { final String file = files.get(0); if (CodeType.guess(file).isCRS) { return CRS.forCode(file); } else { try (DataStore store = DataStores.open(file)) { return store.getMetadata(); } } } }
/** * Returns a provider having an {@linkplain DataStoreProvider#getOpenParameters() identification} * equals (ignoring case) to the given string. If more than one provider is found, then this * method selects an arbitrary one. If no factory is found, then this method returns * {@code null}. * * @param identifier The identifier of the factory to find. * @return A factory for the given identifier, or {@code null} if none. */ public static synchronized DataStoreProvider getProviderById(final String identifier) { for (final DataStoreProvider factory : org.apache.sis.storage.DataStores.providers()) { for (String name : IdentifiedObjects.getNames(factory.getOpenParameters(),null)) { if (name.equals(identifier)) { return factory; } } } return null; }
/** * 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); } } }
/** * Returns the MIME type of the storage file format, or {@code null} if unknown or not applicable. * * @param storage the input/output object as a URL, file, image input stream, <i>etc.</i>. * @return the storage MIME type, or {@code null} if unknown or not applicable. * @throws DataStoreException if an error occurred while opening the storage. */ public static String probeContentType(final Object storage) throws DataStoreException { return registry().probeContentType(storage); }
/** * Tests {@link DataStores#open(Object)}. * * @throws DataStoreException Should never happen. */ @Test public void testOpen() throws DataStoreException { final DataStore store = DataStores.open(new StringReader(StoreTest.XML)); assertFalse(store.getMetadata().getContacts().isEmpty()); } }
final Set<T> results = new HashSet<>(); loop: for (DataStoreProvider p : org.apache.sis.storage.DataStores.providers()) { if (clazz != null && !clazz.isInstance(p)) continue; if (types != null && types.length > 0) {
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);
/** * Returns the MIME type of the storage file format, or {@code null} if unknown or not applicable. * * @param storage the input/output object as a URL, file, image input stream, <i>etc.</i>. * @return the storage MIME type, or {@code null} if unknown or not applicable. * @throws DataStoreException if an error occurred while opening the storage. */ public static String probeContentType(final Object storage) throws DataStoreException { return registry().probeContentType(storage); }
connector.setOption(OptionKey.ENCODING, encoding); try { next = DataStores.open(connector); } catch (UnsupportedStorageException ex) { if (!Files.isDirectory(candidate)) {
/** * Returns a provider for the given format name. * * @param format name of the format for which to get a provider. * @return first provider found for the given format name. * @throws UnsupportedStorageException if no provider is found for the specified format. * * @see StoreMetadata#formatName() */ public static DataStoreProvider providerByFormatName(final String format) throws UnsupportedStorageException { for (DataStoreProvider provider : DataStores.providers()) { if (format.equalsIgnoreCase(getFormatName(provider))) { return provider; } } throw new UnsupportedStorageException(Errors.format(Errors.Keys.UnsupportedFormat_1, format)); }
/** * 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); }
/** * Creates a {@link DataStore} for the given storage. * The {@code storage} argument can be any of the following types: * * <ul> * <li>A {@link java.nio.file.Path} or a {@link java.io.File} for a file or a directory.</li> * <li>A {@link java.net.URI} or a {@link java.net.URL} to a distant resource.</li> * <li>A {@link java.lang.CharSequence} interpreted as a filename or a URL.</li> * <li>A {@link java.nio.channels.Channel}, {@link java.io.DataInput}, {@link java.io.InputStream} or {@link java.io.Reader}.</li> * <li>A {@link javax.sql.DataSource} or a {@link java.sql.Connection} to a JDBC database.</li> * <li>Any other {@code DataStore}-specific object, for example {@link ucar.nc2.NetcdfFile}.</li> * <li>An existing {@link StorageConnector} instance.</li> * </ul> * * @param storage the input/output object as a URL, file, image input stream, <i>etc.</i>. * @return the object to use for reading geospatial data from the given storage. * @throws UnsupportedStorageException if no {@link DataStoreProvider} is found for a given storage object. * @throws DataStoreException if an error occurred while opening the storage. */ public static DataStore open(final Object storage) throws UnsupportedStorageException, DataStoreException { return registry().open(storage); } }
try { if (componentProvider == null) { next = DataStores.open(connector); // May throw UnsupportedStorageException. } else if (componentProvider.probeContent(connector).isSupported()) {
final Collection<DataStoreProvider> providers = DataStores.providers(); final int count = providers.size(); final String[] list = new String[count * 2];
/** * Creates a {@link DataStore} for the given storage. * The {@code storage} argument can be any of the following types: * * <ul> * <li>A {@link java.nio.file.Path} or a {@link java.io.File} for a file or a directory.</li> * <li>A {@link java.net.URI} or a {@link java.net.URL} to a distant resource.</li> * <li>A {@link java.lang.CharSequence} interpreted as a filename or a URL.</li> * <li>A {@link java.nio.channels.Channel}, {@link java.io.DataInput}, {@link java.io.InputStream} or {@link java.io.Reader}.</li> * <li>A {@link javax.sql.DataSource} or a {@link java.sql.Connection} to a JDBC database.</li> * <li>Any other {@code DataStore}-specific object, for example {@link ucar.nc2.NetcdfFile}.</li> * <li>An existing {@link StorageConnector} instance.</li> * </ul> * * @param storage the input/output object as a URL, file, image input stream, <i>etc.</i>. * @return the object to use for reading geospatial data from the given storage. * @throws UnsupportedStorageException if no {@link DataStoreProvider} is found for a given storage object. * @throws DataStoreException if an error occurred while opening the storage. */ public static DataStore open(final Object storage) throws UnsupportedStorageException, DataStoreException { return registry().open(storage); } }