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:eionet.gdem.web.struts.stylesheet.GetStylesheetAction.java
@Override public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) {/*from w w w .j av a 2s. c o m*/ ActionMessages errors = new ActionMessages(); String metaXSLFolder = Properties.metaXSLFolder; String tableDefURL = Properties.ddURL; DynaValidatorForm loginForm = (DynaValidatorForm) actionForm; String id = (String) loginForm.get("id"); String convId = (String) loginForm.get("conv"); try { ConversionDto conv = Conversion.getConversionById(convId); String format = metaXSLFolder + File.separatorChar + conv.getStylesheet(); String url = tableDefURL + "/GetTableDef?id=" + id; ByteArrayInputStream byteIn = XslGenerator.convertXML(url, format); int bufLen = 0; byte[] buf = new byte[1024]; // byteIn.re response.setContentType("text/xml"); while ((bufLen = byteIn.read(buf)) != -1) { response.getOutputStream().write(buf, 0, bufLen); } byteIn.close(); return null; } catch (Exception ge) { LOGGER.error("Error getting stylesheet", ge); errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("label.stylesheet.error.generation")); // request.getSession().setAttribute("dcm.errors", errors); request.setAttribute("dcm.errors", errors); return actionMapping.findForward("fail"); } // return null; }
From source file:org.gallery.web.controller.FileController.java
@RequestMapping(value = "/uploadfile", method = RequestMethod.POST) public @ResponseBody Map upload(MultipartHttpServletRequest request, HttpServletResponse response) { log.info("uploadfile called..."); Iterator<String> itr = request.getFileNames(); MultipartFile mpf;//from w w w . j a va 2 s . c om List<DataFileEntity> list = new LinkedList<>(); while (itr.hasNext()) { mpf = request.getFile(itr.next()); String originalFilename = mpf.getOriginalFilename(); log.info("Uploading {}", originalFilename); String key = UUID.randomUUID().toString(); String storageDirectory = fileUploadDirectory; File file = new File(storageDirectory + File.separatorChar + key); try { // Save Images mpf.transferTo(file); // Save FileEntity DataFileEntity dataFileEntity = new DataFileEntity(); dataFileEntity.setName(mpf.getOriginalFilename()); dataFileEntity.setKey(key); dataFileEntity.setSize(mpf.getSize()); dataFileEntity.setContentType(mpf.getContentType()); dataFileDao.save(dataFileEntity); list.add(dataFileEntity); } catch (IOException e) { log.error("Could not upload file " + originalFilename, e); } } Map<String, Object> files = new HashMap<>(); files.put("files", list); return files; }
From source file:com.nridge.core.base.std.FilUtl.java
/** * Generates a unique path based on the parameters provided. * * @param aPathName Optional path name - if not provided, then the current working directory will be used. * @param aPrefix Path name prefix (appended with random id) * * @return A unique path name./*ww w.ja v a 2 s . c o m*/ */ static public String generateUniquePathName(String aPathName, String aPrefix) { if (StringUtils.isEmpty(aPathName)) aPathName = getWorkingDirectory(); if (StringUtils.isEmpty(aPathName)) aPrefix = "subpath"; // http://www.javapractices.com/topic/TopicAction.do?Id=56 UUID uniqueId = UUID.randomUUID(); byte idBytes[] = uniqueId.toString().getBytes(); Checksum checksumValue = new CRC32(); checksumValue.update(idBytes, 0, idBytes.length); long longValue = checksumValue.getValue(); return String.format("%s%c%s_%d", aPathName, File.separatorChar, aPrefix, longValue); }
From source file:net.thackbarth.sparrow.FileReader.java
/** * This method reads the ID3-Tags from the given file and stores them * to the MusicTrack object./*from w w w . ja va2 s . c om*/ * * @param fileToRead the file to read * @param rootFolder the root of the scan. It will be used to calculate * the correct file path. * @param track the object to store the information from the file */ public boolean readFile(File fileToRead, File rootFolder, MusicTrack track) { boolean result = false; try { Mp3File mp3file = new Mp3File(fileToRead.getAbsolutePath()); track.setFilePath(fileToRead.getAbsolutePath().substring(rootFolder.getAbsolutePath().length())); track.setFilePath(track.getFilePath().replace(File.separatorChar, '/')); track.setModificationDate(fileToRead.lastModified()); copyTagField("Album", mp3file, track); copyTagField("Artist", mp3file, track); copyTagField("Genre", mp3file, track); copyTagField("GenreDescription", mp3file, track); copyTagField("Title", mp3file, track); copyTagField("Track", mp3file, track); Set<ConstraintViolation<MusicTrack>> violations = validator.validate(track); if (violations.isEmpty()) { // create Target Filename String newFileName = filenameGenerator.generateName(track); if ((newFileName == null) || (newFileName.isEmpty())) { throw new IllegalStateException( "FilenameGenerator returns wrong value for " + fileToRead.getAbsolutePath()); } track.setTargetFilePath(newFileName); track.setFilePathCorrect(track.getFilePath().equals(track.getTargetFilePath())); if (!track.isFilePathCorrect()) { int endPosition = fileToRead.getAbsolutePath().length() - track.getFilePath().length(); String base = fileToRead.getAbsolutePath().substring(0, endPosition); String target = base.concat(track.getTargetFilePath()); logger.info("Track must be moved to " + target + " -> " + track); } result = true; } else { logger.error("File is not valid: " + fileToRead.getAbsolutePath() + " - " + violations); } } catch (IOException e) { logger.error(EXCEPTION_MESSAGE_MP3, e); } catch (UnsupportedTagException e) { logger.error(EXCEPTION_MESSAGE_MP3, e); } catch (InvalidDataException e) { logger.error(EXCEPTION_MESSAGE_MP3, e); } return result; }
From source file:de.ailis.wlandsuite.FixWlOffsets.java
/** * @see de.ailis.wlandsuite.cli.CLIProg#run(java.lang.String[]) *///from w w w . j a v a 2 s. co m @Override protected void run(String[] params) throws IOException { WlExe wl; List<Integer> oldOffsets, newOffsets; File file; int oldOffset, newOffset; boolean changed = false; // Read wasteland directory parameter if (params.length > 1) { wrongUsage("Too many parameters"); } if (params.length == 0) { wrongUsage("No wasteland directory specified"); } this.wlDir = new File(params[0]).getPath() + File.separatorChar; // Open the wl.exe wl = new WlExe(new File(this.wlDir + "wl.exe")); try { // Fix HTDS1 offsets file = new File(this.wlDir + "allhtds1"); if (file.length() > 34307) { log.warn("allhtds1 file is larger then 34307 bytes. This can cause trouble"); } oldOffsets = wl.getHtds1Offsets(); newOffsets = Htds.getMsqOffsets(file); if (!oldOffsets.equals(newOffsets)) { for (int i = 0; i < oldOffsets.size(); i++) { oldOffset = oldOffsets.get(i).intValue(); newOffset = newOffsets.get(i).intValue(); if (oldOffset != newOffset) { log.info("Adjusting HTDS1 bank " + i + " offset from " + oldOffset + " to " + newOffset); } wl.setHtds1Offsets(newOffsets); changed = true; } } // Fix HTDS2 offsets file = new File(this.wlDir + "allhtds2"); if (file.length() > 39230) { log.warn("allhtds2 file is larger then 39230 bytes. This can cause trouble"); } oldOffsets = wl.getHtds2Offsets(); newOffsets = Htds.getMsqOffsets(new File(this.wlDir + "allhtds2")); if (!oldOffsets.equals(newOffsets)) { for (int i = 0; i < oldOffsets.size(); i++) { oldOffset = oldOffsets.get(i).intValue(); newOffset = newOffsets.get(i).intValue(); if (oldOffset != newOffset) { log.info("Adjusting HTDS2 bank " + i + " offset from " + oldOffset + " to " + newOffset); } wl.setHtds2Offsets(newOffsets); changed = true; } } // Fix PICS1 offsets file = new File(this.wlDir + "allpics1"); if (file.length() > 105866) { log.warn("allpics1 file is larger then 105866 bytes. This can cause trouble"); } oldOffsets = wl.getPics1Offsets(); newOffsets = Pics.getMsqOffsets(file); if (!oldOffsets.equals(newOffsets)) { for (int i = 0; i < oldOffsets.size(); i++) { oldOffset = oldOffsets.get(i).intValue(); newOffset = newOffsets.get(i).intValue(); if (oldOffset != newOffset) { log.info("Adjusting PICS1 offset " + i + " from " + oldOffset + " to " + newOffset); } wl.setPics1Offsets(newOffsets); changed = true; } } // Fix PICS2 offsets file = new File(this.wlDir + "allpics2"); oldOffsets = wl.getPics2Offsets(); newOffsets = Pics.getMsqOffsets(file); if (!oldOffsets.equals(newOffsets)) { for (int i = 0; i < oldOffsets.size(); i++) { oldOffset = oldOffsets.get(i).intValue(); newOffset = newOffsets.get(i).intValue(); if (oldOffset != newOffset) { log.info("Adjusting PICS2 offset " + i + " from " + oldOffset + " to " + newOffset); } wl.setPics2Offsets(newOffsets); changed = true; } } } finally { wl.close(); } if (!changed) { log.info("No offsets need to be fixed"); } }
From source file:org.openmeetings.app.data.file.FileProcessor.java
private void prepareFolderStructure(String current_dir) throws Exception { this.workingDir = current_dir + OpenmeetingsVariables.UPLOAD_DIR + File.separatorChar + "files" + File.separatorChar; // System.out.println("IS SYSTEM PROFILE"); // Add the Folder for the Room if it does not exist yet File localFolder = new File(workingDir); if (!localFolder.exists()) { localFolder.mkdir();//w w w.ja v a 2 s .c o m } this.working_dirppt = current_dir + OpenmeetingsVariables.UPLOAD_TEMP_DIR + File.separatorChar + "files" + File.separatorChar; // add Temp Folder Structure File localFolderppt = new File(working_dirppt); if (!localFolderppt.exists()) { localFolderppt.mkdir(); } log.debug("this.workingDir: " + this.workingDir); }
From source file:ar.com.zauber.common.image.impl.FileImageFactory.java
/** @see ImageFactory#createImage(InputStream, String) */ public final synchronized Image createImage(final InputStream is, final String name) throws IOException { if (name.indexOf(File.separatorChar) != -1) { throw new IllegalArgumentException("name can't contain " + File.separator); }//from www.j a va 2s . co m // TODO: implementar con un createTmpDir... esto puede tener carreras // si alguien toca desde afuera el directorio //for( ;; i++) { // File base = new File(baseDir); // if(!new File(baseDir, "").exists()) { // break; // } //} final FileImage ret = new FileImage(baseDir.getAbsolutePath(), name + DEFAULT_FILE_EXTENSION); final File f = ret.getFile(); f.getParentFile().mkdir(); final OutputStream os = new FileOutputStream(f); IOUtil.copy(is, os); os.close(); FileImage.validateImage(ret.getInputStream()); // thumb final FileImage thumb = new FileImage(baseDir.getAbsolutePath(), "thumb_" + name + DEFAULT_FILE_EXTENSION); FileImage.createThumbnail(ret.getInputStream(), new FileOutputStream(thumb.getFile()), maxSize); ret.setThumb(thumb); return ret; }
From source file:com.linecorp.armeria.testing.server.webapp.WebAppContainerTest.java
/** * Returns the doc-base directory of the test web application. *///from ww w . j a va2s . co m public static File webAppRoot() { URL url = WebAppContainerTest.class.getProtectionDomain().getCodeSource().getLocation(); File f; try { f = new File(url.toURI()); } catch (URISyntaxException ignored) { f = new File(url.getPath()); } final File buildDir; if (f.isDirectory()) { // f is: testing/build/resources/main buildDir = f.getParentFile().getParentFile(); } else { // f is: testing/build/libs/armeria-testing-*.jar assert f.isFile(); buildDir = f.getParentFile().getParentFile(); } assert buildDir.getPath().endsWith("testing" + File.separatorChar + "build"); final File webAppRoot = new File(buildDir.getParentFile(), "src" + File.separatorChar + "main" + File.separatorChar + "webapp"); assert webAppRoot.isDirectory(); return webAppRoot; }
From source file:com.qualogy.qafe.bind.io.FileLocation.java
/** * this class takes the root argument if not empty * and adds it to this.path/*from w ww . j av a 2 s .c o m*/ * * protocol http is supported * * @param root * @return */ // CHECKSTYLE.OFF: CyclomaticComplexity public URI toURI() { if (this.uri == null) { String path = location; if (!StringUtils.isEmpty(root) && !root.endsWith("/") && !root.endsWith("\\"))//add File.separator @ end root += File.separator; path = ((root != null) ? root : "") + ((location != null) ? location : ""); if (File.separatorChar == '\\') { path = path.replace('\\', '/'); } if (path.startsWith(SCHEME_HTTP + COMMON_SCHEME_DELIM)) { try { URL url = new URL(path); this.uri = url.toURI(); } catch (MalformedURLException e) { throw new BindException(e); } catch (URISyntaxException e) { throw new BindException(e); } } if (path.startsWith(SCHEME_FILE)) { try { uri = new URI(path); } catch (URISyntaxException e) { throw new BindException(e); } } else { File file = StringUtils.isEmpty(root) ? new File(((location != null) ? location : "")) : new File(root, ((location != null) ? location : "")); if (file.exists()) { this.uri = file.toURI(); } } } return this.uri; }
From source file:com.iggroup.oss.restdoclet.plugin.io.DirectoryBuilder.java
/** * Initialises the directory containing the classes. */// ww w. j a v a 2s. c om private void initClassesDirectory(final String output) { classesDirectory = new File(targetDirectory, CLASSES_DIR + File.separatorChar + output); classesDirectory.mkdir(); }