List of usage examples for org.apache.commons.io FilenameUtils concat
public static String concat(String basePath, String fullFilenameToAdd)
From source file:com.citrix.cpbm.portal.fragment.controllers.AbstractTenantController.java
@Override protected String writeMultiPartFileToLocalFile(String imageFolder, String relativeImageDir, MultipartFile multipartFile) throws IOException { File file = new File(FilenameUtils.concat(imageFolder, relativeImageDir)); if (!file.exists()) { file.mkdir();//from ww w .j a v a 2s .c o m } String fileRelativePath = FilenameUtils.concat(relativeImageDir, FilenameUtils.getName(multipartFile.getOriginalFilename())); String logoFilelocalPath = FilenameUtils.concat(imageFolder, fileRelativePath); FileOutputStream outputStream = new FileOutputStream(logoFilelocalPath); InputStream inputStream = multipartFile.getInputStream(); byte buf[] = new byte[1024]; int len; while ((len = inputStream.read(buf)) > 0) { outputStream.write(buf, 0, len); } outputStream.close(); inputStream.close(); return fileRelativePath; }
From source file:com.moviejukebox.MovieJukebox.java
/** * Update the movie poster for the specified movie. * <p>/* w w w . j av a 2 s . c o m*/ * When an existing thumbnail is found for the movie, it is not overwritten, unless the mjb.forceThumbnailOverwrite is set to * true in the property file. * <p> * When the specified movie does not contain a valid URL for the poster, a dummy image is used instead. * * @param jukebox * @param movie */ public void updateMoviePoster(Jukebox jukebox, Movie movie) { String posterFilename = movie.getPosterFilename(); String skinHome = SkinProperties.getSkinHome(); File dummyFile = FileUtils.getFile(skinHome, LIT_RESOURCES, DUMMY_JPG); File posterFile = new File(FilenameUtils.concat(jukebox.getJukeboxRootLocationDetails(), posterFilename)); File tmpDestFile = new File(FilenameUtils.concat(jukebox.getJukeboxTempLocationDetails(), posterFilename)); FileTools.makeDirsForFile(posterFile); FileTools.makeDirsForFile(tmpDestFile); // Check to see if there is a local poster. // Check to see if there are posters in the jukebox directories (target and temp) // Check to see if the local poster is newer than either of the jukebox posters // Download poster // Do not overwrite existing posters, unless there is a new poster URL in the nfo file. if ((!tmpDestFile.exists() && !posterFile.exists()) || movie.isDirty(DirtyFlag.POSTER) || forcePosterOverwrite) { FileTools.makeDirsForFile(posterFile); if (!isValidString(movie.getPosterURL())) { LOG.debug("Dummy image used for {}", movie.getBaseName()); FileTools.copyFile(dummyFile, tmpDestFile); } else { try { // Issue 201 : we now download to local temp dir LOG.debug("Downloading poster for {} to '{}'", movie.getBaseName(), tmpDestFile.getName()); FileTools.downloadImage(tmpDestFile, movie.getPosterURL()); LOG.debug("Downloaded poster for {}", movie.getBaseName()); } catch (IOException error) { LOG.debug("Failed downloading movie poster: {} - Error: {}", movie.getPosterURL(), error.getMessage()); FileTools.copyFile(dummyFile, tmpDestFile); } } } }
From source file:com.xyphos.vmtgen.GUI.java
private void lstFilesValueChanged(javax.swing.event.ListSelectionEvent evt) {// GEN-FIRST:event_lstFilesValueChanged if (!evt.getValueIsAdjusting() && (-1 != lstFiles.getSelectedIndex())) { String file = lstFiles.getSelectedValue().toString(); // set keywords based on file name setKeywords(FilenameUtils.getBaseName(file).replace("_", ",").replace("-", ",")); String path = FilenameUtils .separatorsToUnix(FilenameUtils.concat(basePath, FilenameUtils.getBaseName(file))) .replaceFirst("/", ""); setBaseTexture1(path);//w w w .j ava 2s. c o m // read the vtf header file = FilenameUtils.concat(workPath, file); File fileVTF = new File(file); try (LittleEndianDataInputStream in = new LittleEndianDataInputStream(new FileInputStream(fileVTF))) { int sig = in.readInt(); if (SIGNATURE_VTF != sig) { throw new IOException("Not a VTF file"); } if (0x10 != in.skipBytes(0x10)) { throw new IOException("skip failure"); } int flags = in.readInt(); frameCount = in.readShort(); in.close(); // don't need any more information chkFlagNoLOD.setSelected(0 != (0x200 & flags)); chkFlagTranslucent.setSelected(0 != (0x3000 & flags)); if (animated = (1 < frameCount)) { setFrameRate(frameCount); ((SpinnerNumberModel) nudEnvMapFrame.getModel()).setMaximum(frameCount); } nudFrameRate.setEnabled(animated & !chkLockFrameRate.isSelected()); nudEnvMapFrame.setEnabled(animated & !chkLockEnvMapFrame.isSelected()); chkLockFrameRate.setEnabled(animated); chkLockEnvMapFrame.setEnabled(animated); } catch (FileNotFoundException ex) { logger.log(Level.SEVERE, null, ex); } catch (IOException ex) { logger.log(Level.SEVERE, null, ex); } } }
From source file:com.xyphos.vmtgen.GUI.java
private String selectVTF() { JFileChooser fc = new JFileChooser(txtWorkFolder.getText()); fc.setAcceptAllFileFilterUsed(false); fc.setFileFilter(new FileFilterVTF()); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); int result = fc.showOpenDialog(this); if (JFileChooser.APPROVE_OPTION == result) { String file = fc.getSelectedFile().getName(); return FilenameUtils.separatorsToUnix(FilenameUtils.concat(basePath, FilenameUtils.getBaseName(file))) .replaceFirst("/", ""); }//w ww . j a v a2 s . c o m return null; }
From source file:fragment.web.AbstractProductsControllerTest.java
@Test public void testEditProductsLogo() throws Exception { Product product = productService.locateProduct("1", false); Assert.assertNull(product.getImagePath()); ProductLogoForm form = new ProductLogoForm(product); MultipartFile logo = new MockMultipartFile("Product.jpeg", "Product.jpeg", "bytes", "ProductLogo".getBytes()); form.setLogo(logo);// w w w. j ava2 s .c o m BindingResult result = validate(form); Assert.assertNotNull(result); File currentDirectory = new File(new File(".").getAbsolutePath()); String currentDirectoryPath = ""; Configuration rootdir = configurationService .locateConfigurationByName(Names.com_citrix_cpbm_portal_settings_images_uploadPath); try { currentDirectoryPath = currentDirectory.getCanonicalPath(); } catch (IOException e1) { e1.printStackTrace(); Assert.fail(); } rootdir.setValue(currentDirectoryPath); configurationService.update(rootdir); Assert.assertNull(product.getImagePath()); productsController.editProductLogo(form, result, request, map); product = productService.locateProduct("1", false); Assert.assertNotNull(product.getImagePath()); String productsAbsoluteDir = FilenameUtils.concat(currentDirectoryPath, "products"); Assert.assertEquals(product.getImagePath().replace("/", "\\"), "products\\1\\Product.jpeg"); File dir = new File(productsAbsoluteDir); try { org.apache.commons.io.FileUtils.deleteDirectory(dir); } catch (IOException e) { e.printStackTrace(); } }
From source file:net.vershinin.flashmind.FlashExportWizard.java
@Override protected void doExport(IProgressMonitor monitor, Display display, Shell parentShell) throws InvocationTargetException, InterruptedException { IMindMap mindMap = getSourceMindMap(); String targetPath = getTargetPath(); path = FilenameUtils.getFullPath(targetPath); baseName = FilenameUtils.getBaseName(targetPath); resourcesDirectory = baseName + RESOURCES_POSTFIX; resourcesPath = FilenameUtils.concat(path, resourcesDirectory); htmlFilename = FilenameUtils.getName(targetPath); mindmapFilename = FilenameUtils.getBaseName(htmlFilename) + MINDMAP_EXT; File path = new File(resourcesPath); path.mkdirs();//from w w w .j av a2s.com saveHtml(mindMap); saveJavaScrpit(); saveSwf(); saveFreemind(monitor, display, parentShell, mindMap); }
From source file:net.vershinin.flashmind.FlashExportWizard.java
protected void saveFreemind(IProgressMonitor monitor, Display display, Shell parentShell, IMindMap mindMap) throws InvocationTargetException, InterruptedException { String mindmapPath = FilenameUtils.concat(resourcesPath, mindmapFilename); FreeMindExporter exporter = new FreeMindExporter(mindMap.getSheet(), mindmapPath); monitor.beginTask(null, 100);//from w ww . j a v a 2 s . c o m exporter.setMonitor(new SubProgressMonitor(monitor, 99)); exporter.build(); launchTargetFile(true, monitor, display, parentShell); }
From source file:net.vershinin.flashmind.FlashExportWizard.java
protected void saveJavaScrpit() { try {//from w ww . j a v a 2 s .co m InputStream in = getBundle().getEntry(RESOURCE_JAVA_SCRIPT).openStream(); String jsPath = FilenameUtils.concat(resourcesPath, JS_FILE_NAME); FileOutputStream out = new FileOutputStream(jsPath); IOUtils.copy(in, out); } catch (IOException e) { handleExportException(e); } }
From source file:net.vershinin.flashmind.FlashExportWizard.java
protected void saveSwf() { try {//from w w w . j a v a2 s . co m InputStream in = getBundle().getEntry(RESOURCE_SWF_FILE).openStream(); String swfPath = FilenameUtils.concat(resourcesPath, SWF_FILE_NAME); FileOutputStream out = new FileOutputStream(swfPath); IOUtils.copy(in, out); } catch (IOException e) { handleExportException(e); } }
From source file:net.vershinin.flashmind.FlashExportWizard.java
protected void saveHtml(IMindMap mindMap) { VelocityEngine engine = initVelocityEngine(); Template template = engine.getTemplate(TEMPLATE_NAME); VelocityContext context = new VelocityContext(); context.put(KEY_TITLE, mindMap.getCentralTopic().getTitleText()); context.put(KEY_JS_FILE, FilenameUtils.concat(resourcesDirectory, JS_FILE_NAME)); String mindmapFile = FilenameUtils.concat(resourcesDirectory, mindmapFilename); context.put(KEY_MINDMAP_FILE, FilenameUtils.separatorsToUnix(mindmapFile)); String swfFilename = FilenameUtils.concat(resourcesDirectory, SWF_FILE_NAME); context.put(KEY_SWF_FILE, FilenameUtils.separatorsToUnix(swfFilename)); StringWriter writer = new StringWriter(); template.merge(context, writer);//from w ww . jav a 2 s . co m try { FileWriter fw = new FileWriter(getTargetPath()); fw.write(writer.toString()); fw.close(); } catch (IOException e) { handleExportException(e); } }