Example usage for org.apache.commons.io FileCleaner track

List of usage examples for org.apache.commons.io FileCleaner track

Introduction

In this page you can find the example usage for org.apache.commons.io FileCleaner track.

Prototype

public static void track(String path, Object marker) 

Source Link

Document

Track the specified file, using the provided marker, deleting the file when the marker instance is garbage collected.

Usage

From source file:com.mob.forum.util.legacy.commons.fileupload.disk.DiskFileItem.java

/**
 * Creates and returns a {@link java.io.File File} representing a uniquely
 * named temporary file in the configured repository path. The lifetime of
 * the file is tied to the lifetime of the <code>FileItem</code> instance;
 * the file will be deleted when the instance is garbage collected.
 *
 * @return The {@link java.io.File File} to be used for temporary storage.
 *///from   w  ww.j  av a  2s  . c  om
protected File getTempFile() {
    File tempDir = repository;
    if (tempDir == null) {
        tempDir = new File(System.getProperty("java.io.tmpdir"));
    }

    String fileName = "upload_" + getUniqueId() + ".tmp";

    File f = new File(tempDir, fileName);
    FileCleaner.track(f, this);
    return f;
}