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.InputStream;
29 import java.io.OutputStream;
30 import java.io.Reader;
31 import java.io.Writer;
32
33 /**
34 * This class implements a virtual file for a Unix style chroot volume.
35 */
36 public class ChrootFile extends AbstractChrootEntry implements VFile {
37
38 /**
39 * The root folder for this volume.
40 */
41 private final ChrootVolume chrootVolume;
42
43 /**
44 * The hidden virtual file.
45 */
46 private final VFile chrootFile;
47
48 /**
49 * The parent folder for this file.
50 */
51 private final ChrootFolder parentFolder;
52
53 /**
54 * Constructs a new chroot file for the specified file, in the specified
55 * folder, on the specified volume.
56 *
57 * @param vol the chroot volume this file belongs on
58 * @param parent the chroot parent folder for this file
59 * @param file the underlying virtual file
60 */
61 ChrootFile( final ChrootVolume vol, final ChrootFolder parent, final VFile file ) {
62 this.chrootVolume = vol;
63 this.chrootFile = file;
64 this.parentFolder = parent;
65 }
66
67 /**
68 * @see org.millscript.commons.vfs.VEntry#appendRelativePath(java.lang.StringBuffer)
69 */
70 public StringBuffer appendRelativePath( final StringBuffer buffer ) {
71
72 if ( this.getParent() != null ) {
73
74
75
76 this.getParent().appendRelativePath( buffer );
77 }
78
79 return buffer.append( this.getName() );
80 }
81
82 /**
83 * @see org.millscript.commons.vfs.VEntry#appendURI(java.lang.StringBuffer)
84 */
85 public StringBuffer appendURI( final StringBuffer buffer ) {
86
87
88
89 if ( this.getParent() == null ) {
90
91 this.getVolume().appendBaseURI( buffer );
92 } else {
93
94 this.getParent().appendURI( buffer );
95 }
96 return buffer.append( this.getName() );
97 }
98
99 /**
100 * @see org.millscript.commons.vfs.VEntry#exists()
101 */
102 public boolean exists() {
103 return this.chrootFile.exists();
104 }
105
106 /**
107 * @see org.millscript.commons.vfs.VFile#getAppendOutputStream()
108 */
109 public OutputStream getAppendOutputStream() {
110 return this.chrootFile.getAppendOutputStream();
111 }
112
113 /**
114 * @see org.millscript.commons.vfs.VFile#getAppendWriter()
115 */
116 public Writer getAppendWriter() {
117 return this.chrootFile.getAppendWriter();
118 }
119
120 /**
121 * @see org.millscript.commons.vfs.VFile#getContentMIMEType()
122 */
123 public String getContentMIMEType() {
124 return this.chrootFile.getContentMIMEType();
125 }
126
127 /**
128 * @see org.millscript.commons.vfs.VFile#getInputStream()
129 */
130 public InputStream getInputStream() {
131 return this.chrootFile.getInputStream();
132 }
133
134 /**
135 * @see org.millscript.commons.vfs.VEntry#getMIMEType(java.lang.String)
136 */
137 public String getMIMEType( final String fileName ) {
138 return this.chrootFile.getMIMEType( fileName );
139 }
140
141 /**
142 * @see org.millscript.commons.vfs.VEntry#getMIMETypeHandler(java.lang.String)
143 */
144 public MIMETypeHandler getMIMETypeHandler( final String type ) {
145 return this.chrootFile.getMIMETypeHandler( type );
146 }
147
148 /**
149 * @see org.millscript.commons.vfs.VEntry#getName()
150 */
151 public String getName() {
152 return this.chrootFile.getName();
153 }
154
155 /**
156 * @see org.millscript.commons.vfs.VFile#getOutputStream()
157 */
158 public OutputStream getOutputStream() {
159 return this.chrootFile.getOutputStream();
160 }
161
162 /**
163 * @see org.millscript.commons.vfs.VEntry#getParent()
164 */
165 public VFolder getParent() {
166 return this.parentFolder;
167 }
168
169 /**
170 * @see org.millscript.commons.vfs.VFile#getReader()
171 */
172 public Reader getReader() {
173 return this.chrootFile.getReader();
174 }
175
176 /**
177 * @see org.millscript.commons.vfs.VEntry#getVolume()
178 */
179 public VVolume getVolume() {
180 return this.chrootVolume;
181 }
182
183 /**
184 * @see org.millscript.commons.vfs.VFile#getWriter()
185 */
186 public Writer getWriter() {
187 return this.chrootFile.getWriter();
188 }
189
190 /**
191 * @see org.millscript.commons.vfs.VEntry#toLocal()
192 */
193 public VFile toLocal() {
194 return new ChrootFile( this.chrootVolume, this.parentFolder, this.chrootFile.toLocal() );
195 }
196
197 /**
198 * @see java.lang.Object#toString()
199 */
200 @Override
201 public String toString() {
202 final StringBuffer buff = new StringBuffer( "CHROOT_FILE( " );
203 return this.appendAbsolutePath( buff ).append( " )" ).toString();
204 }
205
206 }