1 /*******************************************************************************
2  * Copyright (c) 2009, 2014 IBM Corporation and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *     James Blackburn - Fix for bug 266712
14  *******************************************************************************/
15 package org.eclipse.core.internal.resources;
16 
17 import java.io.InputStream;
18 import java.net.URI;
19 import org.eclipse.core.filesystem.*;
20 import org.eclipse.core.filesystem.provider.FileInfo;
21 import org.eclipse.core.filesystem.provider.FileStore;
22 import org.eclipse.core.runtime.*;
23 
24 /**
25  * A file store representing a virtual resource.
26  * A virtual resource always exists and has no children.
27  */
28 public class VirtualFileStore extends FileStore {
29 	private final URI location;
30 
VirtualFileStore(URI location)31 	public VirtualFileStore(URI location) {
32 		this.location = location;
33 	}
34 
35 	@Override
childNames(int options, IProgressMonitor monitor)36 	public String[] childNames(int options, IProgressMonitor monitor) {
37 		return FileStore.EMPTY_STRING_ARRAY;
38 	}
39 
40 	@Override
fetchInfo(int options, IProgressMonitor monitor)41 	public IFileInfo fetchInfo(int options, IProgressMonitor monitor) {
42 		FileInfo result = new FileInfo();
43 		result.setDirectory(true);
44 		result.setExists(true);
45 		result.setLastModified(1);//last modified of zero indicates non-existence
46 		return result;
47 	}
48 
49 	@Override
delete(int options, IProgressMonitor monitor)50 	public void delete(int options, IProgressMonitor monitor) {
51 		//nothing to do - virtual resources don't exist in any physical file system
52 	}
53 
54 	@Override
getChild(String name)55 	public IFileStore getChild(String name) {
56 		return EFS.getNullFileSystem().getStore(new Path(name).makeAbsolute());
57 	}
58 
59 	@Override
getName()60 	public String getName() {
61 		return "virtual"; //$NON-NLS-1$
62 	}
63 
64 	@Override
getParent()65 	public IFileStore getParent() {
66 		return null;
67 	}
68 
69 	@Override
move(IFileStore destination, int options, IProgressMonitor monitor)70 	public void move(IFileStore destination, int options, IProgressMonitor monitor) throws CoreException {
71 		destination.mkdir(EFS.NONE, monitor);
72 	}
73 
74 	@Override
openInputStream(int options, IProgressMonitor monitor)75 	public InputStream openInputStream(int options, IProgressMonitor monitor) {
76 		return null;
77 	}
78 
79 	@Override
toURI()80 	public URI toURI() {
81 		return location;
82 	}
83 }
84