1 7 package fr.jayasoft.ivy.repository.sftp; 8 9 import java.io.IOException ; 10 import java.io.InputStream ; 11 12 import fr.jayasoft.ivy.repository.Resource; 13 14 public class SFTPResource implements Resource { 15 private SFTPRepository _repository; 16 private String _path; 17 18 private transient boolean _init = false; 19 private transient boolean _exists; 20 private transient long _lastModified; 21 private transient long _contentLength; 22 23 public SFTPResource(SFTPRepository repository, String path) { 24 _repository = repository; 25 _path = path; 26 } 27 28 public String getName() { 29 return _path; 30 } 31 32 public Resource clone(String cloneName) { 33 return new SFTPResource(_repository, cloneName); 34 } 35 36 public long getLastModified() { 37 init(); 38 return _lastModified; 39 } 40 41 public long getContentLength() { 42 init(); 43 return _contentLength; 44 } 45 46 public boolean exists() { 47 init(); 48 return _exists; 49 } 50 51 private void init() { 52 if (!_init) { 53 Resource r = _repository.resolveResource(_path); 54 _contentLength = r.getContentLength(); 55 _lastModified = r.getLastModified(); 56 _exists = r.exists(); 57 _init = true; 58 } 59 } 60 61 public String toString() { 62 return getName(); 63 } 64 65 public boolean isLocal() { 66 return false; 67 } 68 69 public InputStream openStream() throws IOException { 70 return _repository.openStream(this); 71 } 72 } 73 | Popular Tags |