This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 46701
Collapse All | Expand All

(-)openide/src/org/openide/filesystems/ExternalUtil.java (-1 / +1 lines)
Lines 112-118 Link Here
112
        
112
        
113
        if (repository == null) {
113
        if (repository == null) {
114
            // if not provided use default one
114
            // if not provided use default one
115
            repository = new Repository (new XMLFileSystem ());
115
            repository = new Repository (FileUtil.createMemoryFileSystem ());
116
        }        
116
        }        
117
    }
117
    }
118
        
118
        
(-)openide/src/org/openide/filesystems/FileUtil.java (+8 lines)
Lines 102-107 Link Here
102
    // public methods
102
    // public methods
103
    //
103
    //
104
104
105
    /** Factory method that creates an empty implementation of a filesystem that
106
     * completely resides in a memory.
107
     * @return a filesystem
108
     * @since JST-PENDING
109
     */
110
    public static FileSystem createMemoryFileSystem () {
111
        return new MemoryFileSystem ();
112
    }
105
113
106
    /** Copies file to the selected folder.
114
    /** Copies file to the selected folder.
107
    * This implementation simply copies the file by stream content.
115
    * This implementation simply copies the file by stream content.
(-)openide/src/org/openide/filesystems/MemoryFileSystem.java (+229 lines)
Added Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.openide.filesystems;
15
16
import java.beans.*;
17
import java.io.*;
18
import java.util.*;
19
20
21
import org.openide.filesystems.*;
22
import org.openide.filesystems.AbstractFileSystem.*;
23
24
25
/**
26
 * Simple implementation of memory file system.
27
 * @author Jaroslav Tulach
28
 */
29
final class MemoryFileSystem extends AbstractFileSystem implements Info, Change, AbstractFileSystem.List, Attr {
30
    /** time when the filesystem was created. It is supposed to be the default
31
     * time of modification for all resources that has not been modified yet
32
     */
33
    private java.util.Date created = new java.util.Date ();
34
    
35
    static final class Entry {
36
        /** String, Object */
37
        public HashMap attrs = new HashMap ();
38
        public byte[] data;
39
        public java.util.Date last;
40
    }
41
    
42
    /** maps String to Entry */
43
    private Hashtable entries = new Hashtable ();
44
    
45
    /** finds entry for given name */
46
    private Entry e (String n) {
47
        if (n.length() > 0  && n.charAt(0) == '/') n = n.substring (1);
48
        
49
        Entry x = (Entry)entries.get (n);
50
        if (x == null) {
51
            x = new Entry ();
52
            entries.put (n, x);
53
        }                             
54
        return x;
55
    }
56
57
    /** finds whether there already is this name */
58
    private boolean is (String n) {
59
        if (n.length() > 0  && n.charAt(0) == '/') n = n.substring (1);
60
        Entry x = (Entry)entries.get (n);
61
        return x != null;
62
    }
63
    
64
    /** Creates new MemoryFS */
65
    public MemoryFileSystem() {
66
        attr = this;
67
        list = this;
68
        change = this;
69
        info = this;
70
        
71
        try {
72
            setSystemName("MemoryFileSystem");
73
        } catch (PropertyVetoException ex) {
74
            ex.printStackTrace();
75
        }
76
    }
77
    
78
    /** Creates MemoryFS with data */
79
    public MemoryFileSystem(String[] resources) {
80
        this ();
81
        
82
        StringBuffer sb = new StringBuffer ();
83
        
84
        for (int i = 0; i < resources.length; i++) {                        
85
            sb.append (resources[i]);
86
            
87
            if (resources[i].endsWith("/")) {
88
                // folder
89
                e (resources[i]).data = null;
90
            }
91
            else {
92
                e (resources[i]).data = new byte[0];
93
            }
94
        }
95
    }
96
    
97
    
98
    
99
    public String getDisplayName() {
100
        return "MemoryFileSystem";
101
    }
102
103
    public boolean isReadOnly() {
104
        return false;
105
    }
106
    
107
    public Enumeration attributes(String name) {
108
        return Collections.enumeration (e (name).attrs.keySet ());
109
    }
110
    
111
    public String[] children(String f) {
112
        if (f.length () > 0 && f.charAt(0) == '/') f = f.substring (1);
113
        if (f.length () > 0 && !f.endsWith ("/")) f = f + "/";
114
        
115
        HashSet l = new HashSet ();
116
        //System.out.println("Folder: " + f);
117
        
118
        Iterator it = entries.keySet().iterator ();
119
        while (it.hasNext ()) {
120
            String name = (String)it.next();
121
            
122
            if (name.startsWith(f) || f.trim().length() == 0) {
123
                int i = name.indexOf ('/', f.length ());
124
                String child = null; 
125
                if (i > 0) {
126
                    child = name.substring (f.length (), i);
127
                } else {
128
                    child = name.substring (f.length ());
129
                }
130
                
131
                if (child.trim().length() > 0) {
132
                    l.add (child);
133
                }
134
            }
135
        }
136
        
137
        return (String[])l.toArray (new String[0]);
138
    }
139
    
140
    public void createData(String name) throws IOException {
141
        if (is(name)) throw new IOException("File already exists");
142
        e (name).data = new byte[0];
143
    }
144
    
145
    public void createFolder(String name) throws java.io.IOException {
146
        if (is(name)) throw new IOException("File already exists");
147
        e (name).data = null;
148
    }
149
    
150
    public void delete(String name) throws IOException {
151
        entries.remove (name);
152
    }
153
    
154
    public void deleteAttributes(String name) {
155
    }
156
    
157
    public boolean folder(String name) {
158
        return e (name).data == null;
159
    }
160
    
161
    public InputStream inputStream(String name) throws java.io.FileNotFoundException {
162
        byte[] arr = e (name).data;
163
        if (arr == null) {
164
            arr = new byte[0];
165
        }
166
        return new ByteArrayInputStream (arr);
167
    }
168
    
169
    public java.util.Date lastModified(String name) {
170
        java.util.Date d = e (name).last;
171
        return d == null ? created : d;
172
    }
173
    
174
    public void lock(String name) throws IOException {
175
    }
176
    
177
    public void markUnimportant(String name) {
178
    }
179
    
180
    public String mimeType(String name) {
181
        return (String)e (name).attrs.get ("mimeType");
182
    }
183
    
184
    public OutputStream outputStream(final String name) throws java.io.IOException {
185
        class Out extends ByteArrayOutputStream {
186
            public void close () throws IOException {
187
                super.close ();
188
                
189
                e (name).data = toByteArray ();
190
                e (name).last = new Date ();
191
            }
192
        }
193
        
194
        return new Out ();
195
    }
196
    
197
    public Object readAttribute(String name, String attrName) {
198
        return e (name).attrs.get (attrName);
199
    }
200
    
201
    public boolean readOnly(String name) {
202
        return false;
203
    }
204
    
205
    public void rename(String oldName, String newName) throws IOException {
206
        if (! is(oldName)) throw new IOException("The file to rename does not exist.");
207
        if (is(newName)) throw new IOException("Cannot rename to existing file");
208
        if (newName.length () > 0 && newName.charAt(0) == '/') newName = newName.substring (1);
209
        Entry e = e (oldName);
210
        entries.remove(oldName);
211
        entries.put (newName, e);
212
    }
213
    
214
    public void renameAttributes(String oldName, String newName) {
215
    }
216
    
217
    public long size(String name) {
218
        byte[] d = e (name).data;
219
        
220
        return d == null ? 0 : d.length;
221
    }
222
    
223
    public void unlock(String name) {
224
    }
225
    
226
    public void writeAttribute(String name, String attrName, Object value) throws IOException {
227
        e (name).attrs.put (attrName, value);
228
    }    
229
}
(-)openide/test/unit/src/org/openide/filesystems/MemoryFileSystemTest.java (+54 lines)
Added Link Here
1
/*
2
 *                 Sun Public License Notice
3
 *
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.openide.filesystems;
15
16
import junit.framework.*;
17
import java.io.IOException;
18
import java.util.*;
19
import org.netbeans.junit.*;
20
21
import org.openide.filesystems.*;
22
23
/**
24
 *
25
 * @author  David Strupl
26
 * @version
27
 */
28
public class MemoryFileSystemTest extends FileSystemFactoryHid {
29
    /** Creates new JarFileSystemTest */
30
    public MemoryFileSystemTest(Test test) {
31
        super(test);
32
    }
33
    
34
    public static void main(String args[]) {
35
        junit.textui.TestRunner.run(suite());
36
    }
37
    
38
    public static Test suite() {
39
        NbTestSuite suite = new NbTestSuite();
40
        suite.addTestSuite(RepositoryTestHid.class);
41
        suite.addTestSuite(FileSystemTestHid.class);
42
        suite.addTestSuite(FileObjectTestHid.class);
43
        
44
        return new MemoryFileSystemTest(suite);
45
    }
46
    
47
    
48
    protected void destroyFileSystem(String testName) throws IOException {
49
    }
50
    
51
    protected FileSystem[] createFileSystem(String testName, String[] resources) throws IOException{
52
        return new FileSystem[] {new MemoryFileSystem(resources)};
53
    }
54
}
(-)core/src/org/netbeans/core/projects/MemoryFileSystem.java (-229 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.core.projects;
15
16
import java.beans.*;
17
import java.io.*;
18
import java.util.*;
19
20
21
import org.openide.filesystems.*;
22
import org.openide.filesystems.AbstractFileSystem.*;
23
24
25
/**
26
 * Simple implementation of memory file system.
27
 * @author Jaroslav Tulach
28
 */
29
public final class MemoryFileSystem extends AbstractFileSystem implements Info, Change, AbstractFileSystem.List, Attr {
30
    /** time when the filesystem was created. It is supposed to be the default
31
     * time of modification for all resources that has not been modified yet
32
     */
33
    private java.util.Date created = new java.util.Date ();
34
    
35
    static final class Entry {
36
        /** String, Object */
37
        public HashMap attrs = new HashMap ();
38
        public byte[] data;
39
        public java.util.Date last;
40
    }
41
    
42
    /** maps String to Entry */
43
    private Hashtable entries = new Hashtable ();
44
    
45
    /** finds entry for given name */
46
    private Entry e (String n) {
47
        if (n.length() > 0  && n.charAt(0) == '/') n = n.substring (1);
48
        
49
        Entry x = (Entry)entries.get (n);
50
        if (x == null) {
51
            x = new Entry ();
52
            entries.put (n, x);
53
        }                             
54
        return x;
55
    }
56
57
    /** finds whether there already is this name */
58
    private boolean is (String n) {
59
        if (n.length() > 0  && n.charAt(0) == '/') n = n.substring (1);
60
        Entry x = (Entry)entries.get (n);
61
        return x != null;
62
    }
63
    
64
    /** Creates new MemoryFS */
65
    public MemoryFileSystem() {
66
        attr = this;
67
        list = this;
68
        change = this;
69
        info = this;
70
        
71
        try {
72
            setSystemName("MemoryFileSystem");
73
        } catch (PropertyVetoException ex) {
74
            ex.printStackTrace();
75
        }
76
    }
77
    
78
    /** Creates MemoryFS with data */
79
    public MemoryFileSystem(String[] resources) {
80
        this ();
81
        
82
        StringBuffer sb = new StringBuffer ();
83
        
84
        for (int i = 0; i < resources.length; i++) {                        
85
            sb.append (resources[i]);
86
            
87
            if (resources[i].endsWith("/")) {
88
                // folder
89
                e (resources[i]).data = null;
90
            }
91
            else {
92
                e (resources[i]).data = new byte[0];
93
            }
94
        }
95
    }
96
    
97
    
98
    
99
    public String getDisplayName() {
100
        return "MemoryFileSystem";
101
    }
102
103
    public boolean isReadOnly() {
104
        return false;
105
    }
106
    
107
    public Enumeration attributes(String name) {
108
        return Collections.enumeration (e (name).attrs.keySet ());
109
    }
110
    
111
    public String[] children(String f) {
112
        if (f.length () > 0 && f.charAt(0) == '/') f = f.substring (1);
113
        if (f.length () > 0 && !f.endsWith ("/")) f = f + "/";
114
        
115
        HashSet l = new HashSet ();
116
        //System.out.println("Folder: " + f);
117
        
118
        Iterator it = entries.keySet().iterator ();
119
        while (it.hasNext ()) {
120
            String name = (String)it.next();
121
            
122
            if (name.startsWith(f) || f.trim().length() == 0) {
123
                int i = name.indexOf ('/', f.length ());
124
                String child = null; 
125
                if (i > 0) {
126
                    child = name.substring (f.length (), i);
127
                } else {
128
                    child = name.substring (f.length ());
129
                }
130
                
131
                if (child.trim().length() > 0) {
132
                    l.add (child);
133
                }
134
            }
135
        }
136
        
137
        return (String[])l.toArray (new String[0]);
138
    }
139
    
140
    public void createData(String name) throws IOException {
141
        if (is(name)) throw new IOException("File already exists");
142
        e (name).data = new byte[0];
143
    }
144
    
145
    public void createFolder(String name) throws java.io.IOException {
146
        if (is(name)) throw new IOException("File already exists");
147
        e (name).data = null;
148
    }
149
    
150
    public void delete(String name) throws IOException {
151
        entries.remove (name);
152
    }
153
    
154
    public void deleteAttributes(String name) {
155
    }
156
    
157
    public boolean folder(String name) {
158
        return e (name).data == null;
159
    }
160
    
161
    public InputStream inputStream(String name) throws java.io.FileNotFoundException {
162
        byte[] arr = e (name).data;
163
        if (arr == null) {
164
            arr = new byte[0];
165
        }
166
        return new ByteArrayInputStream (arr);
167
    }
168
    
169
    public java.util.Date lastModified(String name) {
170
        java.util.Date d = e (name).last;
171
        return d == null ? created : d;
172
    }
173
    
174
    public void lock(String name) throws IOException {
175
    }
176
    
177
    public void markUnimportant(String name) {
178
    }
179
    
180
    public String mimeType(String name) {
181
        return (String)e (name).attrs.get ("mimeType");
182
    }
183
    
184
    public OutputStream outputStream(final String name) throws java.io.IOException {
185
        class Out extends ByteArrayOutputStream {
186
            public void close () throws IOException {
187
                super.close ();
188
                
189
                e (name).data = toByteArray ();
190
                e (name).last = new Date ();
191
            }
192
        }
193
        
194
        return new Out ();
195
    }
196
    
197
    public Object readAttribute(String name, String attrName) {
198
        return e (name).attrs.get (attrName);
199
    }
200
    
201
    public boolean readOnly(String name) {
202
        return false;
203
    }
204
    
205
    public void rename(String oldName, String newName) throws IOException {
206
        if (! is(oldName)) throw new IOException("The file to rename does not exist.");
207
        if (is(newName)) throw new IOException("Cannot rename to existing file");
208
        if (newName.length () > 0 && newName.charAt(0) == '/') newName = newName.substring (1);
209
        Entry e = e (oldName);
210
        entries.remove(e);
211
        entries.put (newName, e);
212
    }
213
    
214
    public void renameAttributes(String oldName, String newName) {
215
    }
216
    
217
    public long size(String name) {
218
        byte[] d = e (name).data;
219
        
220
        return d == null ? 0 : d.length;
221
    }
222
    
223
    public void unlock(String name) {
224
    }
225
    
226
    public void writeAttribute(String name, String attrName, Object value) throws IOException {
227
        e (name).attrs.put (attrName, value);
228
    }    
229
}
(-)core/src/org/netbeans/core/projects/SystemFileSystem.java (-1 / +1 lines)
Lines 293-299 Link Here
293
            user = l;
293
            user = l;
294
        } else {
294
        } else {
295
            // use some replacement
295
            // use some replacement
296
            user = new MemoryFileSystem();
296
            user = FileUtil.createMemoryFileSystem ();
297
        }
297
        }
298
298
299
        if (homeDir == null) {
299
        if (homeDir == null) {

Return to bug 46701