Example usage for java.io File getCanonicalFile

List of usage examples for java.io File getCanonicalFile

Introduction

In this page you can find the example usage for java.io File getCanonicalFile.

Prototype

public File getCanonicalFile() throws IOException 

Source Link

Document

Returns the canonical form of this abstract pathname.

Usage

From source file:es.ehu.si.ixa.pipe.convert.Convert.java

public void brownClusterClean(File dir) throws IOException {
    // process one file
    if (dir.isFile()) {
        File outfile = new File(dir.getCanonicalFile() + ".clean");
        String outKAF = brownCleanUpperCase(dir);
        Files.write(outKAF, outfile, Charsets.UTF_8);
        System.err.println(">> Wrote clean document to " + outfile);
    } else {/*from w  w  w. j  av  a  2 s.  c o m*/
        // recursively process directories
        File listFile[] = dir.listFiles();
        if (listFile != null) {
            for (int i = 0; i < listFile.length; i++) {
                if (listFile[i].isDirectory()) {
                    brownClusterClean(listFile[i]);
                } else {
                    try {
                        File outfile = new File(listFile[i].getCanonicalFile() + ".clean");
                        String outKAF = brownCleanUpperCase(listFile[i]);
                        Files.write(outKAF, outfile, Charsets.UTF_8);
                        System.err.println(">> Wrote pre-clean document to " + outfile);
                    } catch (FileNotFoundException noFile) {
                        continue;
                    }
                }
            }
        }
    }
}

From source file:org.sonar.cxx.preprocessor.SourceCodeProvider.java

public File getSourceCodeFile(String filename, String cwd, boolean quoted) {
    File result = null;
    File file = new File(filename);
    if (file.isAbsolute()) {
        if (file.isFile()) {
            result = file;/* w w  w.  j  ava 2  s. c om*/
        }
    } else {
        // This seems to be an established convention:
        // The special behavior in the quoted case is to look up relative to the
        // current directory.
        if (quoted) {
            File abspath = new File(new File(cwd), file.getPath());
            if (abspath.isFile()) {
                result = abspath;
            }
        }

        // The standard behavior: lookup relative to to the include roots.
        // The quoted case falls back to this, if its special handling wasnt
        // successul (as forced by the Standard).
        if (result == null) {
            for (File folder : includeRoots) {
                File abspath = new File(folder.getPath(), filename);
                if (abspath.isFile()) {
                    result = abspath;
                    break;
                }
            }
        }
    }

    if (result != null) {
        try {
            result = result.getCanonicalFile();
        } catch (java.io.IOException io) {
            LOG.error("cannot get canonical form of: '{}'", result);
        }
    }

    return result;
}

From source file:org.rhq.plugins.jbossas.JBossASDiscoveryComponent.java

private void processAutoDiscoveredProcesses(ResourceDiscoveryContext context,
        Set<DiscoveredResourceDetails> resources, DiscoveredResourceDetails jbossPcIsEmbeddedIn) {
    List<ProcessScanResult> autoDiscoveryResults = context.getAutoDiscoveredProcesses();
    for (ProcessScanResult autoDiscoveryResult : autoDiscoveryResults) {
        ProcessInfo processInfo = autoDiscoveryResult.getProcessInfo();
        if (log.isDebugEnabled())
            log.debug("Discovered JBoss AS process: " + processInfo);

        JBossInstanceInfo cmdLine;//from  www  .  j  a va 2 s  .c om
        try {
            cmdLine = new JBossInstanceInfo(processInfo);
        } catch (Exception e) {
            log.error("Failed to process JBoss AS command line: " + Arrays.asList(processInfo.getCommandLine()),
                    e);
            continue;
        }

        // See if we have an AS 5 or AS 6 - if so, skip it.
        JBossInstallationInfo installInfo = cmdLine.getInstallInfo();
        String version = installInfo.getVersion();
        if (version.startsWith("5") || version.startsWith("6")) {
            if (log.isDebugEnabled())
                log.debug("Found JBoss AS 5.0 or later, which is not supported by this plugin - skipping...");
            continue;
        }

        File installHome = new File(cmdLine.getSystemProperties().getProperty(JBossProperties.HOME_DIR));
        File configDir = new File(cmdLine.getSystemProperties().getProperty(JBossProperties.SERVER_HOME_DIR));

        if ((jbossPcIsEmbeddedIn != null) && jbossPcIsEmbeddedIn.getPluginConfiguration()
                .getSimple(JBossASServerComponent.CONFIGURATION_PATH_CONFIG_PROP).getStringValue()
                .equals(configDir.getAbsolutePath())) {
            // We're running embedded, and the JBossAS server we're embedded in has already been found.
            continue;
        }

        // The config dir might be a symlink - call getCanonicalFile() to resolve it if so, before
        // calling isDirectory() (isDirectory() returns false for a symlink, even if it points at
        // a directory).
        try {
            if (!configDir.getCanonicalFile().isDirectory()) {
                log.warn("Skipping discovery for JBoss AS process " + processInfo
                        + ", because configuration dir '" + configDir
                        + "' does not exist or is not a directory.");
                continue;
            }
        } catch (IOException e) {
            log.error("Skipping discovery for JBoss AS process " + processInfo + ", because configuration dir '"
                    + configDir + "' could not be canonicalized.", e);
            continue;
        }

        Configuration pluginConfiguration = context.getDefaultPluginConfiguration();

        String jnpURL = getJnpURL(cmdLine, installHome, configDir);

        // Set the connection type (used by JMX plugin to connect to the MBean server).
        pluginConfiguration.put(new PropertySimple(JMXDiscoveryComponent.CONNECTION_TYPE,
                JBossConnectionTypeDescriptor.class.getName()));

        // Set the required props...
        pluginConfiguration.put(new PropertySimple(JBossASServerComponent.NAMING_URL_CONFIG_PROP, jnpURL));
        pluginConfiguration.put(new PropertySimple(JBossASServerComponent.JBOSS_HOME_DIR_CONFIG_PROP,
                installHome.getAbsolutePath()));
        pluginConfiguration
                .put(new PropertySimple(JBossASServerComponent.CONFIGURATION_PATH_CONFIG_PROP, configDir));

        // Set the optional props...
        pluginConfiguration.put(new PropertySimple(JBossASServerComponent.CONFIGURATION_SET_CONFIG_PROP,
                cmdLine.getSystemProperties().getProperty(JBossProperties.SERVER_NAME)));
        pluginConfiguration.put(new PropertySimple(JBossASServerComponent.BINDING_ADDRESS_CONFIG_PROP,
                cmdLine.getSystemProperties().getProperty(JBossProperties.BIND_ADDRESS)));

        JBossASDiscoveryUtils.UserInfo userInfo = JBossASDiscoveryUtils.getJmxInvokerUserInfo(configDir);
        if (userInfo != null) {
            pluginConfiguration.put(
                    new PropertySimple(JBossASServerComponent.PRINCIPAL_CONFIG_PROP, userInfo.getUsername()));
            pluginConfiguration.put(
                    new PropertySimple(JBossASServerComponent.CREDENTIALS_CONFIG_PROP, userInfo.getPassword()));
        }

        String javaHome = processInfo.getEnvironmentVariable(JAVA_HOME_ENV_VAR);
        if (javaHome == null && log.isDebugEnabled()) {
            log.debug("JAVA_HOME environment variable not set in JBoss AS process - defaulting "
                    + JBossASServerComponent.JAVA_HOME_PATH_CONFIG_PROP
                    + " connection property to the plugin container JRE dir.");
        }

        pluginConfiguration
                .put(new PropertySimple(JBossASServerComponent.JAVA_HOME_PATH_CONFIG_PROP, javaHome));

        initLogEventSourcesConfigProp(configDir, pluginConfiguration);

        // Init props that have static defaults.
        setPluginConfigurationDefaults(pluginConfiguration);

        DiscoveredResourceDetails resourceDetails = createResourceDetails(context, pluginConfiguration,
                processInfo, installInfo);
        resources.add(resourceDetails);
    }
}

From source file:org.rhq.modules.plugins.wildfly10.BaseServerComponent.java

private void validateServerAttributes() throws InvalidPluginConfigurationException {
    // Validate the base dir (e.g. /opt/jboss-as-7.1.1.Final/standalone).
    File runtimeBaseDir;//from  w w w  .j ava 2s  .  co  m
    File baseDir = null;
    try {
        String runtimeBaseDirString = readAttribute(getEnvironmentAddress(), getBaseDirAttributeName());
        // Canonicalize both paths before comparing them!
        runtimeBaseDir = new File(runtimeBaseDirString).getCanonicalFile();
        File baseDirTmp = serverPluginConfig.getBaseDir();
        if (baseDirTmp != null) { // may be null for manually added servers
            baseDir = baseDirTmp.getCanonicalFile();
        }
    } catch (Exception e) {
        runtimeBaseDir = null;
        baseDir = null;
        LOG.error("Failed to validate base dir for " + getResourceDescription() + ".", e);
    }
    if ((runtimeBaseDir != null) && (baseDir != null)) {
        if (!runtimeBaseDir.equals(baseDir)) {
            throw new InvalidPluginConfigurationException("The server listening on "
                    + serverPluginConfig.getHostname() + ":" + serverPluginConfig.getPort() + " has base dir ["
                    + runtimeBaseDir + "], but the base dir we expected was [" + baseDir
                    + "]. Perhaps the management hostname or port has been changed for the server with base dir ["
                    + baseDir + "].");
        }
    }

    // Validate the config dir (e.g. /opt/jboss-as-7.1.1.Final/standalone/configuration).
    File runtimeConfigDir;
    File configDir = null;
    try {
        String runtimeConfigDirString = readAttribute(getEnvironmentAddress(), getConfigDirAttributeName());
        // Canonicalize both paths before comparing them!
        runtimeConfigDir = new File(runtimeConfigDirString).getCanonicalFile();
        File configDirTmp = serverPluginConfig.getConfigDir();
        if (configDirTmp != null) { // may be null for manually added servers
            configDir = configDirTmp.getCanonicalFile();
        }
    } catch (Exception e) {
        runtimeConfigDir = null;
        configDir = null;
        LOG.error("Failed to validate config dir for " + getResourceDescription() + ".", e);
    }
    if ((runtimeConfigDir != null) && (configDir != null)) {
        if (!runtimeConfigDir.equals(configDir)) {
            throw new InvalidPluginConfigurationException("The server listening on "
                    + serverPluginConfig.getHostname() + ":" + serverPluginConfig.getPort()
                    + " has config dir [" + runtimeConfigDir + "], but the config dir we expected was ["
                    + configDir
                    + "]. Perhaps the management hostname or port has been changed for the server with config dir ["
                    + configDir + "].");
        }
    }

    // Validate the mode (e.g. STANDALONE or DOMAIN).
    String runtimeMode;
    try {
        runtimeMode = readAttribute("launch-type");
    } catch (Exception e) {
        runtimeMode = null;
        LOG.error("Failed to validate mode for " + getResourceDescription() + ".", e);
    }
    if (runtimeMode != null) {
        String mode = getMode().name();
        if (!runtimeMode.equals(mode)) {
            throw new InvalidPluginConfigurationException("The original mode discovered for this server was "
                    + getMode() + ", but the server is now reporting its mode is [" + runtimeMode + "].");
        }
    }

    // Validate the product type (e.g. AS or EAP).
    String expectedRuntimeProductName = pluginConfiguration.getSimpleValue("expectedRuntimeProductName");
    String runtimeProductName;
    try {
        runtimeProductName = readAttribute(getHostAddress(), "product-name");
    } catch (Exception e) {
        throw new InvalidPluginConfigurationException(
                "Failed to validate product type for " + getResourceDescription(), e);
    }
    if (!runtimeProductName.equals(expectedRuntimeProductName)) {
        if (serverPluginConfig.getProductType() != JBossProductType.WILDFLY) {
            throw new InvalidPluginConfigurationException(
                    "The original product type discovered for this server was " + expectedRuntimeProductName
                            + ", but the server is now reporting its product type is [" + runtimeProductName
                            + "]");
        }
    }
}

From source file:net.minecraftforge.fml.common.Loader.java

/**
 *
 *///from w  ww.  jav  a2  s. com
private void initializeLoader() {
    File modsDir = new File(minecraftDir, "mods");
    File configDir = new File(minecraftDir, "config");
    String canonicalModsPath;
    String canonicalConfigPath;

    try {
        canonicalModsPath = modsDir.getCanonicalPath();
        canonicalConfigPath = configDir.getCanonicalPath();
        canonicalConfigDir = configDir.getCanonicalFile();
        canonicalModsDir = modsDir.getCanonicalFile();
    } catch (IOException ioe) {
        FMLLog.log(Level.ERROR, ioe, "Failed to resolve loader directories: mods : %s ; config %s",
                canonicalModsDir.getAbsolutePath(), configDir.getAbsolutePath());
        throw new LoaderException(ioe);
    }

    if (!canonicalModsDir.exists()) {
        FMLLog.info("No mod directory found, creating one: %s", canonicalModsPath);
        boolean dirMade = canonicalModsDir.mkdir();
        if (!dirMade) {
            FMLLog.severe("Unable to create the mod directory %s", canonicalModsPath);
            throw new LoaderException(
                    String.format("Unable to create the mod directory %s", canonicalModsPath));
        }
        FMLLog.info("Mod directory created successfully");
    }

    if (!canonicalConfigDir.exists()) {
        FMLLog.fine("No config directory found, creating one: %s", canonicalConfigPath);
        boolean dirMade = canonicalConfigDir.mkdir();
        if (!dirMade) {
            FMLLog.severe("Unable to create the config directory %s", canonicalConfigPath);
            throw new LoaderException();
        }
        FMLLog.info("Config directory created successfully");
    }

    if (!canonicalModsDir.isDirectory()) {
        FMLLog.severe("Attempting to load mods from %s, which is not a directory", canonicalModsPath);
        throw new LoaderException();
    }

    if (!configDir.isDirectory()) {
        FMLLog.severe("Attempting to load configuration from %s, which is not a directory",
                canonicalConfigPath);
        throw new LoaderException();
    }

    readInjectedDependencies();
}

From source file:org.fao.geonet.kernel.SvnManager.java

/**
 *  Constructor. Creates the subversion repository if it doesn't exist
   *  or just open the subversion repository if it does. Stores the URL
   *  of the repository in repoUrl. Adds the commit/abort listeners to 
   *  the DbmsPool resource provider./* w w w. ja v  a2  s  .c  o  m*/
 *
   * @param context Service context used to get GeoNetwork context objects
   * @param sm SettingManager used to get system settings like catalog id 
 * @param subversionPath File path of the subversion repository.
 * @param dbms Database used to find resource provider
 * @param created set to true if a new database has been created
 */
public SvnManager(ServiceContext context, SettingManager sm, String subversionPath, Dbms dbms, boolean created)
        throws Exception {

    String dbUrl = dbms.getURL();
    this.context = context;
    String uuid = sm.getValue("system/site/svnUuid");

    if (StringUtils.isEmpty(uuid)) {
        uuid = UUID.randomUUID().toString();
        sm.setValue(dbms, "system/site/svnUuid", uuid);
    }

    File subFile = new File(subversionPath);
    boolean repoCreated = false;

    // if subversion repo doesn't exist then create it with siteId 
    try {
        boolean enableRevisionProperties = true;
        boolean force = false;
        repoUrl = SVNRepositoryFactory.createLocalRepository(subFile, uuid, enableRevisionProperties, force);
        repoCreated = true;
    } catch (SVNException e) {

        if (subFile.exists()) { // set the repoUrl and try and open it
            subFile = subFile.getCanonicalFile();
            repoUrl = SVNURL.fromFile(subFile);

        } else {
            e.printStackTrace();
            throw new IllegalArgumentException(
                    "Problem creating or using repository at path " + subversionPath);
        }
    }

    // open the repository now
    SVNRepository repo = null;
    try {
        repo = getRepository();
    } catch (SVNException se) {
        Log.error(Geonet.SVN_MANAGER, "Failed to open subversion repo at path " + subversionPath);
        se.printStackTrace();
        throw se;
    }

    // do some checks on existing repo and recreate it if empty
    if (!repoCreated) {
        String repoUuid = repo.getRepositoryUUID(true);
        long latestRev = repo.getLatestRevision();
        // check that repository has something in it
        if (latestRev > 1) {
            // check that repository uuid matches the repo uuid in database
            if (!uuid.equals(repoUuid)) {
                throw new IllegalArgumentException("Subversion repository at " + subversionPath + " has uuid "
                        + repoUuid + " which does not match repository uuid held in database " + uuid);
            }
        } else {
            // if nothing in repo and it doesn't have the uuid we expect then 
            // recreate it and reopen it
            if (!uuid.equals(repoUuid)) {
                Log.warning(Geonet.SVN_MANAGER, "Recreating subversion repository at " + subversionPath
                        + " as previous repository was empty");
                boolean enableRevisionProperties = true;
                boolean force = true;
                repoUrl = SVNRepositoryFactory.createLocalRepository(subFile, uuid, enableRevisionProperties,
                        force);
                repoCreated = true;
                repo = getRepository();
            }
        }
    }

    // set database URL as property on root of repository if database was
    // created or if new subversion repo created
    if (created || repoCreated) {
        Map<String, String> props = new HashMap<String, String>();
        props.put(Params.Svn.DBURLPROP, dbUrl);
        ISVNEditor editor = getEditor("Setting " + Params.Svn.DBURLPROP + " to " + dbUrl);
        editor.openRoot(-1);
        SvnUtils.modifyFileProps(editor, "/", props);
        editor.closeDir();
        SVNCommitInfo info = editor.closeEdit();
        if (Log.isDebugEnabled(Geonet.SVN_MANAGER))
            Log.debug(Geonet.SVN_MANAGER,
                    "Committed " + dbUrl + " as property " + Params.Svn.DBURLPROP + ":" + info);
    } else {
        // get database URL from root of repository and check against dbUrl
        // if it doesn't match then stop
        SVNProperties rootProps = new SVNProperties();
        Collection nullColl = null;
        repo.getDir("/", -1, rootProps, nullColl);
        String repoDbUrl = rootProps.getStringValue(Params.Svn.DBURLPROP).trim();
        if (repoDbUrl == null || (!dbUrl.trim().equals(repoDbUrl))) {
            throw new IllegalArgumentException("Repository uses database URL of '" + repoDbUrl
                    + "' which does not match current database URL '" + dbUrl + "'. Modify the svn property "
                    + Params.Svn.DBURLPROP + " on the root of the subversion repository at " + subversionPath
                    + " or specify a different subversion repository");
        }
    }

    // now add the listener to the DbmsPool resource provider
    ProviderManager provMan = context.getProviderManager();
    for (ResourceProvider rp : provMan.getProviders()) {
        if (rp.getName().equals(dbUrl)) {
            rp.addListener(resList);
        }
    }
}

From source file:com.yobidrive.diskmap.needles.NeedleManager.java

private void truncate(NeedlePointer needlePointer) throws NeedleManagerException {
    // Truncate current file
    if (needlePointer.getNeedleOffset() < 0) {
        logger.error("Request for truncating " + needlePointer.toString() + "!!!");
        throw new NeedleManagerException("Request for truncating " + needlePointer.toString() + "!!!");
    }/*from   ww  w. ja  v a  2s .c om*/
    // truncates current file
    FileChannel fc = getChannel(needlePointer.getNeedleFileNumber());
    if (fc == null) {
        logger.error("Request for truncating " + needlePointer.toString() + ", no File Channel!!!");
        throw new NeedleManagerException(
                "Request for truncating " + needlePointer.toString() + ", no File Channel!!!");
    }
    try {
        fc.truncate(needlePointer.getNeedleOffset());
        fc.force(true);
    } catch (IOException ie) {
        logger.error("Error truncating " + needlePointer.toString(), ie);
        throw new NeedleManagerException("Error truncating " + needlePointer.toString(), ie);
    }
    // Removes subsequent files. In fact just rename them and alert via logger
    int logNumber = needlePointer.getNeedleFileNumber() + 1;
    while (channelMap.contains(new Integer(logNumber))) {
        closeChannel(logNumber);
        File toClose = getFile(logNumber);
        if (toClose != null) {
            try {
                toClose.renameTo(new File(toClose.getCanonicalFile() + ".bak"));
            } catch (IOException ie) {
                throw new NeedleManagerException(
                        "Could not rename to .bak for file number " + Integer.toHexString(logNumber));
            }
        }
        logNumber++;
    }
}

From source file:es.ehu.si.ixa.pipe.convert.Convert.java

public void nafToCoNLL02(File dir) throws IOException {
    // process one file
    if (dir.isFile()) {
        KAFDocument kaf = KAFDocument.createFromFile(dir);
        File outfile = new File(dir.getCanonicalFile() + ".conll02");
        String outKAF = nafToCoNLLConvert02(kaf);
        Files.write(outKAF, outfile, Charsets.UTF_8);
        System.err.println(">> Wrote CoNLL document to " + outfile);
    } else {/* w w w  .j  ava  2s.  com*/
        // recursively process directories
        File listFile[] = dir.listFiles();
        if (listFile != null) {
            for (int i = 0; i < listFile.length; i++) {
                if (listFile[i].isDirectory()) {
                    nafToCoNLL02(listFile[i]);
                } else {
                    try {
                        File outfile = new File(listFile[i].getCanonicalFile() + ".conll02");
                        KAFDocument kaf = KAFDocument.createFromFile(listFile[i]);
                        String outKAF = nafToCoNLLConvert02(kaf);
                        Files.write(outKAF, outfile, Charsets.UTF_8);
                        System.err.println(">> Wrote CoNLL02 document to " + outfile);
                    } catch (FileNotFoundException noFile) {
                        continue;
                    }
                }
            }
        }
    }
}

From source file:es.ehu.si.ixa.pipe.convert.Convert.java

public void nafToCoNLL03(File dir) throws IOException {
    // process one file
    if (dir.isFile()) {
        KAFDocument kaf = KAFDocument.createFromFile(dir);
        File outfile = new File(dir.getCanonicalFile() + ".conll03");
        String outKAF = nafToCoNLLConvert03(kaf);
        Files.write(outKAF, outfile, Charsets.UTF_8);
        System.err.println(">> Wrote CoNLL document to " + outfile);
    } else {//w  ww. j  ava 2s  .  c  o  m
        // recursively process directories
        File listFile[] = dir.listFiles();
        if (listFile != null) {
            for (int i = 0; i < listFile.length; i++) {
                if (listFile[i].isDirectory()) {
                    nafToCoNLL03(listFile[i]);
                } else {
                    try {
                        File outfile = new File(listFile[i].getCanonicalFile() + ".conll03");
                        KAFDocument kaf = KAFDocument.createFromFile(listFile[i]);
                        String outKAF = nafToCoNLLConvert03(kaf);
                        Files.write(outKAF, outfile, Charsets.UTF_8);
                        System.err.println(">> Wrote CoNLL03 document to " + outfile);
                    } catch (FileNotFoundException noFile) {
                        continue;
                    }
                }
            }
        }
    }
}

From source file:at.ofai.gate.virtualcorpus.DirectoryCorpus.java

/**
 * Initializes the DirectoryCorpus LR//from   w  w w.  j a va  2s.c om
 * @return 
 * @throws ResourceInstantiationException
 */
@Override
public Resource init() throws ResourceInstantiationException {
    logger.info("DirectoryCorpus: calling init");
    if (directoryURL == null) {
        throw new ResourceInstantiationException("directoryURL must be set");
    }
    // first of all, create a map that contains all the supported extensions
    // as keys and the corresponding documente exporter as value. 

    // First, get all the supported extensions for reading files
    Set<String> readExtensions = DocumentFormat.getSupportedFileSuffixes();
    logger.info("DirectoryCorpus/init readExtensions=" + readExtensions);
    Set<String> supportedExtensions = new HashSet<String>();

    // if we also want to write, we have to limit the supported extensions
    // to those where we have an exporter and also we need to remember which
    // exporter supports which extensions
    if (!getReadonly()) {
        List<Resource> des = null;
        try {
            // Now get all the Document exporters
            des = Gate.getCreoleRegister().getAllInstances("gate.DocumentExporter");
        } catch (GateException ex) {
            throw new ResourceInstantiationException("Could not get the document exporters", ex);
        }
        for (Resource r : des) {
            DocumentExporter d = (DocumentExporter) r;
            if (readExtensions.contains(d.getDefaultExtension())) {
                extension2Exporter.put(d.getDefaultExtension(), d);
                supportedExtensions.add(d.getDefaultExtension());
            }
        }
    } else {
        supportedExtensions.addAll(readExtensions);
    }
    logger.info("DirectoryCorpus/init supportedExtensions=" + readExtensions);

    // now check if an extension list was specified by the user. If no, nothing
    // needs to be done. If yes, remove all the extensions from the extnesion2Exporter
    // map which were not specified and warn about all the extensions specified
    // for which we do not have an entry. Also remove them from the supportedExtensions set
    if (getExtensions() != null && !getExtensions().isEmpty()) {
        logger.info("DirectoryCorpu/init getExtgension is not empty: " + getExtensions());
        for (String ext : getExtensions()) {
            if (!supportedExtensions.contains(ext)) {
                logger.warn("DirectoryCorpus warning: extension is not supported: " + ext);
            }
        }
        // now remove all the extensions which are not specified
        Iterator<String> it = supportedExtensions.iterator();
        while (it.hasNext()) {
            String ext = it.next();
            logger.info("DirectoryCorpus/init checking supported extension: " + ext);
            if (!getExtensions().contains(ext)) {
                logger.info("DirectoryCorpus/init removing extension: " + ext);
                it.remove();
                extension2Exporter.remove(ext);
            }
        }
    }
    logger.info("DirectoryCorpus/init supportedExtensions after parms: " + supportedExtensions);
    logger.info("DirectoryCorpus/init exporter map: " + extension2Exporter);

    if (supportedExtensions.isEmpty()) {
        throw new ResourceInstantiationException(
                "DirectoryCorpus could not be created, no file format supported or loaded");
    }

    backingDirectoryFile = Files.fileFromURL(directoryURL);
    try {
        backingDirectoryFile = backingDirectoryFile.getCanonicalFile();
    } catch (IOException ex) {
        throw new ResourceInstantiationException("Cannot get canonical file for " + backingDirectoryFile, ex);
    }
    if (!backingDirectoryFile.isDirectory()) {
        throw new ResourceInstantiationException("Not a directory " + backingDirectoryFile);
    }

    try {
        ourDS = (DummyDataStore4DirCorp) Factory.createDataStore(
                "at.ofai.gate.virtualcorpus.DummyDataStore4DirCorp",
                backingDirectoryFile.getAbsoluteFile().toURI().toURL().toString());
        ourDS.setName("DummyDS4_" + this.getName());
        ourDS.setComment("Dummy DataStore for DirectoryCorpus " + this.getName());
        ourDS.setCorpus(this);
        //System.err.println("Created dummy corpus: "+ourDS+" with name "+ourDS.getName());
    } catch (Exception ex) {
        throw new ResourceInstantiationException("Could not create dummy data store", ex);
    }
    logger.info("DirectoryCorpus/init: ds created: " + ourDS.getName());

    Iterator<File> fileIt = FileUtils.iterateFiles(backingDirectoryFile,
            supportedExtensions.toArray(new String[0]), getRecurseDirectory());
    int i = 0;
    while (fileIt.hasNext()) {
        File file = fileIt.next();
        // if recursion was specified, we need to get the relative file path
        // relative to the root directory. This is done by getting the canonical
        // full path name for both the directory and the file and then 
        // relativizing the path.
        String filename = file.getName();
        // TODO: first check if this file should be ignored (hidden files?)
        if (!filename.startsWith(".")) {
            if (getRecurseDirectory()) {
                try {
                    file = file.getCanonicalFile();
                } catch (IOException ex) {
                    throw new ResourceInstantiationException("Could not get canonical path for " + file);
                }
                filename = backingDirectoryFile.toURI().relativize(file.toURI()).getPath();
            }
            documentNames.add(filename);
            isLoadeds.add(false);
            documentIndexes.put(filename, i);
            i++;
        }
    }
    if (i == 0) {
        logger.warn("DirectoryCorpus warning: empty immutable corpus created, no files found");
    }
    try {
        PersistenceManager.registerPersistentEquivalent(at.ofai.gate.virtualcorpus.DirectoryCorpus.class,
                at.ofai.gate.virtualcorpus.DirectoryCorpusPersistence.class);
    } catch (PersistenceException e) {
        throw new ResourceInstantiationException("Could not register persistence", e);
    }
    Gate.getCreoleRegister().addCreoleListener(this);
    return this;
}