Path: blob/master/src/java.compiler/share/classes/javax/tools/ForwardingFileObject.java
41152 views
/*1* Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.tools;2627import java.io.IOException;28import java.io.InputStream;29import java.io.OutputStream;30import java.io.Reader;31import java.io.Writer;32import java.net.URI;33import java.util.Objects;3435/**36* Forwards calls to a given file object. Subclasses of this class37* might override some of these methods and might also provide38* additional fields and methods.39*40* @param <F> the kind of file object forwarded to by this object41* @author Peter von der Ahé42* @since 1.643*/44public class ForwardingFileObject<F extends FileObject> implements FileObject {4546/**47* The file object which all methods are delegated to.48*/49protected final F fileObject;5051/**52* Creates a new instance of {@code ForwardingFileObject}.53* @param fileObject delegate to this file object54*/55protected ForwardingFileObject(F fileObject) {56this.fileObject = Objects.requireNonNull(fileObject);57}5859@Override60public URI toUri() {61return fileObject.toUri();62}6364@Override65public String getName() {66return fileObject.getName();67}6869/**70* @throws IllegalStateException {@inheritDoc}71* @throws UnsupportedOperationException {@inheritDoc}72* @throws IOException {@inheritDoc}73*/74@Override75public InputStream openInputStream() throws IOException {76return fileObject.openInputStream();77}7879/**80* @throws IllegalStateException {@inheritDoc}81* @throws UnsupportedOperationException {@inheritDoc}82* @throws IOException {@inheritDoc}83*/84@Override85public OutputStream openOutputStream() throws IOException {86return fileObject.openOutputStream();87}8889/**90* @throws IllegalStateException {@inheritDoc}91* @throws UnsupportedOperationException {@inheritDoc}92* @throws IOException {@inheritDoc}93*/94@Override95public Reader openReader(boolean ignoreEncodingErrors) throws IOException {96return fileObject.openReader(ignoreEncodingErrors);97}9899/**100* @throws IllegalStateException {@inheritDoc}101* @throws UnsupportedOperationException {@inheritDoc}102* @throws IOException {@inheritDoc}103*/104@Override105public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {106return fileObject.getCharContent(ignoreEncodingErrors);107}108109/**110* @throws IllegalStateException {@inheritDoc}111* @throws UnsupportedOperationException {@inheritDoc}112* @throws IOException {@inheritDoc}113*/114@Override115public Writer openWriter() throws IOException {116return fileObject.openWriter();117}118119@Override120public long getLastModified() {121return fileObject.getLastModified();122}123124@Override125public boolean delete() {126return fileObject.delete();127}128}129130131