e.g. Calendar Search Help
You must enter a value before pressing Search
spring

Class: org.springframework.core.io.FileSystemResource   ©

 OK to copy?
001 /*
002  * Copyright 2002-2004 the original author or authors.
003  * 
004  * Licensed under the Apache License, Version 2.0 (the "License");
005  * you may not use this file except in compliance with the License.
006  * You may obtain a copy of the License at
007  * 
008  *      http://www.apache.org/licenses/LICENSE-2.0
009  * 
010  * Unless required by applicable law or agreed to in writing, software
011  * distributed under the License is distributed on an "AS IS" BASIS,
012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013  * See the License for the specific language governing permissions and
014  * limitations under the License.
015  */
016 
017 package org.springframework.core.io;
018 
019 import java.io.File;
020 import java.io.FileInputStream;
021 import java.io.IOException;
022 import java.io.InputStream;
023 import java.net.URL;
024 
025 import org.springframework.util.Assert;
026 import org.springframework.util.ResourceUtils;
027 import org.springframework.util.StringUtils;
028 
029 /**
030  * Resource implementation for java.io.File handles.
031  * Obviously supports resolution as File, and also as URL.
032  * @author Juergen Hoeller
033  * @since 28.12.2003
034  * @see java.io.File
035  */
036 public class FileSystemResource extends AbstractResource {
037 
038     private final File file;
039 
040     private final String path;
041 
042     /**
043      * Create a new FileSystemResource.
044      * @param file a File handle
045      */
046     public FileSystemResource(File file) {
047         Assert.notNull(file, "file is required");
048         this.file = file;
049         this.path = StringUtils.cleanPath(file.getPath());
050     }
051 
052     /**
053      * Create a new FileSystemResource.
054      * @param path a file path
055      */
056     public FileSystemResource(String path) {
057         Assert.notNull(path, "path is required");
058         this.file = new File(path);
059         this.path = path;
060     }
061 
062     public boolean exists() {
063         return this.file.exists();
064     }
065 
066     public InputStream getInputStream() throws IOException {
067         return new FileInputStream(this.file);
068     }
069 
070     public URL getURL() throws IOException {
Rate071         return new URL(ResourceUtils.URL_PROTOCOL_FILE + ":" + this.file.getAbsolutePath());
072     }
073 
074     public File getFile() {
075         return file;
076     }
077 
078     public Resource createRelative(String relativePath) {
079         String pathToUse = StringUtils.applyRelativePath(this.path, relativePath);
080         return new FileSystemResource(pathToUse);
081     }
082 
083     public String getFilename() {
084         return this.file.getName();
085     }
086 
087     public String getDescription() {
Rate088         return "file [" + this.file.getAbsolutePath() + "]";
089     }
090 
091     public boolean equals(Object obj) {
092         return (obj == this ||
093             (obj instanceof FileSystemResource && this.file.equals(((FileSystemResource) obj).file)));
094     }
095 
096     public int hashCode() {
097         return this.file.hashCode();
098     }
099 
100 }

            
All Examples in File:
Example
Line
Rating (found
useful by...)
71 0% of 0
88 0% of 0