001    /*
002     * Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
003     * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004     *
005     * This code is free software; you can redistribute it and/or modify it
006     * under the terms of the GNU General Public License version 2 only, as
007     * published by the Free Software Foundation.  Sun designates this
008     * particular file as subject to the "Classpath" exception as provided
009     * by Sun in the LICENSE file that accompanied this code.
010     *
011     * This code is distributed in the hope that it will be useful, but WITHOUT
012     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013     * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014     * version 2 for more details (a copy is included in the LICENSE file that
015     * accompanied this code).
016     *
017     * You should have received a copy of the GNU General Public License version
018     * 2 along with this work; if not, write to the Free Software Foundation,
019     * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020     *
021     * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022     * CA 95054 USA or visit www.sun.com if you need additional information or
023     * have any questions.
024     */
025    
026    package javax.tools;
027    
028    import java.io.IOException;
029    import java.io.InputStream;
030    import java.io.OutputStream;
031    import java.io.Reader;
032    import java.io.Writer;
033    import java.net.URI;
034    
035    /**
036     * Forwards calls to a given file object.  Subclasses of this class
037     * might override some of these methods and might also provide
038     * additional fields and methods.
039     *
040     * @param <F> the kind of file object forwarded to by this object
041     * @author Peter von der Ah&eacute;
042     * @since 1.6
043     */
044    public class ForwardingFileObject<F extends FileObject> implements FileObject {
045    
046        /**
047         * The file object which all methods are delegated to.
048         */
049        protected final F fileObject;
050    
051        /**
052         * Creates a new instance of ForwardingFileObject.
053         * @param fileObject delegate to this file object
054         */
055        protected ForwardingFileObject(F fileObject) {
056            fileObject.getClass(); // null check
057            this.fileObject = fileObject;
058        }
059    
060        public URI toUri() {
061            return fileObject.toUri();
062        }
063    
064        public String getName() {
065            return fileObject.getName();
066        }
067    
068        /**
069         * @throws IllegalStateException {@inheritDoc}
070         * @throws UnsupportedOperationException {@inheritDoc}
071         * @throws IOException {@inheritDoc}
072         */
073        public InputStream openInputStream() throws IOException {
074            return fileObject.openInputStream();
075        }
076    
077        /**
078         * @throws IllegalStateException {@inheritDoc}
079         * @throws UnsupportedOperationException {@inheritDoc}
080         * @throws IOException {@inheritDoc}
081         */
082        public OutputStream openOutputStream() throws IOException {
083            return fileObject.openOutputStream();
084        }
085    
086        /**
087         * @throws IllegalStateException {@inheritDoc}
088         * @throws UnsupportedOperationException {@inheritDoc}
089         * @throws IOException {@inheritDoc}
090         */
091        public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
092            return fileObject.openReader(ignoreEncodingErrors);
093        }
094    
095        /**
096         * @throws IllegalStateException {@inheritDoc}
097         * @throws UnsupportedOperationException {@inheritDoc}
098         * @throws IOException {@inheritDoc}
099         */
100        public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
101            return fileObject.getCharContent(ignoreEncodingErrors);
102        }
103    
104        /**
105         * @throws IllegalStateException {@inheritDoc}
106         * @throws UnsupportedOperationException {@inheritDoc}
107         * @throws IOException {@inheritDoc}
108         */
109        public Writer openWriter() throws IOException {
110            return fileObject.openWriter();
111        }
112    
113        public long getLastModified() {
114            return fileObject.getLastModified();
115        }
116    
117        public boolean delete() {
118            return fileObject.delete();
119        }
120    }