01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.ivy.plugins.repository.sftp;
19:
20: import java.io.IOException;
21: import java.io.InputStream;
22:
23: import org.apache.ivy.plugins.repository.Resource;
24:
25: public class SFTPResource implements Resource {
26: private SFTPRepository _repository;
27:
28: private String _path;
29:
30: private transient boolean _init = false;
31:
32: private transient boolean _exists;
33:
34: private transient long _lastModified;
35:
36: private transient long _contentLength;
37:
38: public SFTPResource(SFTPRepository repository, String path) {
39: _repository = repository;
40: _path = path;
41: }
42:
43: public String getName() {
44: return _path;
45: }
46:
47: public Resource clone(String cloneName) {
48: return new SFTPResource(_repository, cloneName);
49: }
50:
51: public long getLastModified() {
52: init();
53: return _lastModified;
54: }
55:
56: public long getContentLength() {
57: init();
58: return _contentLength;
59: }
60:
61: public boolean exists() {
62: init();
63: return _exists;
64: }
65:
66: private void init() {
67: if (!_init) {
68: Resource r = _repository.resolveResource(_path);
69: _contentLength = r.getContentLength();
70: _lastModified = r.getLastModified();
71: _exists = r.exists();
72: _init = true;
73: }
74: }
75:
76: public String toString() {
77: return getName();
78: }
79:
80: public boolean isLocal() {
81: return false;
82: }
83:
84: public InputStream openStream() throws IOException {
85: return _repository.openStream(this);
86: }
87: }
|