KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > filesystem > NullFileStore


1 /*******************************************************************************
2  * Copyright (c) 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.internal.filesystem;
12
13 import java.io.*;
14 import java.net.URI JavaDoc;
15 import java.net.URISyntaxException JavaDoc;
16 import org.eclipse.core.filesystem.*;
17 import org.eclipse.core.filesystem.provider.FileInfo;
18 import org.eclipse.core.filesystem.provider.FileStore;
19 import org.eclipse.core.runtime.*;
20
21 /**
22  * A null file store represents a file whose location is unknown,
23  * such as a location based on an undefined variable. This store
24  * acts much like /dev/null on *nix: writes are ignored, reads return
25  * empty streams, and modifications such as delete, mkdir, will fail.
26  */

27 public class NullFileStore extends FileStore {
28     private IPath path;
29
30     /**
31      * Creates a null file store
32      * @param path The path of the file in this store
33      */

34     public NullFileStore(IPath path) {
35         this.path = path;
36     }
37
38     public IFileInfo[] childInfos(int options, IProgressMonitor monitor) throws CoreException {
39         return EMPTY_FILE_INFO_ARRAY;
40     }
41
42     public String JavaDoc[] childNames(int options, IProgressMonitor monitor) {
43         return EMPTY_STRING_ARRAY;
44     }
45
46     public void delete(int options, IProgressMonitor monitor) throws CoreException {
47         //super implementation will always fail
48
super.delete(options, monitor);
49     }
50
51     public IFileInfo fetchInfo(int options, IProgressMonitor monitor) {
52         FileInfo result = new FileInfo(getName());
53         result.setExists(false);
54         return result;
55     }
56
57     public IFileStore getChild(String JavaDoc name) {
58         return new NullFileStore(path.append(name));
59     }
60
61     public IFileSystem getFileSystem() {
62         return NullFileSystem.getInstance();
63     }
64
65     public String JavaDoc getName() {
66         return String.valueOf(path.lastSegment());
67     }
68
69     public IFileStore getParent() {
70         return path.segmentCount() == 0 ? null : new NullFileStore(path.removeLastSegments(1));
71     }
72
73     public IFileStore mkdir(int options, IProgressMonitor monitor) throws CoreException {
74         //super implementation will always fail
75
return super.mkdir(options, monitor);
76     }
77
78     public InputStream openInputStream(int options, IProgressMonitor monitor) throws CoreException {
79         return new ByteArrayInputStream(new byte[0]);
80     }
81
82     public OutputStream openOutputStream(int options, IProgressMonitor monitor) throws CoreException {
83         return new OutputStream() {
84             public void write(int b) throws IOException {
85                 //do nothing
86
}
87         };
88     }
89
90     public void putInfo(IFileInfo info, int options, IProgressMonitor monitor) throws CoreException {
91         //super implementation will always fail
92
super.putInfo(info, options, monitor);
93     }
94
95     public String JavaDoc toString() {
96         return path.toString();
97     }
98
99     public URI JavaDoc toURI() {
100         try {
101             return new URI JavaDoc(EFS.SCHEME_NULL, null, path.toString(), null);
102         } catch (URISyntaxException JavaDoc e) {
103             //should not happen
104
throw new Error JavaDoc(e);
105         }
106     }
107 }
108
Popular Tags