Example usage for java.io File toString

List of usage examples for java.io File toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns the pathname string of this abstract pathname.

Usage

From source file:org.eclipse.virgo.ide.runtime.internal.core.Server20Handler.java

/**
 * {@inheritDoc}/* w ww  .  j  ava2  s.c om*/
 */
public List<IRuntimeClasspathEntry> getRuntimeClasspath(IPath installPath) {
    List<IRuntimeClasspathEntry> cp = new ArrayList<IRuntimeClasspathEntry>();

    IPath binPath = installPath.append("lib");
    if (binPath.toFile().exists()) {
        File libFolder = binPath.toFile();
        for (File library : libFolder.listFiles(new FileFilter() {
            public boolean accept(File pathname) {
                return pathname.isFile() && pathname.toString().endsWith(".jar");
            }
        })) {
            IPath path = binPath.append(library.getName());
            cp.add(JavaRuntime.newArchiveRuntimeClasspathEntry(path));
        }
    }

    return cp;
}

From source file:de.unikassel.puma.openaccess.classification.PublicationClassificator.java

private void initialise() {
    ArrayList<ClassificationSource> cceList = new ArrayList<ClassificationSource>();
    cceList.add(new ClassificationXMLChainElement(new JELClassification()));
    cceList.add(new ClassificationXMLChainElement(new ACMClassification()));
    cceList.add(new ClassificationTextChainElement(new DDCClassification()));

    File path = new File(xmlPath);

    if (path.isDirectory()) {

        File[] files = path.listFiles(new FileFilter() {

            @Override/*  w  ww  .  ja  v a 2s.  co  m*/
            public boolean accept(File file) {
                if (file.isDirectory()) {
                    return false;
                }

                if (!file.toString().endsWith(".properties")) {
                    return true;
                }

                return false;
            }
        });

        for (File f : files) {
            try {
                Classification c = null;

                for (int i = 0; i < cceList.size() && !present(c); ++i) {
                    c = cceList.get(i).getClassification(f.toURI().toURL());
                }

                if (!present(c)) {
                    log.error("Unable to parse " + f.getName());
                    continue;
                }

                log.info("Found Classification " + c.getClassName());

                //try to read values from .properties file
                try {
                    Properties properties = new Properties();
                    org.bibsonomy.model.Classification classification = new org.bibsonomy.model.Classification();

                    properties.load(
                            new FileReader(f.getAbsolutePath().substring(0, f.getAbsolutePath().length() - 4)
                                    + ".properties"));

                    classification.setName(properties.getProperty("name"));
                    classification.setDesc(properties.getProperty("desc"));
                    classification.setUrl(properties.getProperty("url"));

                    classifications.put(classification, c);

                } catch (IOException e) {
                    //no .properties file found, use the file name                  
                    org.bibsonomy.model.Classification classification = new org.bibsonomy.model.Classification();
                    classification.setName(f.getName().substring(0, f.getName().length() - 4));
                    classifications.put(classification, c);
                }
            } catch (MalformedURLException e) {

                e.printStackTrace();
            } catch (IOException e) {

                e.printStackTrace();
            }
        }
    }
}

From source file:FileMonitor.java

/**
 * Adds a monitored file with a FileChangeListener.
 * /*  ww w.jav  a2 s. c  o  m*/
 * @param listener
 *          listener to notify when the file changed.
 * @param fileName
 *          name of the file to monitor.
 * @param period
 *          polling period in milliseconds.
 */
public void addFileChangeListener(FileChangeListener listener, File file, long period)
        throws FileNotFoundException {
    removeFileChangeListener(listener, file);
    FileMonitorTask task = new FileMonitorTask(listener, file);
    timerEntries.put(file.toString() + listener.hashCode(), task);
    timer.schedule(task, period, period);
}

From source file:com.boundlessgeo.geoserver.api.controllers.IO.java

private static String source(File file, GeoServerDataDirectory dataDir) {
    File baseDirectory = dataDir.getResourceLoader().getBaseDirectory();
    return file.isAbsolute() ? file.toString() : Paths.convert(baseDirectory, file);
}

From source file:com.genericworkflownodes.knime.base.data.port.FileStorePrefixURIPortObject.java

/**
 * Triggers the re-indexing of the current content of the port, by
 * collecting all files that share the given prefix. This method should be
 * called after all content was generated inside the file store.
 *//*from w ww.ja va2s. c o m*/
public void collectFiles() {
    // we have generated a list of files based on a prefix
    final File f = new File(getPrefix());

    Iterator<File> fIt = FileUtils.iterateFiles(f.getParentFile(), TrueFileFilter.INSTANCE,
            TrueFileFilter.INSTANCE);

    while (fIt.hasNext()) {
        File tf = fIt.next();
        if (!tf.isDirectory()) {
            final String abs_path = tf.getAbsolutePath();
            if (abs_path.startsWith(getPrefix())) {
                // get relative path to filestore as string
                File relPath = new File(tf.getName());
                File parent = tf.getParentFile();
                while (!parent.equals(getFileStoreRootDirectory())) {
                    relPath = new File(parent.getName(), relPath.toString());
                    parent = parent.getParentFile();
                }

                // register the found file at the underlying
                // FileStoreURIPortObject
                registerFile(relPath.toString());
            }
        }
    }

}

From source file:com.photon.phresco.service.api.DocumentGeneratorTest.java

@Test
public final void testGenerateWithNoDocuments() {
    ProjectInfo info = new ProjectInfo();
    info.setName("DocTest123");
    info.setVersion("1.0");
    info.setDescription(//from w ww.j av a2s . c  o m
            "PHP Project demostrating the dynamic generation of documents.\n This also has various modules and libraries to help developer to write their piece of software little quicker and in standard way. ");
    Technology technology = new Technology("tech-phpdru7", "Drupal7");
    info.setTechnology(technology);
    RepositoryManager repoManager = PhrescoServerFactory.getRepositoryManager();
    try {
        PhrescoServerFactory.initialize();
        List<ProjectInfo> pilotProjects = repoManager.getPilotProjects(info.getTechnology().getId());
        for (ProjectInfo projectInfo : pilotProjects) {
            List<ModuleGroup> modules = projectInfo.getTechnology().getModules();
            List<ModuleGroup> modules2 = technology.getModules();
            if (CollectionUtils.isEmpty(modules2)) {
                modules2 = new ArrayList<ModuleGroup>(8);
                technology.setModules(modules2);
            }
            modules2.addAll(modules);
        }
    } catch (PhrescoException e1) {
        fail("Exception caught....at testGenerateWithNoDocuments" + e1.getMessage());
    }
    DocumentGenerator docgen = PhrescoServerFactory.getDocumentGenerator();
    String docTempFolder = System.getProperty(Constants.JAVA_TMP_DIR) + File.separator + "phresco";
    File file = new File(docTempFolder);
    if (file.exists()) {
        file.mkdirs();
    }
    try {
        docgen.generate(info, file);
        System.out.println("file generated at " + file.toString());
    } catch (PhrescoException e) {
    } finally {
        removeFiles();
    }
}

From source file:de.lmu.ifi.dbs.jfeaturelib.utils.PackageScanner.java

List<String> getNames(Package inPackage)
        throws UnsupportedEncodingException, URISyntaxException, ZipException, IOException {
    List<String> binaryNames = new ArrayList<>();

    String packagePath = inPackage.getName();
    packagePath = packagePath.replace('.', '/');

    // During tests, this points to the classes/ directory, later, this points to the jar
    CodeSource src = PackageScanner.class.getProtectionDomain().getCodeSource();
    URL location = src.getLocation();
    // test case//from  www .  ja  v a 2 s  . c o m
    File dirOrJar = new File(location.toURI());
    if (dirOrJar.isDirectory()) {
        // +1 to include the slash after the directory name
        int basePathLength = dirOrJar.toString().length() + 1;
        File packageDir = new File(dirOrJar, packagePath);

        // list all .class files in this package directory
        for (File file : packageDir.listFiles((FilenameFilter) new SuffixFileFilter(".class"))) {
            // strip the leading directory
            String binaryName = file.getPath().substring(basePathLength);
            binaryName = pathToBinary(binaryName);
            binaryNames.add(binaryName);
        }

    } else {
        try (ZipFile jar = new ZipFile(dirOrJar)) {
            for (Enumeration entries = jar.entries(); entries.hasMoreElements();) {
                String binaryName = ((ZipEntry) entries.nextElement()).getName();
                if (!binaryName.endsWith(".class")) { // we only need classes
                    continue;
                }
                if (binaryName.startsWith(packagePath)) {
                    binaryName = pathToBinary(binaryName);
                    binaryNames.add(binaryName);
                }
            }
        }
    }

    return binaryNames;
}

From source file:com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.SpinnakerProfile.java

/**
 * @param node is the node to find required files in.
 * @return the list of files required by the node to function.
 *///w ww .  j a v  a 2 s  . co  m
List<String> processRequiredFiles(Node node) {
    List<String> files = new ArrayList<>();

    Consumer<Node> fileFinder = n -> files.addAll(n.localFiles().stream().map(f -> {
        try {
            f.setAccessible(true);
            String fPath = (String) f.get(n);
            if (fPath == null) {
                return null;
            }

            File fFile = new File(fPath);
            String fName = fFile.getName();

            // Hash the path to uniquely flatten all files into the output directory
            Path newName = Paths.get(spinnakerOutputDependencyPath, Math.abs(fPath.hashCode()) + "-" + fName);
            File parent = newName.toFile().getParentFile();
            if (!parent.exists()) {
                parent.mkdirs();
            } else if (fFile.getParent().equals(parent.toString())) {
                // Don't move paths that are already in the right folder
                return fPath;
            }
            Files.copy(Paths.get(fPath), newName, REPLACE_EXISTING);

            f.set(n, newName.toString());
            return newName.toString();
        } catch (IllegalAccessException e) {
            throw new RuntimeException("Failed to get local files for node " + n.getNodeName(), e);
        } catch (IOException e) {
            throw new HalException(
                    new ProblemBuilder(FATAL, "Failed to backup user file: " + e.getMessage()).build());
        } finally {
            f.setAccessible(false);
        }
    }).filter(Objects::nonNull).collect(Collectors.toList()));
    node.recursiveConsume(fileFinder);

    return files;
}

From source file:dk.netarkivet.common.utils.SimpleXml.java

/**
 * Loads an xml file./*  ww w.j  a v a2 s  . c om*/
 *
 * @param f a XML file
 */
private void load(File f) {
    source = f.toString();

    if (!f.exists()) {
        log.warn("XML file '" + f.getAbsolutePath() + "' does not exist");
        throw new IOFailure("XML file '" + f.getAbsolutePath() + "' does not exist");
    }

    xmlDoc = XmlUtils.getXmlDoc(f);
}

From source file:com.symbian.driver.plugins.comms.stat.StatTransfer.java

public boolean delete(File aSymbianFile, boolean aIsFolder) {
    LOGGER.info("Deleting file/folder " + aSymbianFile.toString());
    JStatResult lResult = null;//from  ww w .  j  a  v  a 2s  .  co  m
    String lDir = aSymbianFile.toString().replaceAll("/", "\\");
    try {
        if (aIsFolder) {
            lResult = iStatProxy.getStat().removeFolder(lDir);
        } else {
            lResult = iStatProxy.getStat().delete(lDir);
        }

        if (lResult.getReturnedValue() == 13) {
            return true;
        }

    } catch (TimeLimitExceededException lTimeLimitExceededException) {
        LOGGER.log(Level.SEVERE, "Time limit exeeded", lTimeLimitExceededException);
    } catch (JStatException lJStatException) {
        LOGGER.log(Level.SEVERE, "STAT exception", lJStatException);
    }
    LOGGER.log(Level.SEVERE,
            "Failed to delete file " + aSymbianFile + ((lResult != null) ? " : " + lResult.toString() : ""));
    return false;
}