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

org.onetwo.common.propconf.ResourceAdapterImpl Maven / Gradle / Ivy

There is a newer version: 4.7.2
Show newest version
package org.onetwo.common.propconf;

import java.io.File;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.onetwo.common.file.FileUtils;

public class ResourceAdapterImpl implements ResourceAdapter {

	protected final T resource;
	protected String postfix;
	
	public ResourceAdapterImpl(T resource) {
		super();
		this.resource = resource;
	}
	
	public ResourceAdapterImpl(T resource, String postfix) {
		super();
		this.resource = resource;
		this.postfix = postfix;
	}


	public String getPostfix() {
		if(StringUtils.isBlank(postfix)){
			return FileUtils.getExtendName(getName());
		}
		return postfix;
	}

	@Override
	public List readAsList(){
		if(isSupportedToFile())
			return FileUtils.readAsList(getFile());
		else
			throw new UnsupportedOperationException();
	}

	public T getResource() {
		return resource;
	}

	
	@Override
	public boolean isSupportedToFile() {
		if(resource instanceof File){
			return true;
		}
		return false;
	}

	@Override
	public File getFile() {
		if(resource instanceof File)
			return (File)resource;
		return null;
	}


	@Override
	public String getName() {
		if(getFile()!=null){
			return getFile().getName();
		}else{
			String path = resource.toString();
			return FileUtils.getFileName(path);
		}
	}

	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy