1 17 18 package org.alfresco.filesys.smb.server.repo.pseudo; 19 20 import java.io.IOException ; 21 22 import org.alfresco.filesys.server.filesys.AccessDeniedException; 23 import org.alfresco.filesys.server.filesys.FileInfo; 24 import org.alfresco.filesys.server.filesys.NetworkFile; 25 import org.alfresco.filesys.smb.SeekType; 26 27 34 public class MemoryNetworkFile extends NetworkFile 35 { 36 38 private long m_filePos; 39 40 42 private byte[] m_data; 43 44 46 private boolean m_eof; 47 48 55 public MemoryNetworkFile(String name, byte[] data, FileInfo finfo) 56 { 57 super( name); 58 59 61 m_data = data; 62 if ( m_data == null) 63 m_data = new byte[0]; 64 65 67 setFileSize( m_data.length); 68 m_eof = false; 69 70 72 setModifyDate( finfo.getModifyDateTime()); 73 setCreationDate( finfo.getCreationDateTime()); 74 75 77 if ( finfo.getPath() != null) 78 { 79 setFileId( finfo.getPath().hashCode()); 80 setFullName( finfo.getPath()); 81 } 82 } 83 84 87 public void closeFile() throws java.io.IOException 88 { 89 } 91 92 97 public long currentPosition() 98 { 99 return m_filePos; 100 } 101 102 107 public void flushFile() throws IOException 108 { 109 } 111 112 117 public boolean isEndOfFile() throws java.io.IOException 118 { 119 121 if ( m_filePos == m_data.length) 122 return true; 123 return false; 124 } 125 126 132 public void openFile(boolean createFlag) throws java.io.IOException 133 { 134 136 setClosed(false); 137 } 138 139 149 public int readFile(byte[] buf, int len, int pos, long fileOff) throws java.io.IOException 150 { 151 153 long fileLen = (long) m_data.length; 154 155 if ( fileOff >= fileLen) 156 return 0; 157 158 160 if (( fileOff + len) > fileLen) 161 len = (int) ( fileLen - fileOff); 162 163 165 System.arraycopy( m_data, (int) fileOff, buf, pos, len); 166 167 169 m_filePos = fileOff + len; 170 171 173 return len; 174 } 175 176 184 public long seekFile(long pos, int typ) throws IOException 185 { 186 188 switch (typ) 189 { 190 192 case SeekType.StartOfFile: 193 if (currentPosition() != pos) 194 m_filePos = pos; 195 break; 196 197 199 case SeekType.CurrentPos: 200 m_filePos += pos; 201 break; 202 203 205 case SeekType.EndOfFile: 206 m_filePos += pos; 207 if ( m_filePos < 0) 208 m_filePos = 0L; 209 break; 210 } 211 212 214 return currentPosition(); 215 } 216 217 223 public void truncateFile(long siz) throws IOException 224 { 225 227 throw new AccessDeniedException("Cannot truncate pseudo file"); 228 } 229 230 237 public void writeFile(byte[] buf, int len, int pos) throws java.io.IOException 238 { 239 241 throw new AccessDeniedException("Cannot write to pseudo file"); 242 } 243 244 253 public void writeFile(byte[] buf, int len, int pos, long offset) throws java.io.IOException 254 { 255 257 throw new AccessDeniedException("Cannot write to pseudo file"); 258 } 259 } 260 | Popular Tags |