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:com.openkm.jcr.SecurityTest.java

@Override
protected void setUp() {
    log.debug("setUp()");
    log.debug("Delete repository: {}", TestConfig.REPOSITORY_HOME);
    FileUtils.deleteQuietly(new File(TestConfig.REPOSITORY_HOME));
}

From source file:hu.ptemik.gallery.servlets.UploadServlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    HttpSession session = request.getSession(false);
    User user = (User) session.getAttribute("user");
    String uploadFolder = getServletContext().getRealPath("") + File.separator + UPLOAD_DIRECTORY;

    if (ServletFileUpload.isMultipartContent(request) && user != null) {
        try {//from  w  w w .j  av a  2  s. c  o  m
            List<FileItem> multiparts = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
            Picture pic = new Picture();
            File uploadedFile = null;

            for (FileItem item : multiparts) {
                if (!item.isFormField()) {
                    String fileName = new File(item.getName()).getName();
                    String filePath = uploadFolder + File.separator + fileName;
                    String relativePath = UPLOAD_DIRECTORY + "/" + fileName;

                    uploadedFile = new File(filePath);
                    item.write(uploadedFile);

                    pic.setUrl(relativePath);
                } else {
                    if (item.getFieldName().equals("title")) {
                        pic.setTitle(item.getString());
                    } else if (item.getFieldName().equals("description")) {
                        pic.setDescription(item.getString());
                    }
                }
            }

            if (Controller.newPicture(pic, user)) {
                request.setAttribute("successMessage", "A fjl feltltse sikerlt!");
            } else {
                FileUtils.deleteQuietly(uploadedFile);
                throw new Exception();
            }
        } catch (FileNotFoundException ex) {
            request.setAttribute("errorMessage", "Hinyzik a fjl!");
        } catch (Exception ex) {
            request.setAttribute("errorMessage", "Hiba a fjl feltltse sorn!");
        }
    } else {
        request.setAttribute("errorMessage", "Form hiba");
    }

    request.getRequestDispatcher("upload.jsp").forward(request, response);
}

From source file:com.linkedin.pinot.core.startree.TestStarTreeMetadata.java

/**
 * Build the StarTree segment//from  w w  w .j  av a 2  s  .  c om
 *
 * @throws Exception
 */
@BeforeTest
public void setup() throws Exception {
    if (INDEX_DIR.exists()) {
        FileUtils.deleteQuietly(INDEX_DIR);
    }
    INDEX_DIR.mkdirs();
    setupSegment(INDEX_DIR);
}

From source file:fr.acxio.tools.agia.tasks.FilesOperationTaskletTest.java

@After
public void tearDown() throws Exception {
    Collection<File> aFilesToDelete = FileUtils.listFiles(new File("target"),
            new WildcardFileFilter("*-input*.csv"), null);
    for (File aFile : aFilesToDelete) {
        FileUtils.deleteQuietly(aFile);
    }/*from w w w.jav a  2 s. c o m*/
    FileUtils.deleteDirectory(new File("target/CP-testfiles"));
}

From source file:com.thoughtworks.go.domain.materials.tfs.AbstractTfsCommand.java

@Override
public final void checkout(File workDir, Revision revision) {
    try {/*from   ww  w.jav  a2  s.c o m*/
        if (workDir.exists()) {
            FileUtils.deleteQuietly(workDir);
        }
        setupWorkspace(workDir);
        LOGGER.debug("[TFS] Retrieving Files from Workspace {}, Working Folder {}, Revision {} ", workspace,
                workDir, revision);
        retrieveFiles(workDir, revision);
    } catch (Exception e) {
        String exceptionMessage = String.format(
                "Failed while checking out into Working Folder: %s, Project Path: %s, Workspace: %s, Username: %s, Domain: %s, Root Cause: %s",
                workDir, projectPath, workspace, userName, domain, e.getMessage());
        throw new RuntimeException(exceptionMessage, e);
    } finally {
        clearMapping(workDir);
    }
}

From source file:com.linkedin.pinot.core.segment.index.readers.ImmutableDictionaryReaderTest.java

@BeforeClass
public void setUp() throws Exception {
    FileUtils.deleteQuietly(TEMP_DIR);

    IntOpenHashSet intSet = new IntOpenHashSet();
    while (intSet.size() < NUM_VALUES) {
        intSet.add(RANDOM.nextInt());/*from  w  ww .j  av  a 2  s.  co m*/
    }
    _intValues = intSet.toIntArray();
    Arrays.sort(_intValues);

    LongOpenHashSet longSet = new LongOpenHashSet();
    while (longSet.size() < NUM_VALUES) {
        longSet.add(RANDOM.nextLong());
    }
    _longValues = longSet.toLongArray();
    Arrays.sort(_longValues);

    FloatOpenHashSet floatSet = new FloatOpenHashSet();
    while (floatSet.size() < NUM_VALUES) {
        floatSet.add(RANDOM.nextFloat());
    }
    _floatValues = floatSet.toFloatArray();
    Arrays.sort(_floatValues);

    DoubleOpenHashSet doubleSet = new DoubleOpenHashSet();
    while (doubleSet.size() < NUM_VALUES) {
        doubleSet.add(RANDOM.nextDouble());
    }
    _doubleValues = doubleSet.toDoubleArray();
    Arrays.sort(_doubleValues);

    Set<String> stringSet = new HashSet<>();
    while (stringSet.size() < NUM_VALUES) {
        stringSet.add(RandomStringUtils.random(RANDOM.nextInt(MAX_STRING_LENGTH)).replace('\0', ' '));
    }
    _stringValues = stringSet.toArray(new String[NUM_VALUES]);
    Arrays.sort(_stringValues);

    try (SegmentDictionaryCreator dictionaryCreator = new SegmentDictionaryCreator(_intValues,
            new DimensionFieldSpec(INT_COLUMN_NAME, FieldSpec.DataType.INT, true), TEMP_DIR)) {
        dictionaryCreator.build();
    }

    try (SegmentDictionaryCreator dictionaryCreator = new SegmentDictionaryCreator(_longValues,
            new DimensionFieldSpec(LONG_COLUMN_NAME, FieldSpec.DataType.LONG, true), TEMP_DIR)) {
        dictionaryCreator.build();
    }

    try (SegmentDictionaryCreator dictionaryCreator = new SegmentDictionaryCreator(_floatValues,
            new DimensionFieldSpec(FLOAT_COLUMN_NAME, FieldSpec.DataType.FLOAT, true), TEMP_DIR)) {
        dictionaryCreator.build();
    }

    try (SegmentDictionaryCreator dictionaryCreator = new SegmentDictionaryCreator(_doubleValues,
            new DimensionFieldSpec(DOUBLE_COLUMN_NAME, FieldSpec.DataType.DOUBLE, true), TEMP_DIR)) {
        dictionaryCreator.build();
    }

    try (SegmentDictionaryCreator dictionaryCreator = new SegmentDictionaryCreator(_stringValues,
            new DimensionFieldSpec(STRING_COLUMN_NAME, FieldSpec.DataType.STRING, true), TEMP_DIR)) {
        dictionaryCreator.build();
        _numBytesPerStringValue = dictionaryCreator.getNumBytesPerString();
    }
}

From source file:com.mmj.app.biz.service.impl.FileServiceImpl.java

@Override
public Result delFileByPath(String filePath) {
    if (StringUtils.isEmpty(filePath)) {
        return Result.failed();
    }//w w w .  j  a  v  a2s  . c  o m
    filePath = StringUtils.replace(filePath, STATIC_TMP_IMG, StringUtils.EMPTY);
    String tmpPath = UPLOAD_BASE_PATH.replaceAll(STATIC_BASE_IMG, "");
    File file = new File(tmpPath + filePath);
    if (file == null || file.isFile()) {
        FileUtils.deleteQuietly(file);
        return Result.success("?", null);
    }
    return Result.failed();
}

From source file:com.linkedin.pinot.core.chunk.creator.impl.ChunkIndexCreationDriverImplTest.java

@BeforeClass
public void setUP() throws Exception {

    if (INDEX_DIR.exists()) {
        FileUtils.deleteQuietly(INDEX_DIR);
    }/*www . j  ava  2s.  com*/

    final String filePath = TestUtils.getFileFromResourceUrl(
            ChunkIndexCreationDriverImplTest.class.getClassLoader().getResource(AVRO_DATA));

    final SegmentGeneratorConfig config = SegmentTestUtils.getSegmentGenSpecWithSchemAndProjectedColumns(
            new File(filePath), INDEX_DIR, "daysSinceEpoch", TimeUnit.DAYS, "testTable");
    config.setSegmentNamePostfix("1");
    config.setTimeColumnName("daysSinceEpoch");
    final SegmentIndexCreationDriver driver = SegmentCreationDriverFactory.get(null);
    driver.init(config);
    driver.build();
}

From source file:com.adaptris.core.fs.MarshallingCacheCase.java

public void testPersistenceWithBadPersistentStore() throws Exception {
    String oldName = Thread.currentThread().getName();
    MarshallingItemCache cache = createCache();
    File badStore = File.createTempFile(this.getClass().getSimpleName(), "");
    badStore.delete();/*from   w  w  w  .j a v  a2s .  co m*/
    badStore.mkdirs();
    cache.setPersistentStore(badStore.getCanonicalPath());

    try {
        Thread.currentThread().setName("testPersistenceWithBadPersistentStore");
        cache.init();
        cache.close();
        fail();
    } catch (CoreException expected) {
        log.debug(expected.getMessage(), expected);
    } finally {
        Thread.currentThread().setName(oldName);
        FileUtils.deleteQuietly(badStore);
    }

}

From source file:com.thoughtworks.go.server.service.plugins.AnalyticsPluginAssetsServiceTest.java

@After
public void tearDown() throws Exception {
    if (railsRoot != null && railsRoot.exists()) {
        FileUtils.deleteQuietly(railsRoot);
    }
}