List of usage examples for java.io File separatorChar
char separatorChar
To view the source code for java.io File separatorChar.
Click Source Link
From source file:mergedoc.core.APIDocument.java
/** * ??/*from w w w . j a va 2 s.c om*/ * @param docDir API * @param className ?? * @param charsetName ?? * @throws IOException ???? */ public APIDocument(File docDir, String className, String charsetName) throws IOException { // API ? StringBuilder path = new StringBuilder(); path.append(docDir.getPath()); path.append(File.separator); path.append(className.replace('.', File.separatorChar)); path.append(".html"); // API ? File docFile = new CachedFile(path.toString()); load(docDir, docFile, charsetName); // API ? // prefix ???? PatternCache ???? String prefix = FastStringUtils.replaceFirst(docFile.getName(), "\\.html$", ""); Pattern innerClass = Pattern.compile(prefix + "\\..+\\.html$"); for (File f : docFile.listFiles()) { if (innerClass.matcher(f.getName()).matches()) { load(docDir, f, charsetName); } } }
From source file:com.tbodt.jswerve.maven.GenerateTemplatesMojo.java
/** * Executes the mojo./* w w w .j a v a 2 s. co m*/ * * @throws MojoExecutionException if something really bad happens */ public void execute() throws MojoExecutionException { DirectoryScanner scanner = new DirectoryScanner(); scanner.addDefaultExcludes(); scanner.setBasedir(sourceDirectory); scanner.setIncludes(new String[] { "**/*.jtl" }); scanner.scan(); for (String templatePath : scanner.getIncludedFiles()) { File template = new File(sourceDirectory, templatePath); String templateClassName = StringUtils.removeEnd(templatePath, ".jtl").replace('.', '_') .replace(File.separatorChar, '.'); int lastDot = templateClassName.lastIndexOf('.'); String templatePackage = templateClassName.substring(0, lastDot); String templateName = templateClassName.substring(lastDot + 1); File outputFile = new File(outputDirectory, templateClassName.replace('.', File.separatorChar) + ".java"); Reader input = null; PrintWriter output = null; try { input = new FileReader(template); getLog().debug(String.valueOf(outputFile.getParentFile().mkdirs())); output = new PrintWriter(new FileWriter(outputFile)); output.println("package " + templatePackage + ";"); output.println(); output.println("public class " + templateName + " implements com.tbodt.jswerve.Template {"); output.println(" @Override"); output.println(" public String render() {"); output.write(Jtl.generateCode(input)); output.println(" }"); output.println("}"); } catch (IOException ioe) { throw new MojoExecutionException("IOException!", ioe); } finally { if (input != null) try { input.close(); } catch (IOException ex) { getLog().error(ex); // nothing else can be done } if (output != null) output.close(); } } // notify maven of the new output directory project.addCompileSourceRoot(outputDirectory.getPath()); }
From source file:org.hawkular.apm.api.services.ConfigurationLoader.java
/** * This method loads the configuration from the supplied URI. * * @param uri The URI/*from w ww. j av a2 s .c o m*/ * @param type The type, or null if default (jvm) * @return The configuration */ protected static CollectorConfiguration loadConfig(String uri, String type) { final CollectorConfiguration config = new CollectorConfiguration(); if (type == null) { type = DEFAULT_TYPE; } uri += java.io.File.separator + type; File f = new File(uri); if (!f.isAbsolute()) { if (f.exists()) { uri = f.getAbsolutePath(); } else if (System.getProperties().containsKey("jboss.server.config.dir")) { uri = System.getProperty("jboss.server.config.dir") + java.io.File.separatorChar + uri; } else { try { URL url = Thread.currentThread().getContextClassLoader().getResource(uri); if (url != null) { uri = url.getPath(); } else { log.severe("Failed to get absolute path for uri '" + uri + "'"); } } catch (Exception e) { log.log(Level.SEVERE, "Failed to get absolute path for uri '" + uri + "'", e); uri = null; } } } if (uri != null) { String[] uriParts = uri.split(Matcher.quoteReplacement(File.separator)); int startIndex = 0; // Remove any file prefix if (uriParts[0].equals("file:")) { startIndex++; } try { Path path = getPath(startIndex, uriParts); Files.walkFileTree(path, new FileVisitor<Path>() { @Override public FileVisitResult postVisitDirectory(Path path, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } @Override public FileVisitResult preVisitDirectory(Path path, BasicFileAttributes attrs) throws IOException { return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException { if (path.toString().endsWith(".json")) { String json = new String(Files.readAllBytes(path)); CollectorConfiguration childConfig = mapper.readValue(json, CollectorConfiguration.class); if (childConfig != null) { config.merge(childConfig, false); } } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path path, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } }); } catch (Throwable e) { log.log(Level.SEVERE, "Failed to load configuration", e); } } return config; }
From source file:com.adito.input.validators.ThemeValidator.java
public void validate(PropertyDefinition definition, String value, Properties properties) throws CodedException { try {/*from w w w. java 2 s . co m*/ super.validate(definition, value, properties); } catch (CoreException ce) { throw new CoreException(ErrorConstants.ERR_EMPTY_THEME, ErrorConstants.CATEGORY_NAME, ErrorConstants.BUNDLE_NAME, null, value, PropertyClassManager.getInstance() .getPropertyClass(ProfileProperties.NAME).getDefinition("ui.theme").getDefaultValue(), null, null); } File themeDirectory = new File(new File("webapp"), value.replace('/', File.separatorChar).replace('\\', File.separatorChar)); if (!themeDirectory.isDirectory()) { throw new CoreException(ErrorConstants.ERR_INVALID_THEME, ErrorConstants.CATEGORY_NAME, ErrorConstants.BUNDLE_NAME, null, value); } }
From source file:org.jvnet.hudson.generators.JobConfigGenerator.java
/** * This returns a String for easier integration with the test cases. * Please, note that the actual writing is also handled here. * * @return/*from w w w . java 2s . c om*/ */ @Override public String generate() { String configBody = getConfigBody(jobConfig.getBuilderType()); BufferedWriter bufferedWriter = null; try { File outputFile = new File(outputDirectory + File.separatorChar + CONFIG_FILE_NAME).getAbsoluteFile(); if (outputFile.exists()) getLog().warn("The output file '" + outputFile + "' already exists!"); bufferedWriter = new BufferedWriter(new FileWriter(outputFile)); bufferedWriter.write(configBody); bufferedWriter.flush(); } catch (IOException e) { e.printStackTrace(); } finally { if (bufferedWriter != null) { try { bufferedWriter.close(); } catch (IOException e) { e.printStackTrace(); } } } return configBody; }
From source file:de.ailis.wlandsuite.PackCurs.java
/** * @see de.ailis.wlandsuite.cli.PackProg#pack(java.io.File, * java.io.OutputStream)//from w ww .j a v a 2 s . c o m */ @Override protected void pack(File directory, OutputStream output) throws IOException { List<Cursor> cursors; EgaImage cursor; EgaImage mask; File file; int cursorNo; // Read the cursors cursors = new ArrayList<Cursor>(); cursorNo = 0; while (true) { file = new File(String.format("%s%c%03d.png", new Object[] { directory.getPath(), File.separatorChar, cursorNo })); if (!file.exists()) { break; } cursor = new EgaImage(ImageIO.read(file)); file = new File(String.format("%s%c%03d_mask.png", new Object[] { directory.getPath(), File.separatorChar, cursorNo })); if (!file.exists()) { log.error("Mask file '" + file.getPath() + "' not found"); } mask = new EgaImage(ImageIO.read(file)); cursors.add(new Cursor(cursor, mask)); cursorNo++; } new Curs(cursors).write(output); }
From source file:it.cilea.osd.jdyna.widget.WidgetFile.java
/** * //w ww .ja va 2 s .c om * Remove file on server by researcher get from parameter method. * * @param fileRP * @param researcher */ public void remove(EmbeddedFile fileRP) { File directory = new File(getBasePath() + File.separatorChar + fileRP.getFolderFile()); if (directory.exists()) { String fileName = fileRP.getValueFile(); if (fileRP.getExtFile() != null && !fileRP.getExtFile().isEmpty()) { fileName += ("." + fileRP.getExtFile()); } Collection<File> files = FileUtils.listFiles(directory, new WildcardFilter(fileName), null); for (File file : files) { file.delete(); } } }
From source file:org.saiku.web.rest.resources.BasicRepositoryResource.java
public void setPath(String path) throws Exception { FileSystemManager fileSystemManager; try {/* w w w . java2s . com*/ if (!path.endsWith("" + File.separatorChar)) { path += File.separatorChar; } fileSystemManager = VFS.getManager(); FileObject fileObject; fileObject = fileSystemManager.resolveFile(path); if (fileObject == null) { throw new IOException("File cannot be resolved: " + path); } if (!fileObject.exists()) { throw new IOException("File does not exist: " + path); } repo = fileObject; } catch (Exception e) { e.printStackTrace(); } }
From source file:org.dspace.app.webui.cris.controller.jdyna.ResearcherTabImageController.java
@Override public ModelAndView handleRequest(HttpServletRequest req, HttpServletResponse response) throws Exception { String idString = req.getPathInfo(); String[] pathInfo = idString.split("/", 3); String tabId = pathInfo[2];//from ww w . j av a 2 s . c o m String contentType = ""; String ext = ""; Tab tab = applicationService.get(Tab.class, Integer.parseInt(tabId)); ext = tab.getExt(); contentType = tab.getMime(); if (ext != null && !ext.isEmpty() && contentType != null && !contentType.isEmpty()) { File image = new File( tab.getFileSystemPath() + File.separatorChar + AFormTabController.DIRECTORY_TAB_ICON + File.separatorChar + AFormTabController.PREFIX_TAB_ICON + tabId + "." + ext); InputStream is = null; try { is = new FileInputStream(image); response.setContentType(contentType); // Response length response.setHeader("Content-Length", String.valueOf(image.length())); Utils.bufferedCopy(is, response.getOutputStream()); is.close(); response.getOutputStream().flush(); } catch (FileNotFoundException not) { log.error(not.getMessage()); response.sendError(HttpServletResponse.SC_NOT_FOUND); } finally { if (is != null) { is.close(); } } } return null; }
From source file:main.server.ClassFinder.java
private void findClasses(File dir, String suffix, Class assignableTo, List<Class> ans) { for (File f : dir.listFiles()) { if (f.isDirectory()) { findClasses(f, suffix, assignableTo, ans); } else if (f.getName().endsWith(suffix)) { String s = f.getAbsolutePath(); s = s.substring(classesPath.length() + 1, s.length() - DOT_CLASS.length()) .replace(File.separatorChar, '.'); try { Class<?> cls = Class.forName(s); if (assignableTo.isAssignableFrom(cls)) { ans.add(cls);//from w w w .ja v a 2 s . co m } } catch (ClassNotFoundException e) { log.error(e, e); } } } }