ForwardingFileObject.java revision 2837:1e3266d870d6
1/*
2 * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package javax.tools;
27
28import java.io.IOException;
29import java.io.InputStream;
30import java.io.OutputStream;
31import java.io.Reader;
32import java.io.Writer;
33import java.net.URI;
34import java.util.Objects;
35
36/**
37 * Forwards calls to a given file object.  Subclasses of this class
38 * might override some of these methods and might also provide
39 * additional fields and methods.
40 *
41 * @param <F> the kind of file object forwarded to by this object
42 * @author Peter von der Ah&eacute;
43 * @since 1.6
44 */
45public class ForwardingFileObject<F extends FileObject> implements FileObject {
46
47    /**
48     * The file object which all methods are delegated to.
49     */
50    protected final F fileObject;
51
52    /**
53     * Creates a new instance of ForwardingFileObject.
54     * @param fileObject delegate to this file object
55     */
56    protected ForwardingFileObject(F fileObject) {
57        this.fileObject = Objects.requireNonNull(fileObject);
58    }
59
60    public URI toUri() {
61        return fileObject.toUri();
62    }
63
64    public String getName() {
65        return fileObject.getName();
66    }
67
68    /**
69     * @throws IllegalStateException {@inheritDoc}
70     * @throws UnsupportedOperationException {@inheritDoc}
71     * @throws IOException {@inheritDoc}
72     */
73    public InputStream openInputStream() throws IOException {
74        return fileObject.openInputStream();
75    }
76
77    /**
78     * @throws IllegalStateException {@inheritDoc}
79     * @throws UnsupportedOperationException {@inheritDoc}
80     * @throws IOException {@inheritDoc}
81     */
82    public OutputStream openOutputStream() throws IOException {
83        return fileObject.openOutputStream();
84    }
85
86    /**
87     * @throws IllegalStateException {@inheritDoc}
88     * @throws UnsupportedOperationException {@inheritDoc}
89     * @throws IOException {@inheritDoc}
90     */
91    public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
92        return fileObject.openReader(ignoreEncodingErrors);
93    }
94
95    /**
96     * @throws IllegalStateException {@inheritDoc}
97     * @throws UnsupportedOperationException {@inheritDoc}
98     * @throws IOException {@inheritDoc}
99     */
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}
121