ForwardingFileObject.java revision 2571:10fc81ac75b4
1251607Sdim/*
2251607Sdim * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
3251607Sdim * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4251607Sdim *
5251607Sdim * This code is free software; you can redistribute it and/or modify it
6251607Sdim * under the terms of the GNU General Public License version 2 only, as
7251607Sdim * published by the Free Software Foundation.  Oracle designates this
8251607Sdim * particular file as subject to the "Classpath" exception as provided
9251607Sdim * by Oracle in the LICENSE file that accompanied this code.
10251607Sdim *
11251607Sdim * This code is distributed in the hope that it will be useful, but WITHOUT
12251607Sdim * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13251607Sdim * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14251607Sdim * version 2 for more details (a copy is included in the LICENSE file that
15251607Sdim * accompanied this code).
16251607Sdim *
17251607Sdim * You should have received a copy of the GNU General Public License version
18251607Sdim * 2 along with this work; if not, write to the Free Software Foundation,
19263508Sdim * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20263508Sdim *
21251607Sdim * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22263508Sdim * or visit www.oracle.com if you need additional information or have any
23251607Sdim * questions.
24251607Sdim */
25263508Sdim
26251607Sdimpackage javax.tools;
27263508Sdim
28251607Sdimimport java.io.IOException;
29263508Sdimimport java.io.InputStream;
30251607Sdimimport java.io.OutputStream;
31263508Sdimimport java.io.Reader;
32263508Sdimimport java.io.Writer;
33251607Sdimimport java.net.URI;
34251607Sdim
35251607Sdim/**
36251607Sdim * Forwards calls to a given file object.  Subclasses of this class
37251607Sdim * might override some of these methods and might also provide
38251607Sdim * additional fields and methods.
39251607Sdim *
40251607Sdim * @param <F> the kind of file object forwarded to by this object
41251607Sdim * @author Peter von der Ah&eacute;
42251607Sdim * @since 1.6
43251607Sdim */
44251607Sdimpublic class ForwardingFileObject<F extends FileObject> implements FileObject {
45251607Sdim
46251607Sdim    /**
47251607Sdim     * The file object which all methods are delegated to.
48251607Sdim     */
49251607Sdim    protected final F fileObject;
50251607Sdim
51251607Sdim    /**
52251607Sdim     * Creates a new instance of ForwardingFileObject.
53251607Sdim     * @param fileObject delegate to this file object
54251607Sdim     */
55251607Sdim    protected ForwardingFileObject(F fileObject) {
56251607Sdim        fileObject.getClass(); // null check
57251607Sdim        this.fileObject = fileObject;
58251607Sdim    }
59251607Sdim
60251607Sdim    public URI toUri() {
61263508Sdim        return fileObject.toUri();
62263508Sdim    }
63251607Sdim
64251607Sdim    public String getName() {
65251607Sdim        return fileObject.getName();
66251607Sdim    }
67251607Sdim
68251607Sdim    /**
69251607Sdim     * @throws IllegalStateException {@inheritDoc}
70251607Sdim     * @throws UnsupportedOperationException {@inheritDoc}
71251607Sdim     * @throws IOException {@inheritDoc}
72251607Sdim     */
73251607Sdim    public InputStream openInputStream() throws IOException {
74251607Sdim        return fileObject.openInputStream();
75251607Sdim    }
76251607Sdim
77251607Sdim    /**
78251607Sdim     * @throws IllegalStateException {@inheritDoc}
79263508Sdim     * @throws UnsupportedOperationException {@inheritDoc}
80251607Sdim     * @throws IOException {@inheritDoc}
81263508Sdim     */
82263508Sdim    public OutputStream openOutputStream() throws IOException {
83263508Sdim        return fileObject.openOutputStream();
84263508Sdim    }
85263508Sdim
86251607Sdim    /**
87251607Sdim     * @throws IllegalStateException {@inheritDoc}
88263508Sdim     * @throws UnsupportedOperationException {@inheritDoc}
89263508Sdim     * @throws IOException {@inheritDoc}
90251607Sdim     */
91263508Sdim    public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
92263508Sdim        return fileObject.openReader(ignoreEncodingErrors);
93251607Sdim    }
94263508Sdim
95263508Sdim    /**
96263508Sdim     * @throws IllegalStateException {@inheritDoc}
97263508Sdim     * @throws UnsupportedOperationException {@inheritDoc}
98251607Sdim     * @throws IOException {@inheritDoc}
99263508Sdim     */
100263508Sdim    public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
101263508Sdim        return fileObject.getCharContent(ignoreEncodingErrors);
102251607Sdim    }
103251607Sdim
104251607Sdim    /**
105263508Sdim     * @throws IllegalStateException {@inheritDoc}
106263508Sdim     * @throws UnsupportedOperationException {@inheritDoc}
107263508Sdim     * @throws IOException {@inheritDoc}
108251607Sdim     */
109251607Sdim    public Writer openWriter() throws IOException {
110251607Sdim        return fileObject.openWriter();
111251607Sdim    }
112251607Sdim
113251607Sdim    public long getLastModified() {
114251607Sdim        return fileObject.getLastModified();
115251607Sdim    }
116251607Sdim
117251607Sdim    public boolean delete() {
118251607Sdim        return fileObject.delete();
119251607Sdim    }
120251607Sdim}
121251607Sdim