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.file;
19:
20: import java.io.File;
21: import java.io.FileInputStream;
22: import java.io.IOException;
23: import java.io.InputStream;
24:
25: import org.apache.ivy.plugins.repository.Resource;
26:
27: public class FileResource implements Resource {
28: private File file;
29:
30: private FileRepository repository;
31:
32: public FileResource(FileRepository repository, File f) {
33: this .repository = repository;
34: this .file = f;
35: }
36:
37: public String getName() {
38: return file.getPath();
39: }
40:
41: public Resource clone(String cloneName) {
42: return new FileResource(repository, new File(cloneName));
43: }
44:
45: public long getLastModified() {
46: return file.lastModified();
47: }
48:
49: public long getContentLength() {
50: return file.length();
51: }
52:
53: public boolean exists() {
54: return file.exists();
55: }
56:
57: public String toString() {
58: return getName();
59: }
60:
61: public File getFile() {
62: return file;
63: }
64:
65: public FileRepository getRepository() {
66: return repository;
67: }
68:
69: public boolean isLocal() {
70: return repository.isLocal();
71: }
72:
73: public InputStream openStream() throws IOException {
74: return new FileInputStream(file);
75: }
76: }
|