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