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:tools.descartes.bungee.viewer.AllocationSeriesView.java

/**
 * Shows the given selection in this view.
 */// w  ww .  ja  v a  2 s .  c  om
public void showSelection(IWorkbenchPart sourcepart, ISelection selection) {
    if (selection instanceof IStructuredSelection) {
        Iterator<?> iterator = ((IStructuredSelection) selection).iterator();
        List<ResourceAllocation> allocations = null;
        DemandSupplyContainer benchedSeries = null;
        DlimAdapter dlim = null;
        while (iterator.hasNext()) {
            Object element = iterator.next();
            if (element instanceof IResource) {
                File file = ((IResource) element).getLocation().toFile();
                if (AllocationSeries.isAllocationFile(file)) {
                    allocations = AllocationSeries.readAllocations(file);
                    setContentDescription(file.toString());
                } else if (DemandSupplyContainer.isSeriesContainer(file)) {
                    benchedSeries = DemandSupplyContainer.read(file);
                    setContentDescription(file.toString());
                } else if (DlimAdapter.isDLIMFile(file)) {
                    dlim = DlimAdapter.read(file, 1);
                }
            }
        }
        if (allocations != null || benchedSeries != null) {
            if (chartComposite != null) {
                chartComposite.dispose();
            }
            JFreeChart chart;
            if (benchedSeries != null) {
                if (dlim != null) {
                    chart = ChartGenerator.allocationChart(benchedSeries, dlim.getArrivalRates(), false);
                } else {
                    chart = ChartGenerator.allocationChart(benchedSeries, false);
                }
            } else {
                chart = ChartGenerator.allocationChart(allocations);
            }
            chartComposite = new ChartComposite(parent, SWT.NONE, chart, false);
            // repaint
            parent.layout(true);
        }
    }
}

From source file:com.buaa.cfs.utils.FileUtil.java

/**
 * A wrapper for {@link File#list()}. This java.io API returns null when a dir is not a directory or for any I/O
 * error. Instead of having null check everywhere File#list() is used, we will add utility API to get around this
 * problem. For the majority of cases where we prefer an IOException to be thrown.
 *
 * @param dir directory for which listing should be performed
 *
 * @return list of file names or empty string list
 *
 * @throws IOException for invalid directory or for a bad disk.
 *///from ww  w .  jav a  2 s  .c om
public static String[] list(File dir) throws IOException {
    String[] fileNames = dir.list();
    if (fileNames == null) {
        throw new IOException("Invalid directory or I/O error occurred for dir: " + dir.toString());
    }
    return fileNames;
}

From source file:FileMangement.PathFinder.java

@SuppressWarnings("empty-statement")
public Path[] FileCreator(String filename, boolean m3uCheck) throws IOException {

    File paths = new File(filename);
    String[] pattern;/*from   w w  w  .j  av  a 2 s  .  c o m*/

    if (m3uCheck != true) {
        pattern = patternCreator.patternCreator(true, false, false, false, 1);
    } else {
        pattern = new String[1];
        pattern[0] = "*.m3u";
    }

    String str = paths.toString();
    String slash = "\\";

    String s = new StringBuilder(str).append(slash).toString();
    Path startingDir = Paths.get(s);

    int i = 0;
    while (i < pattern.length) {
        Finder finder = new Finder(pattern[i]);
        Files.walkFileTree(startingDir, finder);

        listOfPaths = ArrayUtils.addAll(listOfPaths, NullCleaner(finder.returnArray()));
        finalTotal = finder.done(finalTotal);
        i++;
    }

    //    StringBuffer sb = new StringBuffer(listOfPaths[1].getFileName().toString());
    //  sb.delete(sb.length()-4,sb.length()) ;

    //  System.out.println(sb);

    //  System.out.println(Arrays.toString(listOfPaths));

    //   System.out.println("Total Matched Number of Files : " + finalTotal);

    return listOfPaths;
}

From source file:cz.cas.lib.proarc.common.imports.TiffImporterTest.java

@Test
public void testConsume() throws Exception {
    temp.setDeleteOnExit(true);/*from   w ww . java2 s .c  om*/
    File targetFolder = ImportProcess.createTargetFolder(temp.getRoot());
    assertTrue(targetFolder.exists());

    String mimetype = ImportProcess.findMimeType(tiff1);
    assertNotNull(mimetype);

    ImportOptions ctx = new ImportOptions(tiff1.getParentFile(), "scanner:scanner1", true, junit,
            config.getImportConfiguration());
    ctx.setTargetFolder(targetFolder);
    Batch batch = new Batch();
    batch.setId(1);
    batch.setFolder(ibm.relativizeBatchFile(tiff1.getParentFile()));
    ctx.setBatch(batch);
    FileSet fileSet = ImportFileScanner.getFileSets(Arrays.asList(tiff1, ocr1, alto1, ac1, uc1)).get(0);
    ctx.setJhoveContext(jhoveContext);

    TiffImporter instance = new TiffImporter(ibm);
    BatchItemObject result = instance.consume(fileSet, ctx);
    String pid = result.getPid();
    assertTrue(pid.startsWith("uuid"));

    assertEquals(ObjectState.LOADED, result.getState());

    File foxml = result.getFile();
    assertTrue(foxml.toString(), foxml.exists());

    File rootFoxml = new File(foxml.getParent(), ImportBatchManager.ROOT_ITEM_FILENAME);
    assertTrue(rootFoxml.toString(), rootFoxml.exists());

    File raw1 = new File(targetFolder, "img1.full.jpg");
    assertTrue(raw1.exists() && raw1.length() > 0);

    File preview1 = new File(targetFolder, "img1.preview.jpg");
    assertTrue(preview1.exists() && preview1.length() > 0);

    File thumb1 = new File(targetFolder, "img1.thumb.jpg");
    assertTrue(thumb1.exists() && thumb1.length() > 0);

    // validate FOXML
    SchemaFactory sfactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    URL foxmlXsdUrl = ObjectFactory.class.getResource("/xsd/foxml/foxml1-1.xsd");
    assertNotNull(foxmlXsdUrl);
    Schema foxmlXsd = sfactory.newSchema(foxmlXsdUrl);
    foxmlXsd.newValidator().validate(new StreamSource(foxml));

    // check datastreams with xpath
    HashMap<String, String> namespaces = new HashMap<String, String>();
    namespaces.put("f", "info:fedora/fedora-system:def/foxml#");
    XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(namespaces));
    String foxmlSystemId = foxml.toURI().toASCIIString();
    XMLAssert.assertXpathExists(streamXPath(ModsStreamEditor.DATASTREAM_ID), new InputSource(foxmlSystemId));
    XMLAssert.assertXpathExists(streamXPath(DcStreamEditor.DATASTREAM_ID), new InputSource(foxmlSystemId));
    XMLAssert.assertXpathExists(streamXPath(StringEditor.OCR_ID), new InputSource(foxmlSystemId));
    XMLAssert.assertXpathExists(streamXPath(AltoDatastream.ALTO_ID), new InputSource(foxmlSystemId));
    XMLAssert.assertXpathExists(streamXPath(RelationEditor.DATASTREAM_ID), new InputSource(foxmlSystemId));
    XMLAssert.assertXpathExists(streamXPath(BinaryEditor.FULL_ID), new InputSource(foxmlSystemId));
    XMLAssert.assertXpathExists(streamXPath(BinaryEditor.PREVIEW_ID), new InputSource(foxmlSystemId));
    XMLAssert.assertXpathExists(streamXPath(BinaryEditor.THUMB_ID), new InputSource(foxmlSystemId));
    XMLAssert.assertXpathExists(streamXPath(BinaryEditor.RAW_ID), new InputSource(foxmlSystemId));
    XMLAssert.assertXpathExists(streamXPath(MixEditor.RAW_ID), new InputSource(foxmlSystemId));
    XMLAssert.assertXpathExists(streamXPath(BinaryEditor.NDK_ARCHIVAL_ID), new InputSource(foxmlSystemId));
    XMLAssert.assertXpathExists(streamXPath(BinaryEditor.NDK_USER_ID), new InputSource(foxmlSystemId));
    XMLAssert.assertXpathExists(streamXPath(MixEditor.NDK_ARCHIVAL_ID), new InputSource(foxmlSystemId));

    String rootSystemId = rootFoxml.toURI().toASCIIString();
    XMLAssert.assertXpathExists(streamXPath(RelationEditor.DATASTREAM_ID), new InputSource(rootSystemId));
    EasyMock.verify(toVerify.toArray());
}

From source file:com.github.notizklotz.derbunddownloader.download.IssueDownloadService.java

private String startDownload(LocalDate issueDate, boolean wifiOnly) {
    final String title = expandTemplateWithDate(ISSUE_TITLE_TEMPLATE, issueDate);
    final String filename = expandTemplateWithDate(ISSUE_FILENAME_TEMPLATE, issueDate);
    if (BuildConfig.DEBUG) {
        File extFilesDir = getExternalFilesDir(null);
        File file = new File(extFilesDir, filename);
        Log.d(LOG_TAG, "Filename: " + file.toString());
        Log.d(LOG_TAG, "Can write? " + (extFilesDir != null && extFilesDir.canWrite()));
    }//from   ww  w .j a  va  2  s.c  o m

    Uri issueUrl = Uri.parse(expandTemplateWithDate(ISSUE_PDF_URL_TEMPLATE, issueDate));
    DownloadManager.Request pdfDownloadRequest = new DownloadManager.Request(issueUrl).setTitle(title)
            .setDescription(expandTemplateWithDate(ISSUE_DESCRIPTION_TEMPLATE, issueDate))
            .setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE)
            .setDestinationInExternalFilesDir(this, null, filename);

    if (wifiOnly) {
        pdfDownloadRequest.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            pdfDownloadRequest.setAllowedOverMetered(false);
        }
    }
    downloadManager.enqueue(pdfDownloadRequest);

    return title;
}

From source file:com.buaa.cfs.utils.FileUtil.java

/**
 * Convert a os-native filename to a path that works for the shell.
 *
 * @param file              The filename to convert
 * @param makeCanonicalPath Whether to make canonical path for the file passed
 *
 * @return The unix pathname/*from w w  w  .  j a  v  a2s . co  m*/
 *
 * @throws IOException on windows, there can be problems with the subprocess
 */
public static String makeShellPath(File file, boolean makeCanonicalPath) throws IOException {
    if (makeCanonicalPath) {
        return makeShellPath(file.getCanonicalPath());
    } else {
        return makeShellPath(file.toString());
    }
}

From source file:com.totsp.mavenplugin.gwt.scripting.ScriptWriterWindows.java

/**
 * Write test scripts.//from w  w  w .j  ava 2 s.c o m
 */
public void writeTestScripts(AbstractGWTMojo mojo) throws MojoExecutionException {

    // get extras
    String extra = (mojo.getExtraJvmArgs() != null) ? mojo.getExtraJvmArgs() : "";
    String testExtra = mojo.getExtraTestArgs() != null ? mojo.getExtraTestArgs() : "";

    // make sure output dir is present
    File outputDir = new File(mojo.getBuildDir(), "gwtTest");
    outputDir.mkdirs();
    outputDir.mkdir();

    // for each test compile source root, build a test script
    List<String> testCompileRoots = mojo.getProject().getTestCompileSourceRoots();
    for (String currRoot : testCompileRoots) {

        Collection<File> coll = FileUtils.listFiles(new File(currRoot),
                new WildcardFileFilter(mojo.getTestFilter()), HiddenFileFilter.VISIBLE);

        for (File currFile : coll) {

            String testName = currFile.toString();
            mojo.getLog().debug(("gwtTest test match found (after filter applied) - " + testName));

            // parse off the extension
            if (testName.lastIndexOf('.') > testName.lastIndexOf(File.separatorChar)) {
                testName = testName.substring(0, testName.lastIndexOf('.'));
            }
            if (testName.startsWith(currRoot)) {
                testName = testName.substring(currRoot.length());
            }
            if (testName.startsWith(File.separator)) {
                testName = testName.substring(1);
            }
            testName = StringUtils.replace(testName, File.separatorChar, '.');
            mojo.getLog().debug("testName after parsing - " + testName);

            // start script inside gwtTest output dir, and name it with test class name
            File file = new File(mojo.getBuildDir() + File.separator + "gwtTest",
                    "gwtTest-" + testName + ".cmd");
            PrintWriter writer = this.getPrintWriterWithClasspath(mojo, file, DependencyScope.TEST);

            // build Java command
            writer.print("\"" + mojo.getJavaCommand() + "\" ");
            if (extra.length() > 0) {
                writer.print(" " + extra + " ");
            }
            if (testExtra.length() > 0) {
                writer.print(" " + testExtra + " ");
            }

            writer.print("-cp %CLASSPATH% ");

            writer.print("-Dcatalina.base=\"" + mojo.getTomcat().getAbsolutePath() + "\" ");

            writer.print("junit.textui.TestRunner ");
            writer.print(testName);

            // write script out                
            writer.flush();
            writer.close();
        }
    }
}

From source file:dk.statsbiblioteket.alto.AnagramHashingTest.java

private File getInputFolder() {
    for (File input : INPUT_FOLDERS) {
        // Directly available?
        if (input.exists()) {
            return input;
        }/* ww w . jav a 2 s . co m*/
        // Maybe on the class path?
        URL url = Thread.currentThread().getContextClassLoader().getResource(input.toString());
        if (url != null) {
            return new File(url.getFile());
        }
        log.debug("Sample '" + input.getAbsolutePath() + "' did not exist");
    }
    throw new IllegalArgumentException("None of the possible input folders existed. "
            + "Please provide at least one folder containing .alto.xml-files");
}

From source file:com.google.jenkins.plugins.credentials.oauth.P12ServiceAccountConfig.java

private String writeP12KeyToFile(FileItem p12KeyFileItem) throws IOException {
    File p12KeyFileObject = KeyUtils.createKeyFile("key", ".p12");
    InputStream stream = p12KeyFileItem.getInputStream();
    try {/*w  w  w. ja  va 2s  .  co  m*/
        KeyUtils.writeKeyToFile(stream, p12KeyFileObject);
    } finally {
        IOUtils.closeQuietly(stream);
    }
    return p12KeyFileObject.toString();
}

From source file:com.wangzhe.autojoin.wangfw.server.jetty9.JettyRunner.java

/**
 * Establish Scratch directory for the servlet context (used by JSP
 * compilation)/*w  ww.  j  ava 2s  . co  m*/
 */
private File getScratchDir() throws IOException {
    File tempDir = new File(System.getProperty("java.io.tmpdir"));
    File scratchDir = new File(tempDir.toString(), "embedded-jetty-jsp");

    if (!scratchDir.exists()) {
        if (!scratchDir.mkdirs()) {
            throw new IOException("Unable to create scratch directory: " + scratchDir);
        }
    }
    return scratchDir;
}