1   /* Copyright 2002-2025 CS GROUP
2    * Licensed to CS GROUP (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  
19  import java.io.IOException;
20  
21  /** Interface for filtering data (typically uncompressing it) in {@link DataProvider data providers}
22   * before passing it to {@link DataLoader data loaders}.
23   * @see DataProvider
24   * @see DataLoader
25   * @author Luc Maisonobe
26   * @since 9.2
27   */
28  public interface DataFilter {
29  
30      /** Filter the data source.
31       * <p>
32       * Filtering is often based on suffix. For example a gzip compressed
33       * file will have an original name of the form base.ext.gz when the
34       * corresponding uncompressed file will have a filtered name base.ext.
35       * </p>
36       * <p>
37       * A filter must <em>never</em> {@link DataSource.Opener#openStreamOnce() open}
38       * the {@link DataSource} by itself, regardless of the fact it will return
39       * the original instance or a filtered instance. The rationale is that it
40       * is the upper layer that will decide to open (or not) the returned
41       * value and that a {@link DataSource} can be opened only once; this is the
42       * core principle of lazy-opening provided by {@link DataSource}.
43       * </p>
44       * <p>
45       * Beware that as the {@link DataProvidersManager data providers manager}
46       * will attempt to pile all filters in a stack as long as their implementation
47       * of this method returns a value different from the {@code original} parameter.
48       * This implies that the filter, <em>must</em> perform some checks to see if it must
49       * be applied or not. If for example there is a need for a deciphering filter
50       * to be applied once to all data, then the filter should for example check
51       * for a suffix in the {@link DataSource#getName() name} and create a new
52       * filtered {@link DataSource} instance <em>only</em> if the suffix is present,
53       * removing the suffix from the filtered instance. Failing to do so and simply
54       * creating a filtered instance with one deciphering layer without changing the
55       * name would result in an infinite stack of deciphering filters being built, until
56       * a stack overflow or memory exhaustion exception occurs.
57       * </p>
58       * @param original original data source
59       * @return filtered data source, or {@code original} if this filter
60       * does not apply to this data source
61       * @exception IOException if filtered stream cannot be created
62       */
63      DataSource filter(DataSource original) throws IOException;
64  
65  }