Java Code Examples for java.io.File#separatorChar()

The following examples show how to use java.io.File#separatorChar() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParseUtil_4922813.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs an encoded version of the specified path string suitable
 * for use in the construction of a URL.
 *
 * A path separator is replaced by a forward slash. The string is UTF8
 * encoded. The % escape sequence is used for characters that are above
 * 0x7F or those defined in RFC2396 as reserved or excluded in the path
 * component of a URL.
 */
public static String encodePath(String path) {
    StringBuffer sb = new StringBuffer();
    int n = path.length();
    for (int i=0; i<n; i++) {
        char c = path.charAt(i);
        if (c == File.separatorChar)
            sb.append('/');
        else {
            if (c <= 0x007F) {
                if (encodedInPath.get(c))
                    escape(sb, c);
                else
                    sb.append(c);
            } else if (c > 0x07FF) {
                escape(sb, (char)(0xE0 | ((c >> 12) & 0x0F)));
                escape(sb, (char)(0x80 | ((c >>  6) & 0x3F)));
                escape(sb, (char)(0x80 | ((c >>  0) & 0x3F)));
            } else {
                escape(sb, (char)(0xC0 | ((c >>  6) & 0x1F)));
                escape(sb, (char)(0x80 | ((c >>  0) & 0x3F)));
            }
        }
    }
    return sb.toString();
}
 
Example 2
Source File: ConcurrentRead.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        if (File.separatorChar == '\\' ||                // Windows
                                !new File(TEE).exists()) // no tee
            return;

        Process p = Runtime.getRuntime().exec(TEE);
        OutputStream out = p.getOutputStream();
        InputStream in = p.getInputStream();
        Thread t1 = new WriterThread(out, in);
        t1.start();
        Thread t2 = new WriterThread(out, in);
        t2.start();
        t1.join();
        t2.join();
        if (savedException != null)
            throw savedException;
    }
 
Example 3
Source File: T6440528.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
void test(String... args) throws Exception {
    fm.setLocation(CLASS_OUTPUT, null); // no class files are
                                        // generated, so this will
                                        // not leave clutter in
                                        // the source directory
    Iterable<File> files = Arrays.asList(new File(test_src, "package-info.java"));
    JavaFileObject src = fm.getJavaFileObjectsFromFiles(files).iterator().next();
    char sep = File.separatorChar;
    FileObject cls = fm.getFileForOutput(CLASS_OUTPUT,
                                         "com.sun.foo.bar.baz",
                                         "package-info.class",
                                         src);
    File expect = new File(test_src, "package-info.class");
    File got = fm.asPath(cls).toFile();
    if (!got.equals(expect))
        throw new AssertionError(String.format("Expected: %s; got: %s", expect, got));
    System.err.println("Expected: " + expect);
    System.err.println("Got:      " + got);
}
 
Example 4
Source File: ParseUtil_4922813.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs an encoded version of the specified path string suitable
 * for use in the construction of a URL.
 *
 * A path separator is replaced by a forward slash. The string is UTF8
 * encoded. The % escape sequence is used for characters that are above
 * 0x7F or those defined in RFC2396 as reserved or excluded in the path
 * component of a URL.
 */
public static String encodePath(String path) {
    StringBuffer sb = new StringBuffer();
    int n = path.length();
    for (int i=0; i<n; i++) {
        char c = path.charAt(i);
        if (c == File.separatorChar)
            sb.append('/');
        else {
            if (c <= 0x007F) {
                if (encodedInPath.get(c))
                    escape(sb, c);
                else
                    sb.append(c);
            } else if (c > 0x07FF) {
                escape(sb, (char)(0xE0 | ((c >> 12) & 0x0F)));
                escape(sb, (char)(0x80 | ((c >>  6) & 0x3F)));
                escape(sb, (char)(0x80 | ((c >>  0) & 0x3F)));
            } else {
                escape(sb, (char)(0xC0 | ((c >>  6) & 0x1F)));
                escape(sb, (char)(0x80 | ((c >>  0) & 0x3F)));
            }
        }
    }
    return sb.toString();
}
 
Example 5
Source File: ICC_Profile.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a file object corresponding to a built-in profile
 * specified by fileName.
 * If there is no built-in profile with such name, then the method
 * returns null.
 */
private static File getStandardProfileFile(String fileName) {
    String dir = System.getProperty("java.home") +
        File.separatorChar + "lib" + File.separatorChar + "cmm";
    String fullPath = dir + File.separatorChar + fileName;
    File f = new File(fullPath);
    return (f.isFile() && isChildOf(f, dir)) ? f : null;
}
 
Example 6
Source File: Main.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void logClassFile(boolean generatePackagesStructure, String outputPath, String relativeFileName) {
	if ((this.tagBits & Logger.XML) != 0) {
		String fileName = null;
		if (generatePackagesStructure) {
			fileName = buildFileName(outputPath, relativeFileName);
		} else {
			char fileSeparatorChar = File.separatorChar;
			String fileSeparator = File.separator;
			// First we ensure that the outputPath exists
			outputPath = outputPath.replace('/', fileSeparatorChar);
			// To be able to pass the mkdirs() method we need to remove the extra file separator at the end of the outDir name
			int indexOfPackageSeparator = relativeFileName.lastIndexOf(fileSeparatorChar);
			if (indexOfPackageSeparator == -1) {
				if (outputPath.endsWith(fileSeparator)) {
					fileName = outputPath + relativeFileName;
				} else {
					fileName = outputPath + fileSeparator + relativeFileName;
				}
			} else {
				int length = relativeFileName.length();
				if (outputPath.endsWith(fileSeparator)) {
					fileName = outputPath + relativeFileName.substring(indexOfPackageSeparator + 1, length);
				} else {
					fileName = outputPath + fileSeparator + relativeFileName.substring(indexOfPackageSeparator + 1, length);
				}
			}
		}
		File f = new File(fileName);
		try {
			this.parameters.put(Logger.PATH, f.getCanonicalPath());
			printTag(Logger.CLASS_FILE, this.parameters, true, true);
		} catch (IOException e) {
			logNoClassFileCreated(outputPath, relativeFileName, e);
		}
	}
}
 
Example 7
Source File: Package.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public Package(Module m, String n) {
    int c = n.indexOf(":");
    assert(c != -1);
    String mn = n.substring(0,c);
    assert(m.name().equals(m.name()));
    name = n;
    dirname = n.replace('.', File.separatorChar);
    if (m.name().length() > 0) {
        // There is a module here, prefix the module dir name to the path.
        dirname = m.dirname()+File.separatorChar+dirname;
    }
}
 
Example 8
Source File: ParseUtil.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static String encodePath(String path, boolean flag) {
    if (flag && File.separatorChar != '/') {
        return encodePath(path, 0, File.separatorChar);
    } else {
        int index = firstEncodeIndex(path);
        if (index > -1) {
            return encodePath(path, index, '/');
        } else {
            return path;
        }
    }
}
 
Example 9
Source File: AnalysisSaikuService.java    From collect-earth with MIT License 5 votes vote down vote up
private File getMdxTemplate() throws IOException {
	final File mdxFileTemplate = new File(
			localPropertiesService.getProjectFolder() + File.separatorChar + MDX_TEMPLATE);
	if (!mdxFileTemplate.exists()) {
		throw new IOException(
				"The file containing the MDX Cube definition Template does not exist in expected location " //$NON-NLS-1$
						+ mdxFileTemplate.getAbsolutePath());
	}
	return mdxFileTemplate;
}
 
Example 10
Source File: Tools.java    From vethrfolnir-mu with GNU General Public License v3.0 5 votes vote down vote up
public static String slashify(String path, boolean isDirectory) {
    String p = path;
    if (File.separatorChar != '/')
        p = p.replace(File.separatorChar, '/');
    if (!p.startsWith("/"))
        p = "/" + p;
    if (!p.endsWith("/") && isDirectory)
        p = p + "/";
    return p;
}
 
Example 11
Source File: CompilerUtils.java    From neembuu-uploader with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get the build directory
 * @param file The java file.
 * @return Returns the build directory.
 */
public static File getBuildDirectory(File file){
    while(!"src".equals(file.getName())){
        file = file.getParentFile();
    }
    return new File(file.getParentFile().getAbsolutePath() + File.separatorChar+ "build");
}
 
Example 12
Source File: JarReorder.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private String cleanFilePath(String path) {
    // Remove leading and trailing whitespace
    path = path.trim();
    // Make all / and \ chars one
    if (File.separatorChar == '/') {
        path = path.replace('\\', '/');
    } else {
        path = path.replace('/', '\\');
    }
    // Remove leading ./
    if (path.startsWith("." + File.separator)) {
        path = path.substring(2);
    }
    return path;
}
 
Example 13
Source File: PythonSnippetUtilsTest.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
protected String platformDependentStr(String s) {
    if (File.separatorChar != '/') {
        return org.python.pydev.shared_core.string.StringUtils
                .replaceAll(s, "/", (File.separator + File.separator));
    } else {
        return s;
    }
}
 
Example 14
Source File: DirectoryResourceListSource.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @see ResourceListSourceSupport#getResources(String)
 */
protected String[] getResources(String basePath)
{
    String root = (basePath == null) ? "" : basePath;
    List resourceNames = new ArrayList();
    List directories = getDirectories();
    for (Iterator i = directories.iterator(); i.hasNext();)
    {
        String cpDirName = (String) i.next();
        String dirName = null;
        if (root.startsWith(File.separator) || cpDirName.endsWith(File.separator))
        {
            dirName = cpDirName + root; 
        }
        else
        {
            dirName = cpDirName + File.separatorChar + root;
        }
        
        File dir = new File(dirName);
        if (dir.exists() && dir.isDirectory())
        {
            File[] files = dir.listFiles(directoryFilter);
            for (int j = 0; j < files.length; j++)
            {
                String fileName = files[j].getName();
                String resourceName = root + File.separator + fileName;
                resourceName = new File(resourceName).getPath();
                resourceNames.add(resourceName);
            }
        }
    }
    
    return (String[]) resourceNames.toArray(new String[resourceNames.size()]);
}
 
Example 15
Source File: GraphSandboxUtil.java    From atlas with Apache License 2.0 4 votes vote down vote up
private static String getStorageDir(String sandboxName, String directory) {
    return System.getProperty("atlas.data") +
            File.separatorChar + sandboxName +
            File.separatorChar + directory;
}
 
Example 16
Source File: CompileProperties.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private static String inferPackageName(String inputPath, String outputPath) {
    // Normalize file names
    inputPath  = new File(inputPath).getPath();
    outputPath = new File(outputPath).getPath();
    // Split into components
    String sep;
    if (File.separatorChar == '\\') {
        sep = "\\\\";
    } else {
        sep = File.separator;
    }
    String[] inputs  = inputPath.split(sep);
    String[] outputs = outputPath.split(sep);
    // Match common names, eliminating first "classes" entry from
    // each if present
    int inStart  = 0;
    int inEnd    = inputs.length - 2;
    int outEnd   = outputs.length - 2;
    int i = inEnd;
    int j = outEnd;
    while (i >= 0 && j >= 0) {
        if (!inputs[i].equals(outputs[j]) ||
                (inputs[i].equals("gensrc") && inputs[j].equals("gensrc"))) {
            ++i;
            ++j;
            break;
        }
        --i;
        --j;
    }
    String result;
    if (i < 0 || j < 0 || i >= inEnd || j >= outEnd) {
        result = "";
    } else {
        if (inputs[i].equals("classes") && outputs[j].equals("classes")) {
            ++i;
        }
        inStart = i;
        StringBuffer buf = new StringBuffer();
        for (i = inStart; i <= inEnd; i++) {
            buf.append(inputs[i]);
            if (i < inEnd) {
                buf.append('.');
            }
        }
        result = buf.toString();
    }
    return result;
}
 
Example 17
Source File: CompileProperties.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private static String inferPackageName(String inputPath, String outputPath) {
    // Normalize file names
    inputPath  = new File(inputPath).getPath();
    outputPath = new File(outputPath).getPath();
    // Split into components
    String sep;
    if (File.separatorChar == '\\') {
        sep = "\\\\";
    } else {
        sep = File.separator;
    }
    String[] inputs  = inputPath.split(sep);
    String[] outputs = outputPath.split(sep);
    // Match common names, eliminating first "classes" entry from
    // each if present
    int inStart  = 0;
    int inEnd    = inputs.length - 2;
    int outEnd   = outputs.length - 2;
    int i = inEnd;
    int j = outEnd;
    while (i >= 0 && j >= 0) {
        if (!inputs[i].equals(outputs[j]) ||
                (inputs[i].equals("gensrc") && inputs[j].equals("gensrc"))) {
            ++i;
            ++j;
            break;
        }
        --i;
        --j;
    }
    String result;
    if (i < 0 || j < 0 || i >= inEnd || j >= outEnd) {
        result = "";
    } else {
        if (inputs[i].equals("classes") && outputs[j].equals("classes")) {
            ++i;
        }
        inStart = i;
        StringBuffer buf = new StringBuffer();
        for (i = inStart; i <= inEnd; i++) {
            buf.append(inputs[i]);
            if (i < inEnd) {
                buf.append('.');
            }
        }
        result = buf.toString();
    }
    return result;
}
 
Example 18
Source File: WebContext.java    From tale with MIT License 4 votes vote down vote up
@Override
public void processor(Blade blade) {
    JetbrickTemplateEngine templateEngine = new JetbrickTemplateEngine();

    List<String> macros = new ArrayList<>(8);
    macros.add(File.separatorChar + "comm" + File.separatorChar + "macros.html");
    // 扫描主题下面的所有自定义宏
    String themeDir = AttachController.CLASSPATH + "templates" + File.separatorChar + "themes";
    File[] dir      = new File(themeDir).listFiles();
    for (File f : dir) {
        if (f.isDirectory() && Files.exists(Paths.get(f.getPath() + File.separatorChar + "macros.html"))) {
            String macroName = File.separatorChar + "themes" + File.separatorChar + f.getName() + File.separatorChar + "macros.html";
            macros.add(macroName);
        }
    }
    StringBuffer sbuf = new StringBuffer();
    macros.forEach(s -> sbuf.append(',').append(s));
    templateEngine.addConfig("jetx.import.macros", sbuf.substring(1));

    GlobalResolver resolver = templateEngine.getGlobalResolver();
    resolver.registerFunctions(Commons.class);
    resolver.registerFunctions(Theme.class);
    resolver.registerFunctions(AdminCommons.class);
    resolver.registerTags(JetTag.class);

    JetGlobalContext context = templateEngine.getGlobalContext();
    context.set("version", environment.get("app.version", "v1.0"));
    context.set("enableCdn", environment.getBoolean("app.enableCdn", false));

    blade.templateEngine(templateEngine);

    TaleConst.ENABLED_CDN = environment.getBoolean("app.enableCdn", false);
    TaleConst.MAX_FILE_SIZE = environment.getInt("app.max-file-size", 20480);

    TaleConst.AES_SALT = environment.get("app.salt", "012c456789abcdef");
    TaleConst.OPTIONS.addAll(optionsService.getOptions());
    String ips = TaleConst.OPTIONS.get(Types.BLOCK_IPS, "");
    if (StringKit.isNotBlank(ips)) {
        TaleConst.BLOCK_IPS.addAll(Arrays.asList(ips.split(",")));
    }
    if (Files.exists(Paths.get(AttachController.CLASSPATH + "install.lock"))) {
        TaleConst.INSTALLED = Boolean.TRUE;
    }

    BaseController.THEME = "themes/" + Commons.site_option("site_theme");

    TaleConst.BCONF = environment;
}
 
Example 19
Source File: ContainerPathManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public String getLogPath() {
  return getSystemPath() + File.separatorChar + "logs";
}
 
Example 20
Source File: SynthFileChooserUI.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void setPattern(String globPattern) {
    char[] gPat = globPattern.toCharArray();
    char[] rPat = new char[gPat.length * 2];
    boolean isWin32 = (File.separatorChar == '\\');
    boolean inBrackets = false;
    int j = 0;

    this.globPattern = globPattern;

    if (isWin32) {
        // On windows, a pattern ending with *.* is equal to ending with *
        int len = gPat.length;
        if (globPattern.endsWith("*.*")) {
            len -= 2;
        }
        for (int i = 0; i < len; i++) {
            if (gPat[i] == '*') {
                rPat[j++] = '.';
            }
            rPat[j++] = gPat[i];
        }
    } else {
        for (int i = 0; i < gPat.length; i++) {
            switch(gPat[i]) {
              case '*':
                if (!inBrackets) {
                    rPat[j++] = '.';
                }
                rPat[j++] = '*';
                break;

              case '?':
                rPat[j++] = inBrackets ? '?' : '.';
                break;

              case '[':
                inBrackets = true;
                rPat[j++] = gPat[i];

                if (i < gPat.length - 1) {
                    switch (gPat[i+1]) {
                      case '!':
                      case '^':
                        rPat[j++] = '^';
                        i++;
                        break;

                      case ']':
                        rPat[j++] = gPat[++i];
                        break;
                    }
                }
                break;

              case ']':
                rPat[j++] = gPat[i];
                inBrackets = false;
                break;

              case '\\':
                if (i == 0 && gPat.length > 1 && gPat[1] == '~') {
                    rPat[j++] = gPat[++i];
                } else {
                    rPat[j++] = '\\';
                    if (i < gPat.length - 1 && "*?[]".indexOf(gPat[i+1]) >= 0) {
                        rPat[j++] = gPat[++i];
                    } else {
                        rPat[j++] = '\\';
                    }
                }
                break;

              default:
                //if ("+()|^$.{}<>".indexOf(gPat[i]) >= 0) {
                if (!Character.isLetterOrDigit(gPat[i])) {
                    rPat[j++] = '\\';
                }
                rPat[j++] = gPat[i];
                break;
            }
        }
    }
    this.pattern = Pattern.compile(new String(rPat, 0, j), Pattern.CASE_INSENSITIVE);
}