List of usage examples for org.apache.commons.io FilenameUtils getName
public static String getName(String filename)
From source file:de.uzk.hki.da.format.CLIConversionStrategy.java
/** * Convert file.//from w w w. j a v a2s .c o m * * @param ci the ci * @return the list * @throws FileNotFoundException the file not found exception */ @Override public List<Event> convertFile(ConversionInstruction ci) throws FileNotFoundException { if (pkg == null) throw new IllegalStateException("Package not set"); Path.make(object.getDataPath(), object.getPath("newest").getLastElement(), ci.getTarget_folder()).toFile() .mkdirs(); String[] commandAsArray = assemble(ci, object.getPath("newest").getLastElement()); if (!cliConnector.execute(commandAsArray)) throw new RuntimeException("convert did not succeed"); String targetSuffix = ci.getConversion_routine().getTarget_suffix(); if (targetSuffix.equals("*")) targetSuffix = FilenameUtils.getExtension(ci.getSource_file().toRegularFile().getAbsolutePath()); DAFile result = new DAFile(pkg, object.getPath("newest").getLastElement(), ci.getTarget_folder() + "/" + FilenameUtils.removeExtension(Matcher.quoteReplacement( FilenameUtils.getName(ci.getSource_file().toRegularFile().getAbsolutePath()))) + "." + targetSuffix); Event e = new Event(); e.setType("CONVERT"); e.setDetail(Utilities.createString(commandAsArray)); e.setSource_file(ci.getSource_file()); e.setTarget_file(result); e.setDate(new Date()); List<Event> results = new ArrayList<Event>(); results.add(e); return results; }
From source file:io.cloudslang.lang.tools.build.SlangBuilder.java
public SlangBuildResults buildSlangContent(String projectPath, String contentPath, String testsPath, List<String> testSuits, boolean shouldValidateDescription, boolean shouldValidateCheckstyle, BulkRunMode bulkRunMode, SlangBuildMain.BuildMode buildMode, Set<String> changedFiles) { String projectName = FilenameUtils.getName(projectPath); loggingService.logEvent(Level.INFO, ""); loggingService.logEvent(Level.INFO, "------------------------------------------------------------"); loggingService.logEvent(Level.INFO, "Building project: " + projectName); loggingService.logEvent(Level.INFO, "------------------------------------------------------------"); loggingService.logEvent(Level.INFO, ""); loggingService.logEvent(Level.INFO, "--- compiling sources ---"); PreCompileResult preCompileResult = slangContentVerifier.createModelsAndValidate(contentPath, shouldValidateDescription, shouldValidateCheckstyle); Map<String, Executable> slangModels = preCompileResult.getResults(); List<RuntimeException> exceptions = new ArrayList<>(preCompileResult.getExceptions()); CompileResult compileResult = compileModels(slangModels); exceptions.addAll(compileResult.getExceptions()); IRunTestResults runTestsResults = new RunTestsResults(); if (compileResult.getExceptions().size() == 0 && StringUtils.isNotBlank(testsPath) && new File(testsPath).isDirectory()) { runTestsResults = runTests(slangModels, projectPath, testsPath, testSuits, bulkRunMode, buildMode, changedFiles);//from ww w . ja v a 2 s . co m } exceptions.addAll(runTestsResults.getExceptions()); return new SlangBuildResults(compileResult.getResults().size(), runTestsResults, exceptions); }
From source file:com.hortonworks.amstore.view.StoreApplicationView.java
public String getPackageFilepath() { if (package_uri != null) { String targetPath = "/var/lib/ambari-server/resources/views"; String filename = FilenameUtils.getName(package_uri); // Remove any leftover uri characters filename = filename.split("\\?")[0]; return targetPath + "/" + filename; } else/*from ww w .j a v a2 s .c o m*/ return null; }
From source file:de.thischwa.pmcms.model.tool.Upload.java
public Upload(final Site site, final IConnection transfer, String checkumsFileBasename) { siteExportDir = PoPathInfo.getSiteExportDirectory(site); this.transfer = transfer; serverHashes = new HashMap<String, String>(); serverDirs = new ArrayList<String>(); localDirs = new HashSet<String>(); // collect the exported files localHashesFile = new File(siteExportDir, FilenameUtils.getBaseName(checkumsFileBasename) + ".zip"); localHashes = ChecksumTool.getFromZip(localHashesFile, checkumsFileBasename); for (String path : localHashes.keySet()) { // collect the local dirs if (path.contains(UploadTree.PATH_SEPARATOR + "")) { String parent = path.substring(0, path.lastIndexOf(UploadTree.PATH_SEPARATOR)); localDirs.add(parent);//from w ww.j a v a 2s . com } } // download and read the server hashes try { File serverHashFile = File.createTempFile("checksums", ".zip", Constants.TEMP_DIR); if (transfer.download(FilenameUtils.getName(localHashesFile.getName()), new BufferedOutputStream(new FileOutputStream(serverHashFile)))) { serverHashes = ChecksumTool.getFromZip(serverHashFile, checkumsFileBasename); } } catch (Exception e) { logger.warn("Error while getting the server hashes: " + e.getMessage(), e); } // collect the server dirs for (String path : serverHashes.keySet()) { if (path.contains(UploadTree.PATH_SEPARATOR + "")) { String parent = path.substring(0, path.lastIndexOf(UploadTree.PATH_SEPARATOR)); if (!serverDirs.contains(parent)) serverDirs.add(parent); } } }
From source file:es.eucm.mokap.backend.controller.insert.MokapInsertController.java
/** * Stores an uploaded file with a temporal file name. * /*from w w w . jav a 2s. com*/ * @param fis * Stream with the file * @return Name of the created temporal file * @throws IOException * if the file name is null, or if it has no zip extension */ private String storeUploadedTempFile(FileItemStream fis) throws IOException { String tempFileName; // Let's process the file String fileName = fis.getName(); if (fileName != null) { fileName = FilenameUtils.getName(fileName); } else { throw new IOException(ServerReturnMessages.INVALID_UPLOAD_FILENAMEISNULL); } if (!fileName.toLowerCase().endsWith(UploadZipStructure.ZIP_EXTENSION)) { throw new IOException(ServerReturnMessages.INVALID_UPLOAD_EXTENSION); } else { InputStream is = fis.openStream(); // Calculate fileName tempFileName = Utils.generateTempFileName(fileName); // Actually store the general temporal file st.storeFile(is, tempFileName); is.close(); } return tempFileName; }
From source file:com.mindquarry.desktop.client.dialog.conflict.ObstructedConflictDialog.java
@Override protected void createLowerDialogArea(Composite composite) { Composite subComposite = new Composite(composite, SWT.NONE); subComposite.setLayout(new GridLayout(2, false)); Button button1 = makeRadioButton(subComposite, I18N.getString("Rename file and upload it using a new name:"), //$NON-NLS-1$ ObstructedConflict.Action.RENAME); button1.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { newNameField.setEnabled(true); }//from w ww . ja va 2 s . c om }); newNameField = createNewNameField(subComposite, FilenameUtils.getName(conflict.getStatus().getPath())); newNameField.setFocus(); Button button2 = makeRadioButton(subComposite, I18N.getString("Remove obstructing file and download original from server"), //$NON-NLS-1$ ObstructedConflict.Action.REVERT); button2.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { newNameField.setEnabled(false); okButton.setEnabled(true); } }); }
From source file:com.dominion.salud.pedicom.web.controller.PDFController.java
/** * Genera un pdf de un pedido concreto//w w w. j a v a 2 s .c om * * @param pedidos Pedido del que se quiere generar el pdf * @return Ruta del pdf */ @ResponseBody @RequestMapping(value = "pdfPedidos", method = RequestMethod.POST, produces = "application/json") public ResponseEntity<String> pdfPedidos(@RequestBody(required = true) Pedidos pedidos) { logger.debug("Iniciando generacion del pdf"); Connection con = null; try { List<Pedidos> peds = new ArrayList<>(); peds.add(pedidos); con = routingDataSource.getConnection(); InputStream inputstream = pdfService.crearPDF(peds, con); // File dir = new File(System.getProperty("pedicom.home")); File dir = new File(PEDICOMConstantes._HOME); String nombre = Long.toString(new Date().getTime()); logger.debug(" Guardando pdf en : " + dir + "/reports/"); File tempFile = new File(dir + "/reports/", nombre + "tmp.pdf"); FileOutputStream out = new FileOutputStream(tempFile); IOUtils.copy(inputstream, out); logger.debug("Path completo :" + tempFile.getPath()); return new ResponseEntity(FilenameUtils.getName(tempFile.getPath()), HttpStatus.OK); } catch (IOException | SQLException | ClassNotFoundException | JRException ex) { logger.error(ex.getMessage()); } finally { try { if (con != null && !con.isClosed()) { con.close(); } } catch (SQLException ex) { logger.error("Error :" + ex.getMessage()); } } return new ResponseEntity("No_encontrado.pdf", HttpStatus.OK); }
From source file:bean.FileUploadBean.java
public String uploadResume() throws IOException, SQLException { UploadedFile uploadedPhoto = getResume(); //System.out.println("Name " + getName()); //System.out.println("tmp directory" System.getProperty("java.io.tmpdir")); //System.out.println("File Name " + uploadedPhoto.getFileName()); //System.out.println("Size " + uploadedPhoto.getSize()); this.filePath = "C:/Users/Usuario/Documents/fotos/"; objOutros.setUrl(this.filePath); byte[] bytes = null; if (null != uploadedPhoto) { bytes = uploadedPhoto.getContents(); String filename = FilenameUtils.getName(uploadedPhoto.getFileName()); BufferedOutputStream stream = new BufferedOutputStream( new FileOutputStream(new File(this.filePath + filename))); stream.write(bytes);/*from w w w . j a v a2s . co m*/ stream.close(); } return "success"; }
From source file:net.grinder.util.AbstractGrinderClassPathProcessor.java
/** * Construct the classpath of ngrinder which is very important and located in the head of * classpath.// www .j av a 2 s .c o m * * @param classPath classpath string * @param logger logger * @return classpath optimized for grinder. */ public String filterForeMostClassPath(String classPath, Logger logger) { List<String> classPathList = new ArrayList<String>(); for (String eachClassPath : checkNotNull(classPath).split(File.pathSeparator)) { String filename = FilenameUtils.getName(eachClassPath); if (isForemostJar(filename) || isUsefulForForemostReferenceProject(eachClassPath)) { logger.trace("classpath :" + eachClassPath); classPathList.add(eachClassPath); } } return StringUtils.join(classPathList, File.pathSeparator); }
From source file:edu.jhu.pha.vospace.protocol.HttpGetProtocolHandler.java
@Override public void invoke(JobDescription job) throws IOException, JobException, URISyntaxException { String getFileUrl = job.getProtocols() .get(SettingsServlet.getConfig().getString("transfers.protocol.httpget")); MetaStore store = MetaStoreFactory.getMetaStore(job.getUsername()); HttpClient client = MyHttpConnectionPoolProvider.getHttpClient(); HttpGet get = new HttpGet(getFileUrl); InputStream fileInp = null;// ww w. ja v a 2 s.c om try { HttpResponse response = client.execute(get); if (response.getStatusLine().getStatusCode() == 200) { fileInp = response.getEntity().getContent(); logger.debug("Auto node: " + job.getTargetId().toString().endsWith("/.auto")); //TODO make also for container String fileName = FilenameUtils.getName(getFileUrl); Header dispositionHeader = response.getFirstHeader("content-disposition"); if (null != dispositionHeader && dispositionHeader.getValue().indexOf("filename") > 0) { Matcher matcher = fileNamePattern.matcher(dispositionHeader.getValue()); if (matcher.find()) { fileName = matcher.group(1); } } if (job.getTargetId().toString().endsWith("/.auto") && null != fileName) { logger.debug("Auto node success " + fileName); VospaceId newId = new VospaceId(job.getTargetId().toString().replaceFirst(".auto", fileName)); DataNode targetNode = (DataNode) NodeFactory.createNode(newId, job.getUsername(), NodeType.DATA_NODE); targetNode.setNode(null); targetNode.setData(fileInp); } else { DataNode targetNode; if (!store.isStored(job.getTargetId())) { targetNode = NodeFactory.createNode(job.getTargetId(), job.getUsername(), NodeType.DATA_NODE); targetNode.setNode(null); } else { targetNode = (DataNode) NodeFactory.getNode(job.getTargetId(), job.getUsername()); } targetNode.setData(fileInp); } } else { logger.error("Error processing job " + job.getId() + ": " + response.getStatusLine().getStatusCode() + " " + response.getStatusLine().getReasonPhrase()); throw new JobException( "Error processing job " + job.getId() + ": " + response.getStatusLine().getStatusCode() + " " + response.getStatusLine().getReasonPhrase()); } } catch (IOException ex) { ex.printStackTrace(); get.abort(); throw ex; } finally { try { if (null != fileInp) fileInp.close(); } catch (IOException e) { } } }