1 17 18 package org.alfresco.filesys.smb.server.repo.pseudo; 19 20 import java.io.File ; 21 import java.io.IOException ; 22 import java.io.RandomAccessFile ; 23 24 import org.alfresco.filesys.server.filesys.AccessDeniedException; 25 import org.alfresco.filesys.server.filesys.NetworkFile; 26 import org.alfresco.filesys.smb.SeekType; 27 28 35 public class PseudoNetworkFile extends NetworkFile 36 { 37 39 protected File m_file; 40 41 43 protected RandomAccessFile m_io; 44 45 47 protected boolean m_eof; 48 49 56 public PseudoNetworkFile(String name, String localPath, String netPath) 57 { 58 super( name); 59 60 62 m_file = new File ( localPath); 63 64 66 setFileSize(m_file.length()); 67 m_eof = false; 68 69 72 long modDate = m_file.lastModified(); 73 setModifyDate(modDate); 74 setCreationDate(modDate); 75 76 78 setFileId(netPath.hashCode()); 79 80 82 setFullName( netPath); 83 } 84 85 88 public void closeFile() throws java.io.IOException 89 { 90 91 93 if (m_io != null) 94 { 95 96 98 m_io.close(); 99 m_io = null; 100 101 103 if (this.getWriteCount() > 0) 104 m_file.setLastModified(System.currentTimeMillis()); 105 106 108 setClosed(true); 109 } 110 } 111 112 117 public long currentPosition() 118 { 119 120 122 try 123 { 124 if (m_io != null) 125 return m_io.getFilePointer(); 126 } 127 catch (Exception ex) 128 { 129 } 130 return 0; 131 } 132 133 138 public void flushFile() throws IOException 139 { 140 142 if (m_io != null) 143 m_io.getFD().sync(); 144 } 145 146 151 public boolean isEndOfFile() throws java.io.IOException 152 { 153 155 if (m_io != null && m_io.getFilePointer() == m_io.length()) 156 return true; 157 return false; 158 } 159 160 166 public void openFile(boolean createFlag) throws java.io.IOException 167 { 168 169 synchronized (m_file) 170 { 171 173 if (m_io == null) 174 { 175 176 178 m_io = new RandomAccessFile (m_file, "r"); 179 180 182 setClosed(false); 183 } 184 } 185 } 186 187 197 public int readFile(byte[] buf, int len, int pos, long fileOff) throws java.io.IOException 198 { 199 200 202 if (m_io == null) 203 openFile(false); 204 205 207 if (currentPosition() != fileOff) 208 seekFile(fileOff, SeekType.StartOfFile); 209 210 212 int rdlen = m_io.read(buf, pos, len); 213 214 216 return rdlen; 217 } 218 219 227 public long seekFile(long pos, int typ) throws IOException 228 { 229 230 232 if (m_io == null) 233 openFile(false); 234 235 237 switch (typ) 238 { 239 240 242 case SeekType.StartOfFile: 243 if (currentPosition() != pos) 244 m_io.seek(pos); 245 break; 246 247 249 case SeekType.CurrentPos: 250 m_io.seek(currentPosition() + pos); 251 break; 252 253 255 case SeekType.EndOfFile: { 256 long newPos = m_io.length() + pos; 257 m_io.seek(newPos); 258 } 259 break; 260 } 261 262 264 return currentPosition(); 265 } 266 267 273 public void truncateFile(long siz) throws IOException 274 { 275 277 throw new AccessDeniedException("Cannot truncate pseudo file"); 278 } 279 280 287 public void writeFile(byte[] buf, int len, int pos) throws java.io.IOException 288 { 289 291 throw new AccessDeniedException("Cannot write to pseudo file"); 292 } 293 294 303 public void writeFile(byte[] buf, int len, int pos, long offset) throws java.io.IOException 304 { 305 307 throw new AccessDeniedException("Cannot write to pseudo file"); 308 } 309 } 310 | Popular Tags |