001/*
002 * Copyright 2002-2016 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.util;
018
019import java.io.IOException;
020import java.io.InputStream;
021import java.io.OutputStream;
022import java.io.Reader;
023import java.io.Writer;
024import java.util.Properties;
025
026/**
027 * Strategy interface for persisting {@code java.util.Properties},
028 * allowing for pluggable parsing strategies.
029 *
030 * <p>The default implementation is DefaultPropertiesPersister,
031 * providing the native parsing of {@code java.util.Properties},
032 * but allowing for reading from any Reader and writing to any Writer
033 * (which allows to specify an encoding for a properties file).
034 *
035 * @author Juergen Hoeller
036 * @since 10.03.2004
037 * @see DefaultPropertiesPersister
038 * @see java.util.Properties
039 */
040public interface PropertiesPersister {
041
042        /**
043         * Load properties from the given InputStream into the given
044         * Properties object.
045         * @param props the Properties object to load into
046         * @param is the InputStream to load from
047         * @throws IOException in case of I/O errors
048         * @see java.util.Properties#load
049         */
050        void load(Properties props, InputStream is) throws IOException;
051
052        /**
053         * Load properties from the given Reader into the given
054         * Properties object.
055         * @param props the Properties object to load into
056         * @param reader the Reader to load from
057         * @throws IOException in case of I/O errors
058         */
059        void load(Properties props, Reader reader) throws IOException;
060
061        /**
062         * Write the contents of the given Properties object to the
063         * given OutputStream.
064         * @param props the Properties object to store
065         * @param os the OutputStream to write to
066         * @param header the description of the property list
067         * @throws IOException in case of I/O errors
068         * @see java.util.Properties#store
069         */
070        void store(Properties props, OutputStream os, String header) throws IOException;
071
072        /**
073         * Write the contents of the given Properties object to the
074         * given Writer.
075         * @param props the Properties object to store
076         * @param writer the Writer to write to
077         * @param header the description of the property list
078         * @throws IOException in case of I/O errors
079         */
080        void store(Properties props, Writer writer, String header) throws IOException;
081
082        /**
083         * Load properties from the given XML InputStream into the
084         * given Properties object.
085         * @param props the Properties object to load into
086         * @param is the InputStream to load from
087         * @throws IOException in case of I/O errors
088         * @see java.util.Properties#loadFromXML(java.io.InputStream)
089         */
090        void loadFromXml(Properties props, InputStream is) throws IOException;
091
092        /**
093         * Write the contents of the given Properties object to the
094         * given XML OutputStream.
095         * @param props the Properties object to store
096         * @param os the OutputStream to write to
097         * @param header the description of the property list
098         * @throws IOException in case of I/O errors
099         * @see java.util.Properties#storeToXML(java.io.OutputStream, String)
100         */
101        void storeToXml(Properties props, OutputStream os, String header) throws IOException;
102
103        /**
104         * Write the contents of the given Properties object to the
105         * given XML OutputStream.
106         * @param props the Properties object to store
107         * @param os the OutputStream to write to
108         * @param encoding the encoding to use
109         * @param header the description of the property list
110         * @throws IOException in case of I/O errors
111         * @see java.util.Properties#storeToXML(java.io.OutputStream, String, String)
112         */
113        void storeToXml(Properties props, OutputStream os, String header, String encoding) throws IOException;
114
115}