    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 *     http://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
    028 * read and write themselves from or to a character stream.
    029 * </p>
    030 * <p>
    031 * This interface is implemented by special implementations of the
    032 * {@code Configuration} interface which are associated with a file. It demands
    033 * only basic methods for doing I/O based on character stream objects. Based on
    034 * these methods it is possible to implement other methods which operate on
    035 * files, file names, URLs, etc.
    036 * </p>
    037 * <p>
    038 * <strong>Note that the methods defined by this interface are not intended to
    039 * be called directly by client code!</strong> Rather, they are used internally
    040 * when doing I/O operations with a {@link FileHandler}. A {@code FileHandler}
    041 * supports additional functionality (e.g. it evaluates some additional
    042 * interfaces the {@code FileBased} object may implement); this functionality
    043 * is not available on a direct method invocation, so this may lead to
    044 * unpredictable results.
    045 * </p>
    046 *
    047 * @version $Id: FileBased.java 1772264 2016-12-01 20:51:46Z oheger $
    048 */
    049public interface FileBased
    050{
    051    /**
    052     * Reads the content of this object from the given reader.
    053     * <strong>Client code should not call this method directly, but use a
    054     * {@code FileHandler} for reading data.</strong>
    055     *
    056     * @param in the reader
    057     * @throws IOException if an I/O error occurs
    058     * @throws ConfigurationException if a non-I/O related problem occurs, e.g.
    059     *         the data read does not have the expected format
    060     */
    061    void read(Reader in) throws ConfigurationException, IOException;
    062
    063    /**
    064     * Writes the content of this object to the given writer.
    065     * <strong>Client code should not call this method directly, but use a
    066     * {@code FileHandler} for writing data.</strong>
    067     *
    068     * @param out the writer
    069     * @throws IOException if an I/O error occurs
    070     * @throws ConfigurationException if a non-I/O related problem occurs, e.g.
    071     *         the data read does not have the expected format
    072     */
    073    void write(Writer out) throws ConfigurationException, IOException;
    074}