KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > source > parsing > OutputFileObject


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.java.source.parsing;
21
22
23 import java.io.File JavaDoc;
24 import java.io.FileInputStream JavaDoc;
25 import java.io.FileOutputStream JavaDoc;
26 import java.io.FileReader JavaDoc;
27 import java.io.FileWriter JavaDoc;
28 import java.net.URI JavaDoc;
29
30 /**
31  *
32  * @author Tomas Zezula
33  */

34 public class OutputFileObject extends FileObjects.FileBase {
35
36     private final File JavaDoc baseFolder;
37
38
39     public static OutputFileObject create (final File JavaDoc baseFolder, final File JavaDoc diskDelegate) {
40         assert baseFolder != null && diskDelegate != null;
41         String JavaDoc[] pkgNamePair = FileObjects.getFolderAndBaseName(FileObjects.getRelativePath(baseFolder,diskDelegate),File.separatorChar);
42         return new OutputFileObject (baseFolder, diskDelegate, FileObjects.convertFolder2Package(pkgNamePair[0],File.separatorChar), pkgNamePair[1]);
43     }
44     
45     /** Creates a new instance of ClassUpdateFileObject */
46    private OutputFileObject (final File JavaDoc baseFolder, final File JavaDoc diskDelegate, final String JavaDoc packageName, final String JavaDoc baseName) {
47         super (diskDelegate, packageName, baseName);
48         this.baseFolder = baseFolder;
49     }
50
51     public java.nio.CharBuffer JavaDoc getCharContent(boolean ignoreEncodingErrors) throws java.io.IOException JavaDoc {
52         throw new UnsupportedOperationException JavaDoc ("Binary file");
53     }
54
55     public boolean delete() {
56         return this.f.delete();
57     }
58
59     public String JavaDoc getPath() {
60         return this.f.getPath();
61     }
62     
63     public URI JavaDoc toUri () {
64         return this.f.toURI();
65     }
66
67     public long getLastModified() {
68         return this.f.lastModified();
69     }
70
71     public java.io.InputStream JavaDoc openInputStream() throws java.io.IOException JavaDoc {
72         return new FileInputStream JavaDoc (this.f);
73     }
74
75     public java.io.OutputStream JavaDoc openOutputStream() throws java.io.IOException JavaDoc {
76         return new FileOutputStream JavaDoc (f);
77     }
78
79     public java.io.Reader JavaDoc openReader(boolean b) throws java.io.IOException JavaDoc {
80         return new FileReader JavaDoc (this.f);
81     }
82
83     public java.io.Writer JavaDoc openWriter() throws java.io.IOException JavaDoc {
84         return new FileWriter JavaDoc (this.f);
85     }
86     
87     public @Override JavaDoc String JavaDoc toString () {
88         return this.f.getAbsolutePath();
89     }
90     
91     public @Override JavaDoc boolean equals (Object JavaDoc other) {
92         if (other instanceof OutputFileObject) {
93             OutputFileObject ofo = (OutputFileObject) other;
94             return this.baseFolder.equals(ofo.baseFolder) &&
95                    this.f.equals(ofo.f);
96         }
97         return false;
98     }
99     
100     public @Override JavaDoc int hashCode () {
101         return this.f.hashCode();
102     }
103 }
104
Popular Tags