Example usage for java.io File separatorChar

List of usage examples for java.io File separatorChar

Introduction

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

Prototype

char separatorChar

To view the source code for java.io File separatorChar.

Click Source Link

Document

The system-dependent default name-separator character.

Usage

From source file:com.medsphere.common.util.PropertyFileLocator.java

private Properties loadPropertiesFromFile(String resourceDirectory, String fileName) {
    Properties props = new Properties();

    String location = resourceDirectory + File.separatorChar + fileName;
    FileInputStream fis = null;//ww  w  . java2  s. co m
    try {
        try {
            fis = new FileInputStream(location);
        } catch (FileNotFoundException e) {
        }
        if (fis != null) {
            try {
                props.load(fis);

                propertiesConfiguration.load(new FileInputStream(location));
                filePath = new File(location).getAbsolutePath();
            } catch (IOException e) {
            } catch (ConfigurationException e) {
            }
        } else {
            location = '/' + resourceDirectory + '/' + fileName;
            InputStream inputStream = this.getClass().getResourceAsStream(location);
            try {
                if (inputStream != null) {
                    try {
                        props.load(inputStream);
                        propertiesConfiguration.load(this.getClass().getResourceAsStream(location));
                        filePath = this.getClass().getResource(location).toExternalForm();
                    } catch (IOException e) {
                    } catch (ConfigurationException e) {
                    }
                }
            } finally {
                if (inputStream != null) {
                    try {
                        inputStream.close();
                    } catch (IOException e) {
                    }
                }
            }
        }

    } finally {

    }

    return props;

}

From source file:com.imaginea.kodebeagle.base.util.Utils.java

@NotNull
public String createFileWithContents(final String displayFileName, final String contents, final String baseDir,
        final String digest) throws IOException {

    final String fileParentPath = String.format("%s%c%s", baseDir, File.separatorChar, digest);
    final File parentDir = new File(fileParentPath);
    FileUtil.createDirectory(parentDir);
    parentDir.deleteOnExit();/* ww  w  .  j  av  a  2 s  .com*/
    final String fullFilePath = String.format("%s%c%s", parentDir.getAbsolutePath(), File.separatorChar,
            displayFileName);
    final File file = new File(fullFilePath);
    if (!file.exists()) {
        FileUtil.createIfDoesntExist(file);
        forceWrite(contents, file);
        file.deleteOnExit();
    }
    return fullFilePath;
}

From source file:it.cilea.osd.jdyna.web.controller.FileServiceController.java

@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String idString = request.getPathInfo();
    String[] pathInfo = idString.split("/", 4);

    String folder = pathInfo[3];//w w  w  .j a  v  a  2  s . c  o m
    String fileName = request.getParameter("filename");

    File dir = new File(getPath() + File.separatorChar + folder);
    File file = new File(dir, fileName);

    if (file.getCanonicalPath().replace("\\", "/").startsWith(dir.getCanonicalPath().replace("\\", "/"))) {
        if (file.exists()) {
            InputStream is = null;
            try {
                is = new FileInputStream(file);

                response.setContentType(request.getSession().getServletContext().getMimeType(file.getName()));
                Long len = file.length();
                response.setContentLength(len.intValue());
                response.setHeader("Content-Disposition", "attachment; filename=" + file.getName());
                FileCopyUtils.copy(is, response.getOutputStream());
                response.getOutputStream().flush();
            } finally {
                if (is != null) {
                    is.close();
                }

            }
        } else {
            throw new RuntimeException("File doesn't exists!");
        }
    } else {
        throw new RuntimeException("No permission to download this file");
    }
    return null;
}

From source file:com.elasticgrid.amazon.boot.BootstrapperTest.java

@Test
public void testMonitorLaunch() throws IOException, EC2Exception {
    String data = "CLUSTER_NAME=test\n" + "AWS_ACCESS_ID=123456123456\n" + "AWS_SECRET_KEY=123456123456\n"
            + "AWS_EC2_AMI32=ami-bdcb2dd4\n" + "AWS_EC2_AMI64=ami-fdcb2d94\n" + "AWS_EC2_KEYPAIR=eg-keypair\n"
            + "AWS_SQS_SECURED=true\n" + "DROP_BUCKET=elastic-grid-drop-target";
    FileUtils.writeStringToFile(new File("/tmp/user-data"), data);
    FileUtils.writeStringToFile(new File("/tmp/security-groups"),
            "elastic-grid, elastic-grid-cluster-test, eg-monitor");
    System.setProperty("EG_HOME", System.getProperty("java.io.tmpdir"));
    new File(System.getProperty("java.io.tmpdir") + File.separatorChar + "config").mkdir();
    Bootstrapper bootstrapper = new Bootstrapper();

    Properties props = new Properties();
    props.load(new FileInputStream(System.getProperty("java.io.tmpdir") + "/config/eg.properties"));
    Assert.assertEquals("Wrong AWS Access ID", "123456123456",
            props.getProperty(EC2Configuration.AWS_ACCESS_ID));
    Assert.assertEquals("Wrong AWS Secret Key", "123456123456",
            props.getProperty(EC2Configuration.AWS_SECRET_KEY));
    Assert.assertEquals("Wrong AWS AMI for 32 bits", "ami-bdcb2dd4",
            props.getProperty(EC2Configuration.AWS_EC2_AMI32));
    Assert.assertEquals("Wrong AWS AMI for 64 bits", "ami-fdcb2d94",
            props.getProperty(EC2Configuration.AWS_EC2_AMI64));
    Assert.assertEquals("Wrong AWS KeyPair", "eg-keypair", props.getProperty(EC2Configuration.AWS_EC2_KEYPAIR));
    Assert.assertEquals("Wrong AWS SQS security setting", "true",
            props.getProperty(EC2Configuration.AWS_SQS_SECURED));
    Assert.assertEquals("Wrong EG Cluster name", "test", props.getProperty(EC2Configuration.EG_CLUSTER_NAME));
    Assert.assertEquals("Wrong EG Drop Bucket", "elastic-grid-drop-target",
            props.getProperty(EC2Configuration.EG_DROP_BUCKET));
}

From source file:com.jaxio.celerio.support.AbstractNamer.java

@Override
public String getPath() {
    return getPackageName().replace('.', File.separatorChar);
}

From source file:com.nridge.ds.neo4j.ds_neo4j.Neo4jGDB.java

public static GraphDatabaseService getInstance(final AppMgr anAppMgr, DataBag aSchemaBag) throws DSException {
    if (mGraphDBService == null) {
        Label graphDBLabel = null;
        if (aSchemaBag != null) {
            String labelName = aSchemaBag.getFeature("labelName");
            if (StringUtils.isNotEmpty(labelName))
                graphDBLabel = Label.label(labelName);
        }/*from   www  .jav  a  2  s  . co  m*/
        String graphDBPathName = anAppMgr.getString(anAppMgr.APP_PROPERTY_GDB_PATH);
        String graphDBSchemaPathFileName = String.format("%s%cschema", graphDBPathName, File.separatorChar);
        File graphDBSchemaFile = new File(graphDBSchemaPathFileName);
        boolean gdbSchemaExists = graphDBSchemaFile.exists();

        // Ensure we have a graph database folder for data storage.

        File graphDBPathFile = new File(graphDBPathName);
        if (!graphDBPathFile.exists())
            graphDBPathFile.mkdir();
        if (!graphDBPathFile.exists()) {
            String msgStr = String.format("%s: Does not exist.", graphDBPathName);
            throw new DSException(msgStr);
        }

        // Prevent a large number of log messages from being generated.

        LogProvider logProvider = new Slf4jLogProvider();

        // Enter the critical section to create the service handle.

        synchronized (Neo4jGDB.class) {
            if (mGraphDBService == null) {
                mGraphDBService = new GraphDatabaseFactory().setUserLogProvider(logProvider)
                        .newEmbeddedDatabaseBuilder(new File(graphDBPathName)).newGraphDatabase();
                if ((aSchemaBag != null) && (!gdbSchemaExists)) {
                    DataField pkField = aSchemaBag.getPrimaryKeyField();
                    if (pkField != null) {
                        Schema gdbSchema;
                        IndexDefinition indexDefinition = null;

                        try (Transaction gdbTransaction = mGraphDBService.beginTx()) {
                            gdbSchema = mGraphDBService.schema();
                            for (DataField dataField : aSchemaBag.getFields()) {
                                if (dataField != pkField) {
                                    if (dataField.isFeatureTrue("isIndexed"))
                                        gdbSchema.indexFor(graphDBLabel).on(dataField.getName()).create();
                                }
                            }
                            indexDefinition = gdbSchema.indexFor(graphDBLabel).on(pkField.getName()).create();
                            gdbTransaction.success();
                        }
                        if (indexDefinition != null) {
                            try (Transaction gdbTransaction = mGraphDBService.beginTx()) {
                                gdbSchema.awaitIndexOnline(indexDefinition, 10, TimeUnit.SECONDS);
                                gdbTransaction.success();
                            }
                        }
                    }
                }
            }
        }
    }

    return mGraphDBService;
}

From source file:com.puppetlabs.geppetto.forge.util.TarUtils.java

private static void append(File file, FileFilter filter, int baseNameLen, String addedTopFolder,
        TarArchiveOutputStream tarOut) throws IOException {

    String name = file.getAbsolutePath();
    if (name.length() <= baseNameLen)
        name = "";
    else/*  w  w w.  j a v  a2s.com*/
        name = name.substring(baseNameLen);
    if (File.separatorChar == '\\')
        name = name.replace('\\', '/');
    if (addedTopFolder != null)
        name = addedTopFolder + '/' + name;

    if (FileUtils.isSymlink(file)) {
        String linkTarget = FileUtils.readSymbolicLink(file);
        if (linkTarget != null) {
            TarArchiveEntry entry = new TarArchiveEntry(name, TarConstants.LF_SYMLINK);
            entry.setName(name);
            entry.setLinkName(linkTarget);
            tarOut.putArchiveEntry(entry);
        }
        return;
    }

    ArchiveEntry entry = tarOut.createArchiveEntry(file, name);
    tarOut.putArchiveEntry(entry);
    File[] children = file.listFiles(filter);
    if (children != null) {
        tarOut.closeArchiveEntry();
        // This is a directory. Append its children
        for (File child : children)
            append(child, filter, baseNameLen, addedTopFolder, tarOut);
        return;
    }

    // Append the content of the file
    InputStream input = new FileInputStream(file);
    try {
        StreamUtil.copy(input, tarOut);
        tarOut.closeArchiveEntry();
    } finally {
        StreamUtil.close(input);
    }
}

From source file:com.katsu.dwm.web.Loader.java

private File createPath(String path) {
    File root = JarUtils.getRootApplicationContentPath();
    File result = new File(root, path.replace('.', File.separatorChar));
    if (result.exists()) {
        result.delete();/*from ww  w  .j a  v  a2 s  . co m*/
    }
    if (result.mkdirs()) {
        logger.trace("Create path: " + result.getPath());
        return result;
    }
    return null;
}

From source file:com.dx.ss.plugins.ptree.impl.DefaultShellCallback.java

public File getDirectory(String targetProject, String targetPackage) {
    // targetProject is interpreted as a directory that must exist
    ///*from  ww w  .  ja v  a 2  s.c  o  m*/
    // targetPackage is interpreted as a sub directory, but in package
    // format (with dots instead of slashes). The sub directory will be
    // created
    // if it does not already exist

    File project = new File(targetProject);
    System.out.println(project.getAbsolutePath());

    StringBuilder sb = new StringBuilder();
    if (!StringUtils.isBlank(targetPackage)) {
        StringTokenizer st = new StringTokenizer(targetPackage, "."); //$NON-NLS-1$
        while (st.hasMoreTokens()) {
            sb.append(st.nextToken());
            sb.append(File.separatorChar);
        }
    }

    File directory = new File(project, sb.toString());
    if (!directory.exists()) {
        boolean rc = directory.mkdirs();
        if (!rc)
            return null;
    }

    return directory;
}

From source file:com.bean.ImagenLogica.java

/**
 * Metodo encargado de la creacion de la ruta de imagen del perfil de usuario actual
 **//*from  w w  w . j av  a  2s . c  o  m*/
public void creaRutaImgPerfil() {
    servletContext = (ServletContext) contexto.getExternalContext().getContext();
    String ruta = "";
    //Ruta real hasta la carpeta de uploads
    ruta = servletContext.getRealPath("/upload/");

    //Concatenamiento de directorios internos
    ruta += File.separatorChar + "img" + File.separatorChar + "users" + File.separatorChar;

    //Asignacion de la ruta creada
    this.rutaImgPerfil = ruta;
}