Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/**
 * Copyright 2000-2006 DFKI GmbH.
 * All Rights Reserved.  Use is subject to license terms.
 * <p/>
 * This file is part of MARY TTS.
 * <p/>
 * MARY TTS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, version 3 of the License.
 * <p/>
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * <p/>
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.File;
import java.io.IOException;

import java.util.Timer;
import java.util.TimerTask;

public class Main {
    private static Timer maintenanceTimer = new Timer(true);

    /**
     * Create a temporary file that will be deleted after a specified number of seconds.
     * The file will be deleted regardless of whether it is still used or not,
     * so be sure to specify a sufficiently large value.
     *
     * @param lifetimeInSeconds the number of seconds after which the file will be
     *                          deleted -- e.g., 3600 means that the file will be deleted one hour after creation.
     * @return the File that was created.
     * @throws IOException
     */
    public static File createSelfDeletingTempFile(int lifetimeInSeconds) throws IOException {
        final File f = File.createTempFile("mary", "temp");
        maintenanceTimer.schedule(new TimerTask() {
            @Override
            public void run() {
                f.delete();
            }
        }, lifetimeInSeconds * 1000l);
        return f;
    }
}