1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.millscript.commons.vfs.util;
22
23 import org.millscript.commons.vfs.VFile;
24 import org.millscript.commons.vfs.VFolder;
25 import org.millscript.commons.vfs.VVolume;
26 import org.millscript.commons.vfs.mime.MIMETypeHandler;
27
28 import java.io.FileDescriptor;
29 import java.io.FileInputStream;
30 import java.io.FileOutputStream;
31 import java.io.InputStream;
32 import java.io.InputStreamReader;
33 import java.io.OutputStream;
34 import java.io.OutputStreamWriter;
35 import java.io.Reader;
36 import java.io.Writer;
37 import java.net.URI;
38
39 import javax.activation.FileTypeMap;
40
41
42 /**
43 * The standard system console as a virtual file. I'm not sure how useful this
44 * really is, or how technically correct.
45 */
46 public class StandardConsoleFile implements VFile {
47
48 private static final URI CONSOLE_URI = URI.create( "system:console" );
49
50 /**
51 * The file type map for determining the MIME type of a file, based on file
52 * extension.
53 */
54 private static final FileTypeMap MIME_TYPES = FileTypeMap.getDefaultFileTypeMap();
55
56 private static final String NAME = "System::Console";
57
58 /**
59 * @see org.millscript.commons.vfs.VEntry#appendAbsolutePath(java.lang.StringBuffer)
60 */
61 public StringBuffer appendAbsolutePath( StringBuffer buffer ) {
62 return buffer.append( NAME );
63 }
64
65 /**
66 * @see org.millscript.commons.vfs.VEntry#appendAbsolutePathOnVolume(java.lang.StringBuffer)
67 */
68 public StringBuffer appendAbsolutePathOnVolume( StringBuffer buffer ) {
69 return buffer.append( NAME );
70 }
71
72 /**
73 * @see org.millscript.commons.vfs.VEntry#appendRelativePath(java.lang.StringBuffer)
74 */
75 public StringBuffer appendRelativePath( StringBuffer buffer ) {
76 return buffer.append( NAME );
77 }
78
79 /**
80 * @see org.millscript.commons.vfs.VEntry#appendRelativePathOnVolume(java.lang.StringBuffer)
81 */
82 public StringBuffer appendRelativePathOnVolume( StringBuffer buffer ) {
83 return buffer.append( NAME );
84 }
85
86 /**
87 * @see org.millscript.commons.vfs.VEntry#appendURI(java.lang.StringBuffer)
88 */
89 public StringBuffer appendURI( StringBuffer buffer ) {
90 return buffer.append( CONSOLE_URI.toString() );
91 }
92
93 /**
94 * @see org.millscript.commons.vfs.VEntry#exists()
95 */
96 public boolean exists() {
97
98 return true;
99 }
100
101 /**
102 * @see org.millscript.commons.vfs.VEntry#getAbsolutePath()
103 */
104 public String getAbsolutePath() {
105 return "/";
106 }
107
108 /**
109 * @see org.millscript.commons.vfs.VEntry#getAbsolutePathOnVolume()
110 */
111 public String getAbsolutePathOnVolume() {
112 return "/";
113 }
114
115 /**
116 * @see org.millscript.commons.vfs.VFile#getAppendOutputStream()
117 */
118 public OutputStream getAppendOutputStream() {
119 return new FileOutputStream( FileDescriptor.out );
120 }
121
122 /**
123 * @see org.millscript.commons.vfs.VFile#getAppendWriter()
124 */
125 public Writer getAppendWriter() {
126 return new OutputStreamWriter(
127 this.getAppendOutputStream(),
128 this.getVolume().getParentVFS().getDefaultCharset()
129 );
130 }
131
132 /**
133 * @see org.millscript.commons.vfs.VFile#getContentMIMEType()
134 */
135 public String getContentMIMEType() {
136 return "application/octet-stream";
137 }
138
139 /**
140 * @see org.millscript.commons.vfs.VFile#getInputStream()
141 */
142 public InputStream getInputStream() {
143 return new FileInputStream( FileDescriptor.in );
144 }
145
146 /**
147 * @see org.millscript.commons.vfs.VEntry#getMIMEType(java.lang.String)
148 */
149 public String getMIMEType( String fileName ) {
150 return MIME_TYPES.getContentType( fileName );
151 }
152
153 /**
154 * @see org.millscript.commons.vfs.VEntry#getMIMETypeHandler(java.lang.String)
155 */
156 public MIMETypeHandler getMIMETypeHandler( String type ) {
157
158 return null;
159 }
160
161 /**
162 * @see org.millscript.commons.vfs.VEntry#getName()
163 */
164 public String getName() {
165
166 return null;
167 }
168
169 /**
170 * @see org.millscript.commons.vfs.VFile#getOutputStream()
171 */
172 public OutputStream getOutputStream() {
173 return new FileOutputStream( FileDescriptor.out );
174 }
175
176 /**
177 * @see org.millscript.commons.vfs.VEntry#getParent()
178 */
179 public VFolder getParent() {
180 return null;
181 }
182
183 /**
184 * @see org.millscript.commons.vfs.VFile#getReader()
185 */
186 public Reader getReader() {
187 return new InputStreamReader(
188 this.getInputStream(),
189 this.getVolume().getParentVFS().getDefaultCharset()
190 );
191 }
192
193 /**
194 * @see org.millscript.commons.vfs.VEntry#getRelativePath()
195 */
196 public String getRelativePath() {
197 return "/";
198 }
199
200 /**
201 * @see org.millscript.commons.vfs.VEntry#getRelativePathOnVolume()
202 */
203 public String getRelativePathOnVolume() {
204 return "/";
205 }
206
207 /**
208 * @see org.millscript.commons.vfs.VEntry#getURI()
209 */
210 public URI getURI() {
211 return CONSOLE_URI;
212 }
213
214 /**
215 * @see org.millscript.commons.vfs.VEntry#getVolume()
216 */
217 public VVolume getVolume() {
218 return null;
219 }
220
221 /**
222 * @see org.millscript.commons.vfs.VFile#getWriter()
223 */
224 public Writer getWriter() {
225 return new OutputStreamWriter(
226 this.getAppendOutputStream(),
227 this.getVolume().getParentVFS().getDefaultCharset()
228 );
229 }
230
231 /**
232 * @see org.millscript.commons.vfs.VEntry#toLocal()
233 */
234 public VFile toLocal() {
235
236 return this;
237 }
238
239 }