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

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

Introduction

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

Prototype

public static void forceMkdir(File directory) throws IOException 

Source Link

Document

Makes a directory, including any necessary but nonexistent parent directories.

Usage

From source file:hoot.services.controllers.ingest.RasterToTilesService.java

public RasterToTilesService() {
    try {//from   www . j  a va2 s  .com
        File f = null;
        if (processScriptName == null) {
            processScriptName = HootProperties.getProperty("RasterToTiles");
        }

        if (_tileServerPath == null) {
            _tileServerPath = HootProperties.getProperty("tileServerPath");
            f = new File(_tileServerPath);
            FileUtils.forceMkdir(f);
        }
        if (appContext == null) {
            appContext = new ClassPathXmlApplicationContext("hoot/spring/CoreServiceContext.xml");
        }
    } catch (Exception ex) {

    }
}

From source file:com.talis.entity.db.babudb.bulk.BabuDbEntityDatabaseBuilder.java

/**
 * Build a BabuDB database for use as a EntityDatabase
 * @param quads A stream of the input quads - must be sorted by subject, then by graph
 * @param outputDir The output location of the BabuDB files
 * @throws IOException //from  w  ww.  j  a  v  a  2s. c o  m
 * @throws BabuDBException 
 */
public void build(InputStream quads, File tmpDir, File outputDir, String dbName)
        throws IOException, BabuDBException {
    LOG.info("Building entity database in {}", outputDir.getAbsolutePath());
    File dbDir = new File(outputDir, dbName);

    initWorkingDirs(tmpDir);
    File tmpDbDir = new File(tmpDir, "db");
    File tmpSortDir = new File(tmpDir, "sort");
    FileUtils.forceMkdir(tmpSortDir);
    Comparator<byte[]> comparator = new DefaultByteRangeComparator();
    PassThruSerializer serializer = new PassThruSerializer();

    ExternalSortWriter<byte[]> sortWriter = new ExternalSortWriter<byte[]>(tmpSortDir, serializer, comparator,
            100000, 2, true);

    EntityIterator entities = new EntityIterator(quads, new Marshaller(new SnappyCodec()));
    ResultSet<Object, Object> iterator = new EntityResultSet(entities, sortWriter);

    // values from default babudb config
    int maxNumRecordsPerBlock = 64;
    int maxBlockFileSize = 52428800;
    boolean compressIndex = false;

    // Write the first babudb index (subject:graph -> po), by virtue of the
    // KeySortWriter, this has the side effect of writing the tmp files to 
    // be used by the merge sort that provides an iterator to build the inverse 
    // (graph:subject -> subject:graph) index in the next step
    DiskIndexWriter firstWriter = new DiskIndexWriter(tmpDbDir.getAbsolutePath(), maxNumRecordsPerBlock,
            compressIndex, maxBlockFileSize);
    firstWriter.writeIndex(iterator);
    sortWriter.flush();
    copyIndexFiles(tmpDbDir, dbDir, "IX0V0SEQ0.idx");
    sortWriter.waitForCompletion();
    FileUtils.deleteDirectory(tmpDbDir);

    // Use a new writer, as they keep an index of the block files they've written,
    // and we want to start again at 0 for the second set of index files
    InverseIndexResultSet inverseIterator = new InverseIndexResultSet(new ExternalSortIterator<byte[]>(
            sortWriter.getTmpDir(), serializer, comparator, sortWriter.compressed()));
    DiskIndexWriter secondWriter = new DiskIndexWriter(tmpDbDir.getAbsolutePath(), maxNumRecordsPerBlock,
            compressIndex, maxBlockFileSize);
    secondWriter.writeIndex(inverseIterator);
    copyIndexFiles(tmpDbDir, dbDir, "IX1V0SEQ0.idx");

    BabuDB dbSystem = makeDatabaseSystem(outputDir);
    Database db = dbSystem.getDatabaseManager().createDatabase(dbName, 2);
    db.shutdown();
    dbSystem.shutdown();
    LOG.info("Done building entity database");
}

From source file:edu.uci.ics.hyracks.control.cc.web.ApplicationInstallationHandler.java

@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    try {/* w  ww  .  j a v a 2  s. c om*/
        while (target.startsWith("/")) {
            target = target.substring(1);
        }
        while (target.endsWith("/")) {
            target = target.substring(0, target.length() - 1);
        }
        String[] parts = target.split("/");
        if (parts.length != 1) {
            return;
        }
        final String[] params = parts[0].split("&");
        String deployIdString = params[0];
        String rootDir = ccs.getServerContext().getBaseDir().toString();
        final String deploymentDir = rootDir.endsWith(File.separator)
                ? rootDir + "applications/" + deployIdString
                : rootDir + File.separator + "/applications/" + File.separator + deployIdString;
        if (HttpMethods.PUT.equals(request.getMethod())) {
            class OutputStreamGetter extends SynchronizableWork {
                private OutputStream os;

                @Override
                protected void doRun() throws Exception {
                    FileUtils.forceMkdir(new File(deploymentDir));
                    String fileName = params[1];
                    File jarFile = new File(deploymentDir, fileName);
                    os = new FileOutputStream(jarFile);
                }
            }
            OutputStreamGetter r = new OutputStreamGetter();
            try {
                ccs.getWorkQueue().scheduleAndSync(r);
            } catch (Exception e) {
                throw new IOException(e);
            }
            try {
                IOUtils.copyLarge(request.getInputStream(), r.os);
            } finally {
                r.os.close();
            }
        } else if (HttpMethods.GET.equals(request.getMethod())) {
            class InputStreamGetter extends SynchronizableWork {
                private InputStream is;

                @Override
                protected void doRun() throws Exception {
                    String fileName = params[1];
                    File jarFile = new File(deploymentDir, fileName);
                    is = new FileInputStream(jarFile);
                }
            }
            InputStreamGetter r = new InputStreamGetter();
            try {
                ccs.getWorkQueue().scheduleAndSync(r);
            } catch (Exception e) {
                throw new IOException(e);
            }
            if (r.is == null) {
                response.setStatus(HttpServletResponse.SC_NOT_FOUND);
            } else {
                response.setContentType("application/octet-stream");
                response.setStatus(HttpServletResponse.SC_OK);
                try {
                    IOUtils.copyLarge(r.is, response.getOutputStream());
                } finally {
                    r.is.close();
                }
            }
        }
        baseRequest.setHandled(true);
    } catch (IOException e) {
        e.printStackTrace();
        throw e;
    }
}

From source file:dbseer.comp.process.live.LiveLogProcessor.java

public void start() throws Exception {
    liveLogExecutor = Executors.newCachedThreadPool();
    sysStartTime = 0;/*www.  j a v a2  s.  c  om*/
    txStartTime = 0;

    // check live directory
    File liveDir = new File(dir);
    if (!liveDir.exists()) {
        // create directories if it does not exist.
        liveDir.mkdirs();
    }

    // start sys log processors
    servers = serverStr.split(MiddlewareConstants.SERVER_STRING_DELIMITER);
    for (String server : servers) {
        FileUtils.forceMkdir(new File(dir + File.separator + server));
        FileUtils.cleanDirectory(new File(dir + File.separator + server));
        File sysFile = new File(dir + File.separator + "sys.log." + server);
        SystemLogProcessor sysLogProcessor;
        if (DBSeerGUI.osType == DBSeerConstants.OS_LINUX) {
            sysLogProcessor = new DstatSystemLogProcessor(dir + File.separator + server, this);
        } else {
            sysLogProcessor = new DstatSystemLogProcessor(dir + File.separator + server, this);
        }
        sysLogProcessor.initialize();
        LiveLogTailer sysLogTailerListener = new LiveLogTailer(sysLogProcessor);
        LogTailer sysLogTailer = new LogTailer(sysFile, sysLogTailerListener, 250, 0, false);

        liveLogExecutor.submit(sysLogTailer);
    }

    // start tx log processors
    TransactionLogProcessor txLogProcessor;
    if (DBSeerGUI.databaseType == DBSeerConstants.DB_MYSQL) {
        txLogProcessor = new MySQLTransactionLogProcessor(DBSeerGUI.settings.mysqlLogDelimiter,
                DBSeerGUI.settings.mysqlQueryDelimiter);
    } else {
        txLogProcessor = new MySQLTransactionLogProcessor(DBSeerGUI.settings.mysqlLogDelimiter,
                DBSeerGUI.settings.mysqlQueryDelimiter);
    }
    File txLogFile = new File(dir + File.separator + "tx.log");
    LiveLogTailer txLogTailerListener = new LiveLogTailer(txLogProcessor);
    LogTailer txLogTailer = new LogTailer(txLogFile, txLogTailerListener, 250, 0, false);

    transactionLogWriter = new TransactionLogWriter(dir, servers, DBSeerGUI.liveMonitorInfo, this);
    transactionLogWriter.initialize();

    liveTransactionLogWriter = new LiveTransactionLogWriter(txLogProcessor, transactionLogWriter);
    liveMonitor = new LiveMonitor();

    liveLogExecutor.submit(txLogTailer);
    liveLogExecutor.submit(liveTransactionLogWriter);
    liveLogExecutor.submit(liveMonitor);
    this.isStarted = true;
}

From source file:com.acc.storefront.filters.AbstractAddOnFilterTest.java

@Before
public void prepare() throws IOException {
    //log("Starting ...");
    MockitoAnnotations.initMocks(this);

    webTargetResource = createWebTargetDir();
    addOnSourceResource = new File(rootSandboxDir, ADDONTWO_NAME + "/acceleratoraddon" + getFolder());

    FileUtils.forceMkdir(webTargetResource);
    FileUtils.forceMkdir(addOnSourceResource);

    LOG.info("Created sandbox dirs");

    setAddOnFilterActive(true);/*ww w.  j  av  a2  s  . c  o  m*/

    final File addOnExtensionPhysicalPath = new File(rootSandboxDir, ADDONTWO_NAME);
    webExtensionPhysicalPath = createWebCtxPhysicalPath();

    Mockito.doReturn(webExtensionPhysicalPath).when(extensionAccessor).getExtensionDir(STOREFRONT_NAME);
    Mockito.doReturn(addOnExtensionPhysicalPath).when(extensionAccessor).getExtensionDir(ADDONTWO_NAME);

}

From source file:cpcc.ros.sim.osm.TileCache.java

/**
 * @param zoom the zoom level//from  ww  w.j  a  va  2  s .  c om
 * @param x the X-coordinate of the tile.
 * @param y the Y-coordinate of the tile.
 * @return the tile as a <code>File</code> object.
 * @throws IOException thrown in case of errors.
 */
@SuppressFBWarnings("PATH_TRAVERSAL_IN")
public File getTile(int zoom, int x, int y) throws IOException {
    String tileCacheFileName = String.format(Locale.US, FORMAT_TILE_CACHE_FILE, tileCacheBaseDir, zoom, x, y);

    File tileCacheFile = new File(tileCacheFileName);

    if (tileCacheFile.exists()) {
        LOG.debug(String.format("Cached tile found for zoom=%d, x=%d, y=%d", zoom, x, y));
        return tileCacheFile;
    }

    String tileCacheDirName = String.format(Locale.US, FORMAT_TILE_CACHE_DIR, tileCacheBaseDir, zoom, x);
    File tileCacheDir = new File(tileCacheDirName);
    if (!tileCacheDir.exists()) {
        FileUtils.forceMkdir(tileCacheDir);
    }

    String tileDownloadUrl = String.format(Locale.US, tileServerUrl, zoom, x, y);

    LOG.debug(String.format("Downloading tile for zoom=%d, x=%d, y=%d, url=%s", zoom, x, y, tileDownloadUrl));

    downloadFile(tileDownloadUrl, tileCacheFile);

    return tileCacheFile;
}

From source file:net.pms.logging.DebugLogPropertyDefiner.java

/**
 * @return first writable folder in the following order:
 * <p>//  w w  w .  j  ava 2s .  c  om
 *     1. (On Linux only) path to {@code /var/log/universalmediaserver/%USERNAME%/}.
 * </p>
 * <p>
 *     2. Path to profile folder ({@code ~/.config/UMS/} on Linux, {@code %ALLUSERSPROFILE%\UMS} on Windows and
 *     {@code ~/Library/Application Support/UMS/} on Mac).
 * </p>
 * <p>
 *     3. Path to user-defined temp folder specified by {@code temp_directory} param in UMS.conf.
 * </p>
 * <p>
 *     4. Path to system temp folder.
 * </p>
 */
public String getDebugLogPath() {
    if (Platform.isLinux()) {
        final String username = System.getProperty("user.name");
        final File logDirectory = new File("/var/log/universalmediaserver/" + username + "/");
        try {
            FileUtils.forceMkdir(logDirectory);
            if (FileUtil.isDirectoryWritable(logDirectory)) {
                return logDirectory.getAbsolutePath();
            }
        } catch (IOException ex) {
            // Could not create directory, possible permissions problems.
        }
    }

    // Check if profile directory is writable.
    final File logDirectory = new File(configuration.getProfileDirectory());
    if (FileUtil.isDirectoryWritable(logDirectory)) {
        return logDirectory.getAbsolutePath();
    }

    // Try user-defined temp folder or fallback to system temp folder, which should be writable.
    try {
        return configuration.getTempFolder().getAbsolutePath();
    } catch (IOException ex) {
        return System.getProperty("java.io.tmpdir");
    }
}

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

/** Rolls to next buffer if necessary */
private void checkBuffer() {
    if (backingBuffer == null || backingBuffer.position() == backingBuffer.limit()) {
        try {//from  w w  w . jav a 2  s  .  c o  m
            if (!backingBufferDir.exists()) {
                FileUtils.forceMkdir(backingBufferDir);
            }
            File backingBufferFile = new File(backingBufferDir, String.valueOf(fileCount));
            FileChannel backingFileChannel = new RandomAccessFile(backingBufferFile, "rw").getChannel();
            backingBuffer = backingFileChannel.map(FileChannel.MapMode.READ_WRITE, 0,
                    documentIncrement * rowSize);
            fileCount++;
            documentCount = 0;
        } catch (Exception e) {
            throw new IllegalStateException(e);
        }
    }
}

From source file:jp.co.tis.gsp.tools.dba.dialect.Dialect.java

protected void exportSchemaGeneral(ExportParams params) throws MojoExecutionException {
    // CSV/*w  w w. j  ava 2 s  .  co m*/
    try {
        File dataDir = new File(params.getOutputDirectory(), DATA_DIR_NAME);
        FileUtils.forceMkdir(dataDir);

        CsvExporter exporter = new CsvExporter(url, driver, params.getSchema(), params.getAdminUser(),
                params.getAdminPassword(), dataDir, UTF8);

        exporter.execute();
    } catch (Exception e1) {
        throw new MojoExecutionException("CSV???????:", e1);
    }

    // DDL & extraDDL??
    try {
        File ddlDir = params.getDdlDirectory();
        File extraDdlDir = params.getExtraDdlDirectory();

        // ???? ddlDirectory???
        if (ddlDir != null && ddlDir.exists()) {
            FileUtils.copyDirectory(params.getDdlDirectory(),
                    new File(params.getOutputDirectory(), DDL_DIR_NAME));
        } else {
            throw new MojoExecutionException("DDL???????");
        }

        // ????
        if (extraDdlDir != null) {
            if (!extraDdlDir.exists())
                throw new MojoExecutionException("extraDDL???????");

            FileUtils.copyDirectory(params.getExtraDdlDirectory(),
                    new File(params.getOutputDirectory(), EXTRADDL_DIR_NAME));
        }

    } catch (IOException e) {
        throw new MojoExecutionException("DDL???????:", e);
    }
}

From source file:io.druid.query.groupby.epinephelinae.LimitedTemporaryStorage.java

/**
 * Create a new temporary file. All methods of the returned output stream may throw
 * {@link TemporaryStorageFullException} if the temporary storage area fills up.
 *
 * @return output stream to the file//from   w  ww.ja  va 2  s.c om
 *
 * @throws TemporaryStorageFullException if the temporary storage area is full
 * @throws IOException                   if something goes wrong while creating the file
 */
public LimitedOutputStream createFile() throws IOException {
    if (bytesUsed.get() >= maxBytesUsed) {
        throw new TemporaryStorageFullException(maxBytesUsed);
    }

    synchronized (files) {
        if (closed) {
            throw new ISE("Closed");
        }

        FileUtils.forceMkdir(storageDirectory);

        final File theFile = new File(storageDirectory, StringUtils.format("%08d.tmp", files.size()));
        final EnumSet<StandardOpenOption> openOptions = EnumSet.of(StandardOpenOption.CREATE_NEW,
                StandardOpenOption.WRITE);

        final FileChannel channel = FileChannel.open(theFile.toPath(), openOptions);
        files.add(theFile);
        return new LimitedOutputStream(theFile, Channels.newOutputStream(channel));
    }
}