Example usage for java.io File getParent

List of usage examples for java.io File getParent

Introduction

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

Prototype

public String getParent() 

Source Link

Document

Returns the pathname string of this abstract pathname's parent, or null if this pathname does not name a parent directory.

Usage

From source file:ch.unibas.fittingwizard.application.base.MoleculesDir.java

public boolean contains(File selectedDir) {
    return FilenameUtils.equalsNormalized(directory.getAbsolutePath(), selectedDir.getParent());
}

From source file:md.archivers.ZIPArchiver.java

private String createNameForZip(File f) {
    String path = f.getParent();
    int pos = path.lastIndexOf(File.separator);
    String baseDir = path.substring(pos + 1);
    String zipPath = baseDir + File.separator + f.getName();
    return zipPath;
}

From source file:com.huawei.streaming.cql.executor.mergeuserdefinds.RenameRule.java

/**
 * {@inheritDoc}/*from   w  w w.j  ava  2 s  .c o  m*/
 */
@Override
public void execute(File srcFile, File distFile, String jarName) throws IOException {
    String parent = distFile.getParent();
    String newFilePath = parent + File.separator + jarName + "." + srcFile.getName();
    FileUtils.copyFile(srcFile, new File(newFilePath));
}

From source file:mx.itesm.imb.EcoreImbEditor.java

@SuppressWarnings("unchecked")
private static void writeSelectionAspect(final File ecoreProject, final String typesPackage,
        final List<String> types) {
    Writer writer;//from  www .  ja  va 2  s  . com
    String packageName;
    VelocityContext context;
    StringBuilder validTypes;
    Collection<File> contributorFiles;

    try {
        validTypes = new StringBuilder();
        for (String type : types) {
            if (!type.toLowerCase().equals("system")) {
                validTypes.append("validTypes.add(\"" + type + "\");\n");
            }
        }

        contributorFiles = FileUtils.listFiles(
                new File(ecoreProject.getParent(), ecoreProject.getName() + ".editor"), new IOFileFilter() {
                    @Override
                    public boolean accept(File dir, String file) {
                        return file.endsWith("Contributor.java");
                    }

                    @Override
                    public boolean accept(File file) {
                        return file.getName().endsWith("Contributor.java");
                    }
                }, TrueFileFilter.INSTANCE);

        for (File contributor : contributorFiles) {
            context = new VelocityContext();
            packageName = contributor.getPath()
                    .substring(contributor.getPath().indexOf("src") + "src".length() + 1,
                            contributor.getPath().indexOf(contributor.getName().replace(".java", "")) - 1)
                    .replace('/', '.');

            context.put("validTypes", validTypes);
            context.put("packageName", packageName);
            context.put("typesPackage", typesPackage);
            context.put("contributor", contributor.getName().replace(".java", ""));

            writer = new FileWriter(new File(contributor.getParentFile(), "SelectionAspect.aj"));
            EcoreImbEditor.selectionTemplate.merge(context, writer);
            writer.close();
            break;
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("Unable to update selection service: " + e.getMessage());
    }
}

From source file:net.solarnetwork.node.weather.nz.metservice.test.MetserviceDayDatumDataSourceTest.java

private MetserviceDayDatumDataSource createDataSourceInstance() throws Exception {

    URL url = getClass().getResource(RISE_SET_RESOURCE_NAME);
    File f = ResourceUtils.getFile(url);
    String baseDirectory = f.getParent();

    MetserviceDayDatumDataSource ds = new MetserviceDayDatumDataSource();
    ds.setBaseUrl("file://" + baseDirectory);
    ds.setRiseSet(RISE_SET_RESOURCE_NAME);
    ds.setObjectMapper(new ObjectMapper());
    return ds;//from   ww w  . j a v  a  2s . c o  m
}

From source file:net.solarnetwork.node.weather.nz.metservice.test.MetserviceWeatherDatumDataSourceTest.java

private MetserviceWeatherDatumDataSource createDataSourceInstance() throws Exception {

    URL url = getClass().getResource("localObs_wellington-city.json");
    File f = ResourceUtils.getFile(url);
    String baseDirectory = f.getParent();

    MetserviceWeatherDatumDataSource ds = new MetserviceWeatherDatumDataSource();
    ds.setBaseUrl("file://" + baseDirectory);
    ds.setLocalObs(f.getName());/*from w ww  . ja v  a  2 s  . co  m*/
    ds.setLocalForecast("localForecastwellington-city.json");
    ds.setObjectMapper(new ObjectMapper());
    return ds;
}

From source file:com.twitter.distributedlog.config.TestDynamicConfigurationFactory.java

private DynamicConfigurationFactory getConfigFactory(File configFile) {
    String streamConfigPath = configFile.getParent();
    ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(1);
    ConcurrentBaseConfiguration defaultConf = new ConcurrentConstConfiguration(
            new DistributedLogConfiguration());
    return new DynamicConfigurationFactory(executorService, 100, TimeUnit.MILLISECONDS);
}

From source file:de.langmi.spring.batch.examples.complex.file.renamefile.partition.extrastep.RenameFilesTasklet.java

@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
    for (Entry<String, String> entry : fileNames.entrySet()) {
        String oldFileName = entry.getKey();
        // remove "file:" part, sometimes there due to spring resource patterns
        if (oldFileName.contains(FILE_PREFIX)) {
            oldFileName = oldFileName.replace(FILE_PREFIX, "");
        }/*from   ww w.j a v a2s.co  m*/
        // old file name
        File oldFile = new File(oldFileName);
        String path = oldFile.getParent();
        String newFilePathAndName = createOutputFileName(path, entry);

        // rename file
        File newFile = new File(newFilePathAndName);
        oldFile.renameTo(newFile);

        LOG.info("renamed:" + oldFile.getPath() + " to:" + newFilePathAndName);
    }

    return RepeatStatus.FINISHED;
}

From source file:org.springsource.sinspctr.rest.SInspctrController.java

private File createBackupFile(File siConfigFile) {
    File newFile = new File(siConfigFile.getParent(), siConfigFile.getName() + ".BAK");
    int cnt = 0;//from   w w w.  java 2  s .c om
    while (newFile.exists() && cnt < 1000) {
        cnt++;
        newFile = new File(siConfigFile.getParent(), siConfigFile.getName() + ".BAK" + cnt);
    }
    return newFile;
}

From source file:io.stallion.dataAccess.file.JsonFilePersister.java

@Override
public void persist(T obj) {
    if (obj.getId() == null) {
        obj.setId(DataAccessRegistry.instance().getTickets().nextId());
    }/*from  w w w. j  a  v a  2  s  . c  o  m*/
    String filePath = fullFilePathForObj(obj);
    File file = new File(filePath);
    File directory = new File(file.getParent());
    if (!directory.isDirectory()) {
        directory.mkdirs();
    }

    try {
        FileUtils.write(file, JSON.stringify(obj), UTF8);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    //ObjectMapper mapper = new ObjectMapper();
    //mapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);
    //try {
    //mapper.writerWithDefaultPrettyPrinter().writeValue(file, obj);
    //} catch (IOException e) {
    //    throw new RuntimeException(e);
    //}

}