org.carlspring.commons.io.reloading.FSReloadableInputStreamHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of commons-io Show documentation
Show all versions of commons-io Show documentation
A set of common IO classes
package org.carlspring.commons.io.reloading;
import org.carlspring.commons.io.resource.ResourceCloser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.*;
/**
* @author mtodorov
*/
public class FSReloadableInputStreamHandler
implements ReloadableInputStreamHandler
{
private static final Logger logger = LoggerFactory.getLogger(FSReloadableInputStreamHandler.class);
private File file;
private InputStream inputStream;
public FSReloadableInputStreamHandler(File file)
{
this.file = file;
}
@Override
public InputStream getInputStream()
throws IOException
{
if (inputStream == null)
{
loadInputStream();
return inputStream;
}
else
{
return inputStream;
}
}
@Override
public void reload()
throws IOException
{
ResourceCloser.close(inputStream, logger);
loadInputStream();
}
private void loadInputStream()
throws FileNotFoundException
{
inputStream = new FileInputStream(file);
}
}