NamedData.java

  1. /* Copyright 2002-2018 CS Systèmes d'Information
  2.  * Licensed to CS Systèmes d'Information (CS) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * CS licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *   http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.orekit.data;

  18. import java.io.IOException;
  19. import java.io.InputStream;

  20. import org.orekit.errors.OrekitException;

  21. /** Container for holding named data that can be {@link DataFilter filtered}.
  22.  * <p>
  23.  * This class is a simple container without any processing methods.
  24.  * </p>
  25.  * @see DataFilter
  26.  * @author Luc Maisonobe
  27.  * @since 9.2
  28.  */
  29. public class NamedData {

  30.     /** Name of the data (file name, zip entry name...). */
  31.     private final String name;

  32.     /** Supplier for data stream. */
  33.     private final StreamOpener streamOpener;

  34.     /** Simple constructor.
  35.      * @param name data name
  36.      * @param streamOpener opener for the data stream
  37.      */
  38.     public NamedData(final String name, final StreamOpener streamOpener) {
  39.         this.name         = name;
  40.         this.streamOpener = streamOpener;
  41.     }

  42.     /** Get the name of the data.
  43.      * @return name of the data
  44.      */
  45.     public String getName() {
  46.         return name;
  47.     }

  48.     /** Get the data stream opener.
  49.      * @return data stream opener
  50.      */
  51.     public StreamOpener getStreamOpener() {
  52.         return streamOpener;
  53.     }

  54.     /** Interface for lazy-opening a stream. */
  55.     public interface StreamOpener {
  56.         /** Open the stream.
  57.          * @return opened stream
  58.          * @exception IOException if stream cannot be opened
  59.          * @exception OrekitException if some format error is detected
  60.          */
  61.         InputStream openStream() throws IOException, OrekitException;

  62.     }

  63. }