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:com.microfocus.application.automation.tools.run.JobConfigRebrander.java

/**
 * Converts xml files which is located in the root directory
 * That is responsible for the configuration files located at the "Manage Jenkins -> Configure System".
 * @param listener  a place to send log output
 * @param root      the root directory//from  ww  w . j  a  v a  2s.co m
 */
private void convertXmlFilesAtRootDir(@Nonnull TaskListener listener, File root) {
    try {
        File[] files = root.listFiles(pathname -> {
            String name = pathname.getName().toLowerCase();
            return (name.startsWith("com.hpe") || name.startsWith("com.hp")) && name.endsWith(".xml")
                    && pathname.isFile();
        });

        for (File file : files) {
            String newFileName = file.toString().replaceAll(HPE_HP_REGEX, MICROFOCUS);
            File replacedFile = new File(newFileName);

            removeXmlFileIfExists(listener, newFileName, replacedFile);
            convertXmlFileIfNotExists(listener, file, replacedFile);
        }
    } catch (SecurityException | NullPointerException e) {
        listener.error("Failed to convert Global Settings configurations to microfocus: %s", e.getMessage());
        build.setResult(Result.FAILURE);
    }
}

From source file:com.ssy.isor.ws.impl.ImageWS.java

@Override
public Response getImage(@PathParam("module") String module, @PathParam("fileId") String fileId,
        @QueryParam("filename") String filename) throws FileNotFoundException {
    try {/*from  w  w w.ja  v a2 s  .c om*/
        String filePath = FileUtils.createFolder(isorConfig.getImagesRootPath() + module, fileId) + filename;
        File file = new File(filePath);
        if (file.exists()) {
            String fileExt = file.toString().substring(file.toString().lastIndexOf('.') + 1);
            // This default is standard for browsers
            MediaType mediaType = MediaType.APPLICATION_OCTET_STREAM_TYPE;
            if (fileExt.equalsIgnoreCase(ImageType.IMAGE_JPG)
                    || fileExt.equalsIgnoreCase(ImageType.IMAGE_JPEG)) {
                mediaType = new MediaType("image", ImageType.IMAGE_JPG);
            } else if (fileExt.equalsIgnoreCase(ImageType.IMAGE_GIF)) {
                mediaType = new MediaType("image", ImageType.IMAGE_GIF);
            } else if (fileExt.equalsIgnoreCase(ImageType.IMAGE_PNG)) {
                mediaType = new MediaType("image", ImageType.IMAGE_PNG);
            } else if (fileExt.equalsIgnoreCase(ImageType.IMAGE_ZIP)) {
                mediaType = new MediaType("image", ImageType.IMAGE_ZIP);
            }
            return Response.ok().type(mediaType).entity(new FileInputStream(file)).build();
        }
    } catch (IOException e) {
        LOG.error("create dest file path error.", e);
    }
    throw new WebApplicationException(Response.Status.NOT_FOUND);
}

From source file:net.lightbody.bmp.proxy.jetty.html.Include.java

private void includeFile(File file) throws IOException {
    if (!file.exists())
        throw new FileNotFoundException(file.toString());

    if (file.isDirectory()) {
        List list = new List(List.Unordered);
        String[] ls = file.list();
        for (int i = 0; i < ls.length; i++)
            list.add(ls[i]);/*from w  ww  .  jav  a  2 s.co m*/
        StringWriter sw = new StringWriter();
        list.write(sw);
        reader = new StringReader(sw.toString());
    } else {
        reader = new BufferedReader(new FileReader(file));
    }
}

From source file:se.ivankrizsan.messagecowboy.integrationtest.camel.CamelTaskConfigRefreshTest.java

/**
 * Performs preparations before each test.
 *
 * @throws Exception If error occurs.//from w  ww .j a va 2 s  .  c o m
 */
@Before
public void setUp() throws Exception {
    final String theDestDirPath = createTestDestinationDirectory();
    createTestFileWithContent();

    LOGGER.info("Files in input directory before task execution");
    for (Object theInputDirectoryFileObject : FileUtils.listFiles(mTestInputDirectory, null, false)) {
        File theInputDirectoryFile = (File) theInputDirectoryFileObject;
        LOGGER.info("File: {}", theInputDirectoryFile.toString());
    }

    /* Original configuration contains a non-existing inbound directory. */
    final String theInboundFileEndpointUri = "file://no-such-directory";
    final String theOutboundFileEndpointUri = "file://" + theDestDirPath;

    /* Insert task configuration into database. */
    MessageCowboySchedulableTaskConfig theTask = new MessageCowboySchedulableTaskConfig();
    theTask.setName(TEST_TASK_CONFIG_NAME);
    theTask.setTaskGroupName("TestTasksGroup");
    theTask.setCronExpression("* * * * * ?");
    /* Task start date: Two seconds from now. */
    final Date theStartDate = new Date(System.currentTimeMillis() + 2000L);
    theTask.setStartDate(theStartDate);
    theTask.setInboundEndpointURI(theInboundFileEndpointUri);
    theTask.setOutboundEndpoint(theOutboundFileEndpointUri);
    theTask.setTaskEnabledFlag(true);

    mTaskConfigurationService.save(theTask);

    mMessageCowboyService.scheduleTasks();
}

From source file:net.sf.ehcache.config.Configurator.java

/**
 * Configures a bean from an XML file./*from  w w  w  .ja va  2 s .c o  m*/
 */
public void configure(final Object bean, final File file) throws Exception {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Configuring ehcache from file: " + file.toString());
    }
    final SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
    final BeanHandler handler = new BeanHandler(bean);
    parser.parse(file, handler);
}

From source file:org.trpr.platform.batch.impl.jetty.JettyWebAppContextFactory.java

/**
 * Interface method implementation. Creates and returns a WebAppContext instance
 * @see org.springframework.beans.factory.FactoryBean#getObject()
 */// w  w w.  ja  v  a2 s.  co m
public WebAppContext getObject() throws Exception {
    String path = null;
    File[] files = FileLocator.findDirectories(this.getContextPath(), null);
    for (File file : files) {
        // we need only WEB-INF from batch-core project and none else even by mistake
        String fileToString = file.toString();
        if (fileToString.contains("batch-core")) {
            path = fileToString;
            break;
        }
    }
    if (path.contains(".jar!") && path.startsWith("file:/")) {
        path = path.replace("file:/", "jar:file:/");
    }
    // trim off the "WEB-INF" part as the WebAppContext path should refer to the parent directory
    if (path.endsWith("WEB-INF")) {
        path = path.replace("WEB-INF", "");
    }
    WebAppContext webAppContext = new WebAppContext(path, this.getContextName());
    webAppContext.setMaxFormContentSize(this.getMaxFormContentSize());
    return webAppContext;
}

From source file:org.trpr.platform.servicefw.jetty.JettyWebAppContextFactory.java

/**
 * Interface method implementation. Creates and returns a WebAppContext instance
 * @see org.springframework.beans.factory.FactoryBean#getObject()
 *///  w w  w.  j ava2 s  .  co m
public WebAppContext getObject() throws Exception {
    String path = null;
    File[] files = FileLocator.findDirectories(this.getContextPath(), null);
    for (File file : files) {
        // we need only WEB-INF from batch-core project and none else even by mistake
        String fileToString = file.toString();
        if (fileToString.contains("serviceframework-core")) {
            path = fileToString;
            break;
        }
    }
    if (path.contains(".jar!") && path.startsWith("file:/")) {
        path = path.replace("file:/", "jar:file:/");
    }
    // trim off the "WEB-INF" part as the WebAppContext path should refer to the parent directory
    if (path.endsWith("WEB-INF")) {
        path = path.replace("WEB-INF", "");
    }
    WebAppContext webAppContext = new WebAppContext(path, this.getContextName());
    webAppContext.setMaxFormContentSize(this.getMaxFormContentSize());
    return webAppContext;
}

From source file:de.erdesignerng.visual.editor.openxavaexport.OpenXavaExportEditor.java

private void commandChooseSrcDirectory() {
    JFileChooser theChooser = new JFileChooser();
    theChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    if (theChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
        File theBaseDirectory = theChooser.getSelectedFile();
        editingView.getSrcDirectory().setText(theBaseDirectory.toString());
    }/* w w  w .  j  a v  a2  s  .c  om*/
}

From source file:com.github.fge.jsonschema.main.cli.Main.java

private RetCode doValidation(final Reporter reporter, final List<File> files)
        throws IOException, ProcessingException {
    final File schemaFile = files.remove(0);
    final String uri = schemaFile.toURI().normalize().toString();
    JsonNode node;//w  w w .ja  va2 s.com

    node = MAPPER.readTree(schemaFile);
    if (!syntaxValidator.schemaIsValid(node)) {
        System.err.println("Schema is invalid! Aborting...");
        return SCHEMA_SYNTAX_ERROR;
    }

    final JsonSchema schema = factory.getJsonSchema(uri);

    RetCode ret = ALL_OK, retcode;

    for (final File file : files) {
        node = MAPPER.readTree(file);
        retcode = reporter.validateInstance(schema, file.toString(), node);
        if (retcode != ALL_OK)
            ret = retcode;
    }

    return ret;
}

From source file:com.github.maven_nar.cpptasks.compiler.AbstractCompiler.java

/**
 * Checks file name to see if parse should be attempted
 *
 * Default implementation returns false for files with extensions '.dll',
 * 'tlb', '.res'/*from   www  .j  a  v  a2 s. c om*/
 *
 */
protected boolean canParse(final File sourceFile) {
    final String sourceName = sourceFile.toString();
    final int lastPeriod = sourceName.lastIndexOf('.');
    if (lastPeriod >= 0 && lastPeriod == sourceName.length() - 4) {
        final String ext = sourceName.substring(lastPeriod).toUpperCase();
        if (ext.equals(".DLL") || ext.equals(".TLB") || ext.equals(".RES")) {
            return false;
        }
    }
    return true;
}