1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.atlassian.theplugin.idea.util.memoryvfs;
18
19 import com.intellij.openapi.fileTypes.FileType;
20 import com.intellij.openapi.fileTypes.StdFileTypes;
21 import com.intellij.openapi.util.IconLoader;
22 import com.intellij.openapi.util.io.FileUtil;
23 import com.intellij.openapi.vfs.DeprecatedVirtualFile;
24 import com.intellij.openapi.vfs.VirtualFile;
25 import com.intellij.openapi.vfs.VirtualFileSystem;
26 import org.jetbrains.annotations.NonNls;
27 import org.jetbrains.annotations.NotNull;
28 import org.jetbrains.annotations.Nullable;
29
30 import javax.swing.*;
31 import java.io.*;
32
33
34
35
36
37
38 public class PlainTextMemoryVirtualFile extends DeprecatedVirtualFile {
39
40
41
42 private final String name;
43 private final String nameWithoutExtension;
44
45
46
47
48 private String content;
49
50
51
52
53 private boolean writable = false;
54
55 public PlainTextMemoryVirtualFile(@NotNull String name) {
56 this.name = name;
57 nameWithoutExtension = FileUtil.getNameWithoutExtension(name);
58 }
59
60
61
62
63
64
65
66
67 public PlainTextMemoryVirtualFile(@NotNull String name, String content) {
68 this.name = name;
69 nameWithoutExtension = FileUtil.getNameWithoutExtension(name);
70 this.content = content;
71 }
72
73
74
75
76 @NotNull
77 @NonNls
78 public String getName() {
79 return name;
80 }
81
82
83
84
85 @NotNull
86 public VirtualFileSystem getFileSystem() {
87 return PlainTextMemoryVirtualFileSystem.getInstance();
88 }
89
90
91
92
93 public String getPath() {
94 VirtualFile myParent = getParent();
95 return myParent == null ? name : myParent.getPath() + '/' + name;
96 }
97
98 @NotNull
99 public FileType getFileType() {
100 return StdFileTypes.PLAIN_TEXT;
101 }
102
103
104
105
106
107
108 public void setWritable(boolean writable) {
109 this.writable = writable;
110 }
111
112
113
114
115 public boolean isWritable() {
116 return writable;
117 }
118
119 public boolean isDirectory() {
120 return false;
121 }
122
123
124
125
126 public boolean isValid() {
127 return true;
128 }
129
130 @Nullable
131 public VirtualFile getParent() {
132 return null;
133 }
134
135 public VirtualFile[] getChildren() {
136 throw new UnsupportedOperationException("method getChidren");
137 }
138
139 public Icon getIcon() {
140 return IconLoader.getIcon("/icons/tab_bamboo.png");
141 }
142
143
144
145
146
147 public OutputStream getOutputStream(Object object, long l, long l1) throws IOException {
148 return new ByteArrayOutputStream();
149 }
150
151
152
153
154
155 public byte[] contentsToByteArray() throws IOException {
156 return content.getBytes();
157 }
158
159
160
161
162 public long getTimeStamp() {
163 return 0L;
164 }
165
166
167
168
169 public long getLength() {
170 return content.getBytes().length;
171 }
172
173
174
175
176 public void refresh(boolean b,
177 boolean b1,
178 Runnable runnable) {
179 }
180
181
182
183
184 public InputStream getInputStream() throws IOException {
185 return new ByteArrayInputStream(content.getBytes());
186 }
187
188
189
190
191
192
193 public void setContent(@NotNull String content) {
194 this.content = content;
195 }
196
197
198
199
200
201
202 @NotNull
203 public String getContent() {
204 return content;
205 }
206
207
208
209
210 public long getModificationStamp() {
211 return 0L;
212 }
213
214
215
216
217 @NotNull
218 public String getUrl() {
219 return Constants.PLAINTEXT_SCHEMA + getPath();
220 }
221
222 @NonNls
223 public String toString() {
224 return nameWithoutExtension;
225 }
226 }