KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > tools > ForwardingFileObject


1 /*
2  * @(#)ForwardingFileObject.java 1.7 06/05/05
3  *
4  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.tools;
9
10 import java.io.IOException JavaDoc;
11 import java.io.InputStream JavaDoc;
12 import java.io.OutputStream JavaDoc;
13 import java.io.Reader JavaDoc;
14 import java.io.Writer JavaDoc;
15 import java.net.URI JavaDoc;
16
17 /**
18  * Forwards calls to a given file object. Subclasses of this class
19  * might override some of these methods and might also provide
20  * additional fields and methods.
21  *
22  * @param <F> the kind of file object forwarded to by this object
23  * @author Peter von der Ah&eacute;
24  * @since 1.6
25  */

26 public class ForwardingFileObject<F extends FileObject> implements FileObject {
27
28     /**
29      * The file object which all methods are delegated to.
30      */

31     protected final F fileObject;
32
33     /**
34      * Creates a new instance of ForwardingFileObject.
35      * @param fileObject delegate to this file object
36      */

37     protected ForwardingFileObject(F fileObject) {
38         fileObject.getClass(); // null check
39
this.fileObject = fileObject;
40     }
41
42     public URI JavaDoc toUri() {
43         return fileObject.toUri();
44     }
45
46     public String JavaDoc getName() {
47         return fileObject.getName();
48     }
49
50     /**
51      * @throws IllegalStateException {@inheritDoc}
52      * @throws UnsupportedOperationException {@inheritDoc}
53      * @throws IOException {@inheritDoc}
54      */

55     public InputStream JavaDoc openInputStream() throws IOException JavaDoc {
56         return fileObject.openInputStream();
57     }
58
59     /**
60      * @throws IllegalStateException {@inheritDoc}
61      * @throws UnsupportedOperationException {@inheritDoc}
62      * @throws IOException {@inheritDoc}
63      */

64     public OutputStream JavaDoc openOutputStream() throws IOException JavaDoc {
65         return fileObject.openOutputStream();
66     }
67
68     /**
69      * @throws IllegalStateException {@inheritDoc}
70      * @throws UnsupportedOperationException {@inheritDoc}
71      * @throws IOException {@inheritDoc}
72      */

73     public Reader JavaDoc openReader(boolean ignoreEncodingErrors) throws IOException JavaDoc {
74         return fileObject.openReader(ignoreEncodingErrors);
75     }
76
77     /**
78      * @throws IllegalStateException {@inheritDoc}
79      * @throws UnsupportedOperationException {@inheritDoc}
80      * @throws IOException {@inheritDoc}
81      */

82     public CharSequence JavaDoc getCharContent(boolean ignoreEncodingErrors) throws IOException JavaDoc {
83         return fileObject.getCharContent(ignoreEncodingErrors);
84     }
85
86     /**
87      * @throws IllegalStateException {@inheritDoc}
88      * @throws UnsupportedOperationException {@inheritDoc}
89      * @throws IOException {@inheritDoc}
90      */

91     public Writer JavaDoc openWriter() throws IOException JavaDoc {
92         return fileObject.openWriter();
93     }
94
95     public long getLastModified() {
96         return fileObject.getLastModified();
97     }
98
99     public boolean delete() {
100         return fileObject.delete();
101     }
102 }
103
Popular Tags