    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 */
    048public interface FileBased
    049{
    050    /**
    051     * Reads the content of this object from the given reader.
    052     * <strong>Client code should not call this method directly, but use a
    053     * {@code FileHandler} for reading data.</strong>
    054     *
    055     * @param in the reader
    056     * @throws IOException if an I/O error occurs
    057     * @throws ConfigurationException if a non-I/O related problem occurs, e.g.
    058     *         the data read does not have the expected format
    059     */
    060    void read(Reader in) throws ConfigurationException, IOException;
    061
    062    /**
    063     * Writes the content of this object to the given writer.
    064     * <strong>Client code should not call this method directly, but use a
    065     * {@code FileHandler} for writing data.</strong>
    066     *
    067     * @param out the writer
    068     * @throws IOException if an I/O error occurs
    069     * @throws ConfigurationException if a non-I/O related problem occurs, e.g.
    070     *         the data read does not have the expected format
    071     */
    072    void write(Writer out) throws ConfigurationException, IOException;
    073}