|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
|
2 // Use of this source code is governed by a BSD-style license that can be |
|
3 // found in the LICENSE file. |
|
4 |
|
5 package org.chromium.debug.core.efs; |
|
6 |
|
7 import java.io.InputStream; |
|
8 import java.io.OutputStream; |
|
9 import java.net.URI; |
|
10 |
|
11 import org.eclipse.core.filesystem.IFileInfo; |
|
12 import org.eclipse.core.filesystem.IFileStore; |
|
13 import org.eclipse.core.filesystem.provider.FileStore; |
|
14 import org.eclipse.core.runtime.CoreException; |
|
15 import org.eclipse.core.runtime.IPath; |
|
16 import org.eclipse.core.runtime.IProgressMonitor; |
|
17 |
|
18 /** |
|
19 * A script file store. Delegates all operations to the ChromiumScriptStorage |
|
20 * instance. |
|
21 */ |
|
22 public class ChromiumScriptFileStore extends FileStore { |
|
23 |
|
24 /** The filesystem storage. */ |
|
25 private static final ChromiumScriptStorage STORAGE = ChromiumScriptStorage.getInstance(); |
|
26 |
|
27 /** The host filesystem of this resource. */ |
|
28 private final ChromiumScriptFileSystem fileSystem; |
|
29 |
|
30 /** The resource path in the filesystem. */ |
|
31 private final IPath path; |
|
32 |
|
33 /** |
|
34 * Constructs a proxy for a real resource (which might not exist). |
|
35 * |
|
36 * @param fileSystem that stores the resource |
|
37 * @param path of the resource |
|
38 */ |
|
39 public ChromiumScriptFileStore(ChromiumScriptFileSystem fileSystem, IPath path) { |
|
40 this.fileSystem = fileSystem; |
|
41 this.path = path; |
|
42 } |
|
43 |
|
44 @Override |
|
45 public String[] childNames(int options, IProgressMonitor monitor) throws CoreException { |
|
46 return STORAGE.childNames(this.path); |
|
47 } |
|
48 |
|
49 @Override |
|
50 public IFileInfo fetchInfo(int options, IProgressMonitor monitor) throws CoreException { |
|
51 return STORAGE.fetchInfo(path, options); |
|
52 } |
|
53 |
|
54 @Override |
|
55 public IFileStore getChild(String name) { |
|
56 return fileSystem.getStore(path.append(name)); |
|
57 } |
|
58 |
|
59 @Override |
|
60 public String getName() { |
|
61 if (path.isEmpty()) { |
|
62 return "ROOT"; //$NON-NLS-1$ |
|
63 } |
|
64 return path.lastSegment(); |
|
65 } |
|
66 |
|
67 @Override |
|
68 public IFileStore getParent() { |
|
69 if (path.segmentCount() == 0) { |
|
70 return null; |
|
71 } |
|
72 return new ChromiumScriptFileStore(fileSystem, path.removeLastSegments(1)); |
|
73 } |
|
74 |
|
75 @Override |
|
76 public InputStream openInputStream(int options, IProgressMonitor monitor) throws CoreException { |
|
77 return STORAGE.openInputStream(path, options); |
|
78 } |
|
79 |
|
80 @Override |
|
81 public OutputStream openOutputStream(int options, IProgressMonitor monitor) throws CoreException { |
|
82 return STORAGE.openOutputStream(path, options); |
|
83 } |
|
84 |
|
85 @Override |
|
86 public IFileStore mkdir(int options, IProgressMonitor monitor) throws CoreException { |
|
87 STORAGE.mkdir(path, options); |
|
88 return this; |
|
89 } |
|
90 |
|
91 @Override |
|
92 public URI toURI() { |
|
93 return ChromiumScriptFileSystem.getFileStoreUri(path); |
|
94 } |
|
95 |
|
96 @Override |
|
97 public void delete(int options, IProgressMonitor monitor) throws CoreException { |
|
98 STORAGE.delete(path, options); |
|
99 } |
|
100 |
|
101 @Override |
|
102 public void putInfo(IFileInfo info, int options, IProgressMonitor monitor) throws CoreException { |
|
103 STORAGE.putInfo(path, info, options); |
|
104 } |
|
105 |
|
106 } |