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

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

Introduction

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

Prototype

public static void touch(File file) throws IOException 

Source Link

Document

Implements the same behaviour as the "touch" utility on Unix.

Usage

From source file:nl.mpi.lamus.archive.implementation.LamusArchiveFileHelper.java

/**
 * @see ArchiveFileHelper#createFileAndDirectories(java.io.File)
 *///from ww w  .j  av  a  2s.  c o  m
@Override
public void createFileAndDirectories(File fileToCreate) throws IOException {

    File parentFile = fileToCreate.getAbsoluteFile().getParentFile();
    FileUtils.forceMkdir(parentFile);
    FileUtils.touch(fileToCreate);
}

From source file:nl.mpi.lamus.archive.implementation.LamusArchiveFileHelperTest.java

@Test
public void getFinalFileExistingOneName() throws IOException {

    final String fileName = "file.cmdi";
    final String expectedName = "file_1.cmdi";
    prepareExistingTempDirectory();/*from  ww w. ja v a 2 s . c  o m*/

    File file = new File(existingTempDirectory, fileName);
    FileUtils.touch(file);
    File expectedFile = new File(existingTempDirectory, expectedName);

    File retrievedFile = testArchiveFileHelper.getFinalFile(existingTempDirectory, fileName);

    assertEquals("Retrieved file different from expected", expectedFile, retrievedFile);
}

From source file:nl.mpi.lamus.archive.implementation.LamusArchiveFileHelperTest.java

@Test
public void getFinalFileExistingSeveralNames() throws IOException {

    final String fileName = "file.cmdi";
    prepareExistingTempDirectory();/*  ww w  .  ja  v a  2  s.c  o m*/

    File file = new File(existingTempDirectory, fileName);
    FileUtils.touch(file);

    for (int suffix = 1; suffix < 11; suffix++) {
        String currentFileName = FilenameUtils.getBaseName(fileName) + "_" + suffix
                + FilenameUtils.EXTENSION_SEPARATOR_STR + FilenameUtils.getExtension(fileName);
        File currentFile = new File(existingTempDirectory, currentFileName);
        FileUtils.touch(currentFile);
    }

    String expectedName = "file_11.cmdi";
    File expectedFile = new File(existingTempDirectory, expectedName);

    File retrievedFile = testArchiveFileHelper.getFinalFile(existingTempDirectory, fileName);

    assertEquals("Retrieved file different from expected", expectedFile, retrievedFile);
}

From source file:nl.mpi.lamus.archive.implementation.LamusArchiveFileHelperTest.java

@Test
public void getFinalFileExistingAllNames() throws IOException {

    final String fileName = "file.cmdi";
    prepareExistingTempDirectory();//w  w  w  . ja  v  a2 s. c o m

    File file = new File(existingTempDirectory, fileName);
    FileUtils.touch(file);

    for (int suffix = 1; suffix < 10000; suffix++) {
        String currentFileName = FilenameUtils.getBaseName(fileName) + "_" + suffix
                + FilenameUtils.EXTENSION_SEPARATOR_STR + FilenameUtils.getExtension(fileName);
        File currentFile = new File(existingTempDirectory, currentFileName);
        FileUtils.touch(currentFile);
    }

    File retrievedFile = testArchiveFileHelper.getFinalFile(existingTempDirectory, fileName);

    assertNull("Retrieved file should be null when all suffixes exist already", retrievedFile);
}

From source file:nl.mpi.lamus.archive.implementation.LamusArchiveFileHelperTest.java

@Test
public void createFileAndDirectoriesBothExistingAlready() throws IOException {

    final String fileName = "file.cmdi";
    prepareExistingTempDirectory();/* ww  w . ja v  a2  s  .  c o m*/

    final File file = new File(existingTempDirectory, fileName);
    FileUtils.touch(file);

    testArchiveFileHelper.createFileAndDirectories(file);

    assertTrue("File should have been created", file.exists());
}

From source file:ome.formats.importer.OMEROWrapperTest.java

@BeforeMethod
public void createPNG() throws Exception {
    fake = TempFileManager.create_path("omerowrappertest.", ".fake");
    png = TempFileManager.create_path("omerowrappertest.", ".png");
    FileUtils.touch(fake);
    FormatTools.convert(fake.getAbsolutePath(), png.getAbsolutePath());
}

From source file:ome.io.nio.PixelsService.java

private PixelsPyramidMinMaxStore performWrite(final Pixels pixels, final File pixelsPyramidFile,
        final BfPyramidPixelBuffer pixelsPyramid, final File pixelsFile, final String pixelsFilePath,
        final String originalFilePath) {

    final PixelBuffer source;
    final Dimension tileSize;
    final PixelsPyramidMinMaxStore minMaxStore;

    if (pixelsFile.exists()) {
        minMaxStore = null;/*from  w  w w  .  ja  v  a 2  s.c om*/
        source = createRomioPixelBuffer(pixelsFilePath, pixels, false);
        // FIXME: This should be configuration or service driven
        // FIXME: Also implemented in RenderingBean.getTileSize()
        tileSize = new Dimension(Math.min(pixels.getSizeX(), sizes.getTileWidth()),
                Math.min(pixels.getSizeY(), sizes.getTileHeight()));
    } else {
        minMaxStore = new PixelsPyramidMinMaxStore(pixels.getSizeC());
        int series = getSeries(pixels);
        BfPixelBuffer bfPixelBuffer = createMinMaxBfPixelBuffer(originalFilePath, series, minMaxStore);
        pixelsPyramid
                .setByteOrder(bfPixelBuffer.isLittleEndian() ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN);
        source = bfPixelBuffer;
        // If the tile sizes we've been given are completely ridiculous
        // then reset them to WIDTHxHEIGHT. Currently these conditions are:
        //  * TileWidth == ImageWidth
        //  * TileHeight == ImageHeight
        //  * Smallest tile dimension divided by the largest resolution
        //    level factor is < 1.
        // -- Chris Allan (ome:#5224).
        final Dimension sourceTileSize = source.getTileSize();
        final double tileWidth = sourceTileSize.getWidth();
        final double tileHeight = sourceTileSize.getHeight();
        final boolean tileDimensionTooSmall;
        double factor = Math.pow(2, 5);
        if (((tileWidth / factor) < 1.0) || ((tileHeight / factor) < 1.0)) {
            tileDimensionTooSmall = true;
        } else {
            tileDimensionTooSmall = false;
        }
        if (tileWidth == source.getSizeX() || tileHeight == source.getSizeY() || tileDimensionTooSmall) {
            tileSize = new Dimension(Math.min(pixels.getSizeX(), sizes.getTileWidth()),
                    Math.min(pixels.getSizeY(), sizes.getTileHeight()));
        } else {
            tileSize = sourceTileSize;
        }
    }
    log.info("Destination pyramid tile size: " + tileSize);

    try {
        final double totalTiles = source.getSizeZ() * source.getSizeC() * source.getSizeT()
                * (Math.ceil(source.getSizeX() / tileSize.getWidth()))
                * (Math.ceil(source.getSizeY() / tileSize.getHeight()));
        final int tenPercent = Math.max((int) totalTiles / 10, 1);
        Utils.forEachTile(new TileLoopIteration() {
            public void run(int z, int c, int t, int x, int y, int w, int h, int tileCount) {
                if (log.isInfoEnabled() && tileCount % tenPercent == 0) {
                    log.info(String.format("Pyramid creation for Pixels:%d %d/%d (%d%%).", pixels.getId(),
                            tileCount + 1, (int) totalTiles, (int) (tileCount / totalTiles * 100)));
                }
                try {
                    PixelData tile = source.getTile(z, c, t, x, y, w, h);
                    pixelsPyramid.setTile(tile.getData().array(), z, c, t, x, y, w, h);
                } catch (IOException e1) {
                    log.error("FAIL -- Error during tile population", e1);
                    try {
                        pixelsPyramidFile.delete();
                        FileUtils.touch(pixelsPyramidFile); // ticket:5189
                    } catch (Exception e2) {
                        log.warn("Error clearing empty or incomplete pixel " + "buffer.", e2);
                    }
                    return;
                }
            }
        }, source, (int) tileSize.getWidth(), (int) tileSize.getHeight());

        log.info("SUCCESS -- Pyramid created for pixels id:" + pixels.getId());

    }

    finally {
        if (source != null) {
            try {
                source.close();
            } catch (IOException e) {
                log.error("Error closing pixel pyramid.", e);
            }
        }
    }
    return minMaxStore;
}

From source file:ome.io.nio.utests.GetPixelBufferUnitTest.java

private void touchPyramid() throws IOException {
    File pyramidFile = filePyramid();
    FileUtils.touch(pyramidFile);
}

From source file:ome.io.nio.utests.GetPixelBufferUnitTest.java

private String touchRomio() throws Exception {
    File romioFile = fileRomio();
    FileUtils.touch(romioFile);
    return romioFile.getAbsolutePath();
}

From source file:ome.services.blitz.test.ManagedRepositoryITest.java

/**
 * Generate a multi-file fake data set by touching "test.fake" and then
 * converting that into a multi-file format (here, ics). Thanks, Melissa.
 *
 * @param dir Directory in which the fakes are created.
 * @return {@link File} object for one of the two files that can be imported.
 * @throws Exception/*from ww  w .ja  v  a 2 s  . co  m*/
 */
protected ImportContainer makeFake(File dir) throws Exception {
    File fake = new File(dir, "test.fake");
    File ids = new File(dir, "test.ids");
    File ics = new File(dir, "test.ics");
    FileUtils.touch(fake);
    FormatTools.convert(fake.getAbsolutePath(), ids.getAbsolutePath());
    ImportContainer ic = new ImportContainer(ids, null /*target*/, null /*user pixels */, null /*reader*/,
            new String[] { ids.getAbsolutePath(), ics.getAbsolutePath() }, Boolean.FALSE /*spw*/);
    return ic;
}