src/share/classes/javax/tools/ForwardingFileObject.java

changeset 0
959103a6100f
child 2525
2eb010b6cb22
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/classes/javax/tools/ForwardingFileObject.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,120 @@
     1.4 +/*
     1.5 + * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package javax.tools;
    1.30 +
    1.31 +import java.io.IOException;
    1.32 +import java.io.InputStream;
    1.33 +import java.io.OutputStream;
    1.34 +import java.io.Reader;
    1.35 +import java.io.Writer;
    1.36 +import java.net.URI;
    1.37 +
    1.38 +/**
    1.39 + * Forwards calls to a given file object.  Subclasses of this class
    1.40 + * might override some of these methods and might also provide
    1.41 + * additional fields and methods.
    1.42 + *
    1.43 + * @param <F> the kind of file object forwarded to by this object
    1.44 + * @author Peter von der Ah&eacute;
    1.45 + * @since 1.6
    1.46 + */
    1.47 +public class ForwardingFileObject<F extends FileObject> implements FileObject {
    1.48 +
    1.49 +    /**
    1.50 +     * The file object which all methods are delegated to.
    1.51 +     */
    1.52 +    protected final F fileObject;
    1.53 +
    1.54 +    /**
    1.55 +     * Creates a new instance of ForwardingFileObject.
    1.56 +     * @param fileObject delegate to this file object
    1.57 +     */
    1.58 +    protected ForwardingFileObject(F fileObject) {
    1.59 +        fileObject.getClass(); // null check
    1.60 +        this.fileObject = fileObject;
    1.61 +    }
    1.62 +
    1.63 +    public URI toUri() {
    1.64 +        return fileObject.toUri();
    1.65 +    }
    1.66 +
    1.67 +    public String getName() {
    1.68 +        return fileObject.getName();
    1.69 +    }
    1.70 +
    1.71 +    /**
    1.72 +     * @throws IllegalStateException {@inheritDoc}
    1.73 +     * @throws UnsupportedOperationException {@inheritDoc}
    1.74 +     * @throws IOException {@inheritDoc}
    1.75 +     */
    1.76 +    public InputStream openInputStream() throws IOException {
    1.77 +        return fileObject.openInputStream();
    1.78 +    }
    1.79 +
    1.80 +    /**
    1.81 +     * @throws IllegalStateException {@inheritDoc}
    1.82 +     * @throws UnsupportedOperationException {@inheritDoc}
    1.83 +     * @throws IOException {@inheritDoc}
    1.84 +     */
    1.85 +    public OutputStream openOutputStream() throws IOException {
    1.86 +        return fileObject.openOutputStream();
    1.87 +    }
    1.88 +
    1.89 +    /**
    1.90 +     * @throws IllegalStateException {@inheritDoc}
    1.91 +     * @throws UnsupportedOperationException {@inheritDoc}
    1.92 +     * @throws IOException {@inheritDoc}
    1.93 +     */
    1.94 +    public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
    1.95 +        return fileObject.openReader(ignoreEncodingErrors);
    1.96 +    }
    1.97 +
    1.98 +    /**
    1.99 +     * @throws IllegalStateException {@inheritDoc}
   1.100 +     * @throws UnsupportedOperationException {@inheritDoc}
   1.101 +     * @throws IOException {@inheritDoc}
   1.102 +     */
   1.103 +    public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
   1.104 +        return fileObject.getCharContent(ignoreEncodingErrors);
   1.105 +    }
   1.106 +
   1.107 +    /**
   1.108 +     * @throws IllegalStateException {@inheritDoc}
   1.109 +     * @throws UnsupportedOperationException {@inheritDoc}
   1.110 +     * @throws IOException {@inheritDoc}
   1.111 +     */
   1.112 +    public Writer openWriter() throws IOException {
   1.113 +        return fileObject.openWriter();
   1.114 +    }
   1.115 +
   1.116 +    public long getLastModified() {
   1.117 +        return fileObject.getLastModified();
   1.118 +    }
   1.119 +
   1.120 +    public boolean delete() {
   1.121 +        return fileObject.delete();
   1.122 +    }
   1.123 +}

mercurial