1 package fr.jayasoft.ivy.repository.ssh; 2 3 4 import java.io.IOException ; 5 import java.io.InputStream ; 6 7 import fr.jayasoft.ivy.repository.Resource; 8 import fr.jayasoft.ivy.util.Message; 9 10 13 public class SshResource implements Resource { 14 15 private boolean resolved = false; 16 private String uri = null; 17 private boolean bExists = false; 18 private long len = 0; 19 private long lastModified = 0; 20 private SshRepository repository = null; 21 22 public SshResource() { 23 resolved = true; 24 } 25 26 public SshResource(SshRepository repository, String uri) { 27 this.uri = uri; 28 this.repository = repository; 29 resolved = false; 30 } 31 32 public SshResource(SshRepository repository, String uri, boolean bExists, long len, long lastModified) { 33 this.uri = uri; 34 this.bExists = bExists; 35 this.len = len; 36 this.lastModified = lastModified; 37 this.repository = repository; 38 resolved = true; 39 } 40 41 44 public boolean exists() { 45 if(!resolved) 46 resolve(); 47 return bExists; 48 } 49 50 53 public long getContentLength() { 54 if(!resolved) 55 resolve(); 56 return len; 57 } 58 59 62 public long getLastModified() { 63 if(!resolved) 64 resolve(); 65 return lastModified; 66 } 67 68 private void resolve() { 69 Message.debug("SShResource: resolving "+uri); 70 SshResource res = repository.resolveResource(uri); 71 len = res.getContentLength(); 72 lastModified = res.getLastModified(); 73 bExists = res.exists(); 74 resolved = true; 75 Message.debug("SShResource: resolved "+this); 76 } 77 78 81 public String getName() { 82 return uri; 83 } 84 85 public String toString() { 86 StringBuffer buffer = new StringBuffer (); 87 buffer.append("SshResource:"); 88 buffer.append(uri); 89 buffer.append(" ("); 90 buffer.append(len); 91 buffer.append(")]"); 92 return buffer.toString(); 93 } 94 95 public boolean isLocal() { 96 return false; 97 } 98 99 public Resource clone(String cloneName) { 100 return new SshResource(repository, cloneName); 101 } 102 103 public InputStream openStream() throws IOException { 104 return repository.openStream(this); 105 } 106 } 107 | Popular Tags |