Example usage for org.apache.commons.io FileUtils deleteQuietly

List of usage examples for org.apache.commons.io FileUtils deleteQuietly

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils deleteQuietly.

Prototype

public static boolean deleteQuietly(File file) 

Source Link

Document

Deletes a file, never throwing an exception.

Usage

From source file:gov.nih.nci.caintegrator.domain.analysis.GisticGeneMapFileParser.java

/**
 * @param inputFile input file/*from   w ww  . ja  v a2  s  .  co  m*/
 * @throws IOException IO exception
 * @return gene map to wide peak boundaries
 */
public Map<String, List<Gene>> parse(File inputFile) throws IOException {
    FileReader fileReader = new FileReader(inputFile);
    CSVReader csvReader = new CSVReader(fileReader, '\t');
    String[] fields;
    while ((fields = csvReader.readNext()) != null) {
        if (WIDE_PEAK_BOUNDARIES.equalsIgnoreCase(fields[0].trim())) {
            processBoundaries(fields);
        } else if (GENES_IN_WIDE_PEAK.equalsIgnoreCase(fields[0].trim()) || StringUtils.isBlank(fields[0])) {
            processGene(fields);
        }
    }
    csvReader.close();
    fileReader.close();
    removeBoundariesWithNoGenes();
    FileUtils.deleteQuietly(inputFile);
    return geneMap;
}

From source file:com.creactiviti.piper.plugin.ffmpeg.Mediainfo.java

@Override
public Map<String, Object> handle(Task aTask) throws Exception {
    CommandLine cmd = new CommandLine("mediainfo");
    cmd.addArgument(aTask.getRequiredString("input"));
    log.debug("{}", cmd);
    DefaultExecutor exec = new DefaultExecutor();
    File tempFile = File.createTempFile("log", null);
    try (PrintStream stream = new PrintStream(tempFile);) {
        exec.setStreamHandler(new PumpStreamHandler(stream));
        exec.execute(cmd);//from   ww  w .  j a  va 2 s.  c  o m
        return parse(FileUtils.readFileToString(tempFile));
    } catch (ExecuteException e) {
        throw new ExecuteException(e.getMessage(), e.getExitValue(),
                new RuntimeException(FileUtils.readFileToString(tempFile)));
    } finally {
        FileUtils.deleteQuietly(tempFile);
    }
}

From source file:com.thoughtworks.go.agent.launcher.AgentLauncherImplTest.java

private void cleanup() {
    FileUtils.deleteQuietly(AGENT_PLUGINS_ZIP);
    FileUtils.deleteQuietly(AGENT_BINARY_JAR);
    FileUtils.deleteQuietly(AGENT_LAUNCHER_JAR);
    FileUtils.deleteQuietly(TFS_IMPL_JAR);
    new Lockfile(new File(AgentLauncherImpl.AGENT_BOOTSTRAPPER_LOCK_FILE)).delete();
}

From source file:com.tc.websocket.runners.TempFileMonitor.java

@Override
public void run() {

    if (TaskRunner.getInstance().isClosing()) {
        return;//from  w  w w. j  a  v  a  2s.c  o  m
    }

    try {
        File temp = File.createTempFile("temp", "temp");
        String absolutePath = temp.getAbsolutePath();
        String tempFilePath = absolutePath.substring(0, absolutePath.lastIndexOf(File.separator));

        System.out.println("cleaning out directory " + tempFilePath);

        File tempdir = new File(tempFilePath);
        File[] files = tempdir.listFiles();

        temp.delete();//cleanup

        if (files != null) {
            for (File file : files) {
                String name = file.getName();
                if (file.exists() && name.startsWith("eo") && name.endsWith("tm")) {
                    //calculate the age
                    Date lastmod = new Date(file.lastModified());
                    long minutes = DateUtils.getTimeDiffMin(lastmod, new Date());
                    if (minutes >= 5) {
                        FileUtils.deleteQuietly(file);
                    }
                }
            }
        }
    } catch (Exception e) {
        LOG.log(Level.SEVERE, null, e);
    }
}

From source file:mitm.common.util.DeleteFileOnCloseFileInputStream.java

@Override
public void close() throws IOException {
    super.close();

    FileUtils.deleteQuietly(file);
}

From source file:io.jeo.geopkg.GeoPkgFeatureTest.java

@After
public void tearDown() throws Exception {
    geopkg.close();
    FileUtils.deleteQuietly(geopkg.file().getParentFile());
}

From source file:com.meltmedia.rodimus.DocumentTransformationTest.java

@Before
public void beforeTest() throws Exception {
    if (expectedOutputDir == null || !expectedOutputDir.exists()) {
        fail("The expected output directory for " + document.getName() + " does not exist.");
    }/*from w  w w. j a  va  2 s .co m*/

    // clear out the output directory.
    FileUtils.deleteQuietly(actualOutputDir);
    if (!actualOutputDir.mkdir()) {
        fail("Could not create output directory for " + document.getPath());
    }

    // rerun the transform.
    RodimusCli.transformDocument(document, actualOutputDir, false);
}

From source file:com.opentangerine.clean.Delete.java

/**
 * Deletes file/dir under given path./*w w w. j  av  a  2s  .c o m*/
 * @param file File.
 */
public void file(final File file) {
    if (file.exists()) {
        this.summary.add(file);
        if (!this.mode.readonly()) {
            FileUtils.deleteQuietly(file);
        }
    }
}

From source file:com.lingxiang2014.service.impl.FileServiceImpl.java

private void addTask(final StoragePlugin storagePlugin, final String path, final File tempFile,
        final String contentType) {
    taskExecutor.execute(new Runnable() {
        public void run() {
            try {
                storagePlugin.upload(path, tempFile, contentType);
            } finally {
                FileUtils.deleteQuietly(tempFile);
            }//from   www .  ja  v a2s.  co  m
        }
    });
}

From source file:eu.esdihumboldt.hale.ui.application.handler.ShowHandbookHandler.java

/**
 * @see IHandler#execute(ExecutionEvent)
 *///from w w  w  .j a  v a2  s  .  c  om
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

    String tempDirName = System.getProperty("java.io.tmpdir"); //$NON-NLS-1$
    if (!tempDirName.endsWith("/")) { //$NON-NLS-1$
        tempDirName = tempDirName + "/"; //$NON-NLS-1$
    }
    tempDirName = tempDirName + HALEApplicationPlugin.PLUGIN_ID + "/"; //$NON-NLS-1$

    File tempDir = new File(tempDirName);
    tempDir.mkdirs();
    tempDir.deleteOnExit();

    File pdfFile = new File(tempDirName + PDFFILE);
    if (pdfFile.exists()) {
        FileUtils.deleteQuietly(pdfFile);
    }

    pdfFile.deleteOnExit();

    URL pdfUrl = this.getClass().getResource("/documentation/" + PDFFILE); //$NON-NLS-1$
    if (pdfUrl == null) {
        throw new RuntimeException("Manual could not be retrieved."); //$NON-NLS-1$
    }

    InputStream in;
    try {
        in = pdfUrl.openStream();
    } catch (IOException e) {
        ExceptionHelper.handleException("Could not open Streaming.", //$NON-NLS-1$
                HALEApplicationPlugin.PLUGIN_ID, e);
        return null;
    }

    FileOutputStream fos = null;
    byte[] buffer = new byte[4096];
    int read;
    try {
        fos = new FileOutputStream(pdfFile);

        while ((read = in.read(buffer)) != -1) {
            fos.write(buffer, 0, read);
        }
    } catch (IOException e) {
        ExceptionHelper.handleException("Error while reading the file.", //$NON-NLS-1$
                HALEApplicationPlugin.PLUGIN_ID, e);
        return null;
    } finally {
        try {
            if (fos != null) {
                fos.close();
            }
            in.close();
        } catch (IOException e) {
            // ignore
        }
    }

    try {
        Desktop.getDesktop().open(pdfFile);
    } catch (IOException e) {
        ExceptionHelper.handleException("The file could not be opened", //$NON-NLS-1$
                HALEApplicationPlugin.PLUGIN_ID, e);
    }

    return null;
}