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

com.github.rrsunhome.excelsql.io.FileSystemResource Maven / Gradle / Ivy

There is a newer version: 2.1.2
Show newest version
package com.github.rrsunhome.excelsql.io;

import org.apache.commons.lang3.StringUtils;

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

/**
 * The class represent the resource in the file system.
 */
public class FileSystemResource implements Resource {

  private final File file;

  private final String path;

  public FileSystemResource(String path) {
    this.file = new File(path);
    this.path = path;
  }

  @Override
  public final String getPath() {
    return this.path;
  }

  @Override
  public String getExtension() {
    int pos = path.lastIndexOf('.');
    if (pos == -1) {
      return null;
    }
    String extension = path.substring(pos + 1);
    if (StringUtils.isEmpty(extension)) {
      return null;
    }
    return extension;
  }

  @Override
  public String getDescription() {
    return "file [" + this.file.getAbsolutePath() + "]";
  }

  @Override
  public boolean exists() {
    return this.file.exists();
  }

  @Override
  public InputStream getInputStream() throws IOException {
    return new FileInputStream(this.file);
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy