KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > core > lib > StreamFileObject


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 package org.netbeans.modules.xml.core.lib;
20
21 import java.io.*;
22 import java.util.*;
23
24 import org.openide.filesystems.*;
25 import org.openide.filesystems.FileSystem;
26
27 /**
28  * This file object represents an InputStream.
29  *
30  * @author Petr Kuzel
31  * @version untested draft
32  */

33 public class StreamFileObject extends FileObject {
34
35     /** Serial Version UID */
36     private static final long serialVersionUID =8966806836211837503L;
37
38
39     private org.openide.filesystems.FileObject[] files; //kids
40

41     private boolean isRoot; //does it represent folder (root);
42

43     private InputStream peer; //wrapped input stream
44

45     private FileSystem fs;
46     
47     
48     //my filesystem
49

50     /** Creates new StreamFileObject */
51     public StreamFileObject(InputStream in) {
52         this(in, false);
53     }
54     
55     public StreamFileObject(InputStream in, boolean isRoot) {
56         this.isRoot = isRoot;
57         peer = in;
58         if (isRoot) {
59             files = new org.openide.filesystems.FileObject[] {
60                 new StreamFileObject(in)
61             };
62         } else {
63             files = new org.openide.filesystems.FileObject[0];
64         }
65         fs = new StreamFileSystem(this);
66     }
67
68     public org.openide.filesystems.FileObject[] getChildren() {
69         return files;
70     }
71     
72     public void removeFileChangeListener(org.openide.filesystems.FileChangeListener fileChangeListener) {
73     }
74     
75     public org.openide.filesystems.FileLock lock() throws java.io.IOException JavaDoc {
76         return FileLock.NONE;
77     }
78     
79     public java.lang.Object JavaDoc getAttribute(java.lang.String JavaDoc str) {
80         return null;
81     }
82     
83     public java.util.Date JavaDoc lastModified() {
84         return new Date(0L);
85     }
86     
87     public java.lang.String JavaDoc getExt() {
88         return "InputStream"; // NOI18N
89
}
90     
91     public boolean isReadOnly() {
92         return true;
93     }
94     
95     public org.openide.filesystems.FileObject createData(java.lang.String JavaDoc str, java.lang.String JavaDoc str1) throws java.io.IOException JavaDoc {
96         return null;
97     }
98     
99     public void delete(org.openide.filesystems.FileLock fileLock) throws java.io.IOException JavaDoc {
100     }
101     
102     public org.openide.filesystems.FileObject createFolder(java.lang.String JavaDoc str) throws java.io.IOException JavaDoc {
103         return null;
104     }
105     
106     public void rename(org.openide.filesystems.FileLock fileLock, java.lang.String JavaDoc str, java.lang.String JavaDoc str2) throws java.io.IOException JavaDoc {
107     }
108     
109     public boolean isData() {
110         return isRoot == false;
111     }
112     
113     public java.io.OutputStream JavaDoc getOutputStream(org.openide.filesystems.FileLock fileLock) throws java.io.IOException JavaDoc {
114         throw new IOException("r/o"); // NOI18N
115
}
116     
117     public java.io.InputStream JavaDoc getInputStream() throws java.io.FileNotFoundException JavaDoc {
118         return peer;
119     }
120     
121     public boolean isValid() {
122         return true;
123     }
124     
125     public java.util.Enumeration JavaDoc getAttributes() {
126         return org.openide.util.Enumerations.empty();
127     }
128     
129     public java.lang.String JavaDoc getName() {
130         return "StreamFileObject"; // NOI18N
131
}
132     
133     public void setImportant(boolean param) {
134     }
135     
136     public boolean isFolder() {
137         return isRoot;
138     }
139     
140     public void setAttribute(java.lang.String JavaDoc str, java.lang.Object JavaDoc obj) throws java.io.IOException JavaDoc {
141     }
142     
143     public void addFileChangeListener(org.openide.filesystems.FileChangeListener fileChangeListener) {
144     }
145     
146     public long getSize() {
147         return 766; //!!!
148
}
149     
150     public org.openide.filesystems.FileObject getParent() {
151         if (isRoot) return null;
152         return fs.getRoot();
153     }
154     
155     public boolean isRoot() {
156         return isRoot;
157     }
158     
159     public org.openide.filesystems.FileObject getFileObject(java.lang.String JavaDoc str, java.lang.String JavaDoc str1) {
160         return null;
161     }
162     
163     public org.openide.filesystems.FileSystem getFileSystem() throws org.openide.filesystems.FileStateInvalidException {
164         return fs;
165     }
166     
167 }
168
Popular Tags