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

io.airlift.testing.TempFile Maven / Gradle / Ivy

There is a newer version: 285
Show newest version
package io.airlift.testing;

import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;

public class TempFile
        implements Closeable
{
    private final File file;
    private boolean deleted;

    public TempFile()
            throws IOException
    {
        this.file = File.createTempFile("tmp", null);
    }

    public File file()
    {
        return file;
    }

    public Path path()
    {
        return file.toPath();
    }

    @SuppressWarnings("ResultOfMethodCallIgnored")
    @Override
    public void close()
    {
        if (!deleted) {
            deleted = true;
            file.delete();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy