All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.dreampie.common.web.resource.FileResource Maven / Gradle / Ivy

There is a newer version: 1.2.2
Show newest version
package cn.dreampie.common.web.resource;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * Created by wangrenhui on 2014/7/11.
 */
public class FileResource implements Resource {

  private File file;

  public FileResource(File file) {
    if (file == null) {
      throw new IllegalArgumentException("File must not be null!");
    }
    this.file = file;
  }

  public boolean exists() {
    return file.exists();
  }

  public InputStream getInputStream() throws IOException {
    return new FileInputStream(file);
  }

  public long lastModified() {
    return file.lastModified();
  }

  public Resource createRelative(String relativePath) {
    File relativeFile = new File(file.getParentFile(), relativePath);
    return new FileResource(relativeFile);
  }

  @Override
  public String toString() {
    return file.getAbsolutePath();
  }

  public String getName() {
    return file.getAbsolutePath();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy