    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *     https://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 * Unless required by applicable law or agreed to in writing, software
    012 * distributed under the License is distributed on an "AS IS" BASIS,
    013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 * See the License for the specific language governing permissions and
    015 * limitations under the License.
    016 */
    017package org.apache.commons.configuration2.io;
    018
    019import java.io.IOException;
    020import java.io.Reader;
    021import java.io.Writer;
    022
    023import org.apache.commons.configuration2.ex.ConfigurationException;
    024
    025/**
    026 * <p>
    027 * Definition of an interface to be implemented by objects which know how to read and write themselves from or to a
    028 * character stream.
    029 * </p>
    030 * <p>
    031 * This interface is implemented by special implementations of the {@code Configuration} interface which are associated
    032 * with a file. It demands only basic methods for doing I/O based on character stream objects. Based on these methods it
    033 * is possible to implement other methods which operate on files, file names, URLs, etc.
    034 * </p>
    035 * <p>
    036 * <strong>Note that the methods defined by this interface are not intended to be called directly by client
    037 * code!</strong> Rather, they are used internally when doing I/O operations with a {@link FileHandler}. A
    038 * {@code FileHandler} supports additional functionality (for example it evaluates some additional interfaces the
    039 * {@code FileBased} object may implement); this functionality is not available on a direct method invocation, so this
    040 * may lead to unpredictable results.
    041 * </p>
    042 */
    043public interface FileBased {
    044    /**
    045     * Reads the content of this object from the given reader. <strong>Client code should not call this method directly, but
    046     * use a {@code FileHandler} for reading data.</strong>
    047     *
    048     * @param in the reader
    049     * @throws IOException if an I/O error occurs.
    050     * @throws ConfigurationException if a non-I/O related problem occurs, for example the data read does not have the expected
    051     *         format
    052     */
    053    void read(Reader in) throws ConfigurationException, IOException;
    054
    055    /**
    056     * Writes the content of this object to the given writer. <strong>Client code should not call this method directly, but
    057     * use a {@code FileHandler} for writing data.</strong>
    058     *
    059     * @param out the writer
    060     * @throws IOException if an I/O error occurs.
    061     * @throws ConfigurationException if a non-I/O related problem occurs, for example the data read does not have the expected
    062     *         format
    063     */
    064    void write(Writer out) throws ConfigurationException, IOException;
    065}