View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF 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.apache.commons.configuration2.io;
18  
19  import java.io.IOException;
20  import java.io.InputStream;
21  
22  import org.apache.commons.configuration2.ex.ConfigurationException;
23  
24  /**
25   * <p>
26   * Definition of an interface to be implemented by objects which support reading from an input stream.
27   * </p>
28   * <p>
29   * When reading data using a {@link FileHandler} per default a reader is used as defined by the
30   * {@link FileBased#read(java.io.Reader)} method. For some configuration formats it is necessary to directly read binary
31   * data. In order to achieve this, a {@link FileBased} object can also implement this interface. It defines an
32   * additional {@code read()} method expecting an {@code InputStream} as argument. If the {@code FileHandler} detects
33   * that its associated {@code FileBased} object implements this interface, it passes the input stream directly rather
34   * than transforming it to a reader.
35   * </p>
36   *
37   * @since 2.0
38   */
39  public interface InputStreamSupport {
40      /**
41       * Reads the content of this object from the specified {@code InputStream}.
42       *
43       * @param in the input stream
44       * @throws ConfigurationException if a non-I/O related problem occurs, e.g. the data read does not have the expected
45       *         format
46       * @throws IOException if an I/O error occurs.
47       */
48      void read(InputStream in) throws ConfigurationException, IOException;
49  }