Example usage for org.apache.poi.util TempFile setTempFileCreationStrategy

List of usage examples for org.apache.poi.util TempFile setTempFileCreationStrategy

Introduction

In this page you can find the example usage for org.apache.poi.util TempFile setTempFileCreationStrategy.

Prototype

public static void setTempFileCreationStrategy(TempFileCreationStrategy strategy) 

Source Link

Document

Configures the strategy used by #createTempFile(String,String) to create the temporary files.

Usage

From source file:com.opendoorlogistics.core.tables.io.PoiIO.java

License:Open Source License

public static void initPOI() {
    if (!initialised) {
        // create a directory based on a random number so different instances of the application
        // should use different tmp directories (unless they're started at exactly the same nanosecond).
        Random random = new Random();
        int val = random.nextInt();
        poiTempFileDirectory = new File(System.getProperty("java.io.tmpdir"), "odlpoi" + val);

        TempFile.setTempFileCreationStrategy(new TempFileCreationStrategy() {

            @Override// w  w w .j  av a  2 s. c o  m
            public File createTempFile(String prefix, String suffix) throws IOException {
                // check dir exists, make if doesn't
                if (!poiTempFileDirectory.exists()) {
                    poiTempFileDirectory.mkdir();
                    poiTempFileDirectory.deleteOnExit();
                }

                File newFile = File.createTempFile(prefix, suffix, poiTempFileDirectory);
                return newFile;
            }
        });
        initialised = true;
    }
}