KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > jayasoft > ivy > repository > sftp > SFTPResource


1 /*
2  * This file is subject to the licence found in LICENCE.TXT in the root directory of the project.
3  * Copyright Jayasoft 2005 - All rights reserved
4  *
5  * #SNAPSHOT#
6  */

7 package fr.jayasoft.ivy.repository.sftp;
8
9 import java.io.IOException JavaDoc;
10 import java.io.InputStream JavaDoc;
11
12 import fr.jayasoft.ivy.repository.Resource;
13
14 public class SFTPResource implements Resource {
15     private SFTPRepository _repository;
16     private String JavaDoc _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 JavaDoc path) {
24         _repository = repository;
25         _path = path;
26     }
27
28     public String JavaDoc getName() {
29         return _path;
30     }
31     
32     public Resource clone(String JavaDoc 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 JavaDoc toString() {
62         return getName();
63     }
64
65     public boolean isLocal() {
66         return false;
67     }
68
69     public InputStream JavaDoc openStream() throws IOException JavaDoc {
70         return _repository.openStream(this);
71     }
72 }
73
Popular Tags