List of usage examples for org.apache.commons.io FilenameUtils removeExtension
public static String removeExtension(String filename)
From source file:jenkins.plugins.livingdoc.XmlReportReader.java
private String getFilenameWithoutExtension(FilePath file) { return FilenameUtils.removeExtension(file.getName()); }
From source file:eu.edisonproject.classification.prepare.controller.DataPrepare.java
@Override public void execute() { File file = new File(inputFolder); Document davro;/*from www . j a va 2 s. c o m*/ DocumentAvroSerializer dAvroSerializer = null; if (file.isDirectory()) { File[] filesInDir = file.listFiles(); // Arrays.sort(filesInDir); // LocalDate date = getCreationDate(file); for (File f : filesInDir) { if (f.isFile() && FilenameUtils.getExtension(f.getName()).endsWith("txt")) { LocalDate date = getCreationDate(f); documentObject = new DocumentObject(); documentObject.setDate(date); ReaderFile rf = new ReaderFile(f.getAbsolutePath()); String contents = rf.readFile(); cleanStopWord.setDescription(contents); String cleanCont = cleanStopWord.execute().toLowerCase(); cleanLemmatisation.setDescription(cleanCont); cleanCont = cleanLemmatisation.execute(); documentObject.setDescription(cleanCont); documentObject.setDocumentId(FilenameUtils.removeExtension(f.getName())); documentObject.setTitle(f.getParentFile().getName()); // extract(this.getDocumentObject(), f.getPath()); // documentObject.setDescription(documentObject.getDescription().toLowerCase()); // clean(this.getDocumentObject().getDescription()); if (documentObject.getDescription().equals("")) { continue; } documentObjectList.add(this.getDocumentObject()); davro = new Document(); davro.setDocumentId(documentObject.getDocumentId()); davro.setTitle(documentObject.getTitle()); davro.setDate(documentObject.getDate().toString()); davro.setDescription(documentObject.getDescription()); if (dAvroSerializer == null) { dAvroSerializer = new DocumentAvroSerializer(outputFolder + File.separator + documentObject.getTitle().replaceAll(" ", "_") + date + ".avro", davro.getSchema()); } Logger.getLogger(Text2Avro.class.getName()).log(Level.INFO, "Adding :{0} to: {1}{2}{3}{4}.avro", new Object[] { documentObject.getDocumentId(), outputFolder, File.separator, documentObject.getTitle().replaceAll(" ", "_"), date }); dAvroSerializer.serialize(davro); } } if (dAvroSerializer != null) { dAvroSerializer.close(); dAvroSerializer = null; } } }
From source file:com.rubinefocus.admin.servlet.UploadAdminImage.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//from w w w .j av a2s . com * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { File f = new File(this.getServletContext().getRealPath("admin/assets/images/adminPic")); String savePath = f.getPath(); savePath = savePath.replace("%20", " "); savePath = savePath.replace("build", ""); String fileName = ""; boolean isMultipart = ServletFileUpload.isMultipartContent(request); // process only if its multipart content if (isMultipart) { // Create a factory for disk-based file items FileItemFactory factory = new DiskFileItemFactory(); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); try { // Parse the request List<FileItem> multiparts = upload.parseRequest(request); for (FileItem item : multiparts) { if (!item.isFormField()) { fileName = new File(item.getName()).getName(); File file = new File(savePath + "/" + fileName); if (file.exists()) { String fileNameWithOutExt = FilenameUtils.removeExtension(fileName); String ext = FilenameUtils.getExtension(fileName); fileName = fileNameWithOutExt + new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date()) + "." + ext; fileName = fileName.replace(" ", ""); fileName = fileName.replace("-", ""); fileName = fileName.replace(":", ""); item.write(new File(savePath + File.separator + fileName)); } else { item.write(new File(savePath + File.separator + fileName)); } Gson gson = new Gson(); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(gson.toJson(fileName)); } } } catch (Exception e) { e.printStackTrace(); } } }
From source file:it.geosolutions.imageio.plugins.nitronitf.ImageIOUtils.java
public static String getPackageName(Class clazz) { // we can cheat and use the FilenameUtils to remove the class name return FilenameUtils.removeExtension(clazz.getCanonicalName()); }
From source file:com.collaide.fileuploader.requests.repository.RepositoryRequest.java
/** * download a file or a folder from the server to the disk a folder is * downloaded as a zip and the unzipped<br/> * * @param url the URL of the repo item to download * @param folderToSave the folderin which to save the downloaded item * @return The path of the saved file or folder * @throws IOException//w w w .j a v a2 s . co m */ public String download(String url, String folderToSave) throws IOException { ClientResponse response = Client.create().resource(url + "?" + CurrentUser.getAuthParams()) .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); if (response.getStatus() != 200) { return null; } File downloadedFile = response.getEntity(File.class); File fileToSave = new File(folderToSave, getFileName(response)); downloadedFile.renameTo(fileToSave); FileWriter fr = new FileWriter(downloadedFile); fr.flush(); String itemName = fileToSave.getAbsolutePath(); if (isAZip(response)) { unzip(fileToSave, new File(folderToSave)); fileToSave.delete(); itemName = FilenameUtils.removeExtension(itemName); } downloadedFile.getAbsolutePath(); return itemName; }
From source file:com.freedomotic.plugins.TrackingReadFile.java
/** * Reads coordinates from file.//from w ww . j a va 2s .c o m * * @param f file of coordinates */ private void readMoteFileCoordinates(File f) { FileReader fr = null; ArrayList<Coordinate> coord = new ArrayList<Coordinate>(); String userId = FilenameUtils.removeExtension(f.getName()); try { LOG.info("Reading coordinates from file {}", f.getAbsolutePath()); fr = new FileReader(f); BufferedReader br = new BufferedReader(fr); String line; while ((line = br.readLine()) != null) { //tokenize string StringTokenizer st = new StringTokenizer(line, ","); LOG.info("Mote {} coordinate added {}", userId, line); Coordinate c = new Coordinate(); c.setUserId(userId); c.setX(new Integer(st.nextToken())); c.setY(new Integer(st.nextToken())); c.setTime(new Integer(st.nextToken())); coord.add(c); } fr.close(); WorkerThread wt = new WorkerThread(this, coord, ITERATIONS); workers.add(wt); } catch (FileNotFoundException ex) { LOG.error("Coordinates file not found for mote " + userId); } catch (IOException ex) { LOG.error("IOException: ", ex); } finally { try { fr.close(); } catch (IOException ex) { LOG.error("IOException: ", ex); } } }
From source file:com.rubinefocus.admin.servlet.UploadProductImage.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/*from w w w . jav a 2 s. c om*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { File f = new File(this.getServletContext().getRealPath("admin/assets/images/products")); String savePath = f.getPath(); savePath = savePath.replace("%20", " "); savePath = savePath.replace("build", ""); String fileName = ""; boolean isMultipart = ServletFileUpload.isMultipartContent(request); // process only if its multipart content if (isMultipart) { // Create a factory for disk-based file items FileItemFactory factory = new DiskFileItemFactory(); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); try { // Parse the request List<FileItem> multiparts = upload.parseRequest(request); for (FileItem item : multiparts) { if (!item.isFormField()) { fileName = new File(item.getName()).getName(); File file = new File(savePath + "/" + fileName); if (file.exists()) { String fileNameWithOutExt = FilenameUtils.removeExtension(fileName); String ext = FilenameUtils.getExtension(fileName); fileName = fileNameWithOutExt + new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date()) + "." + ext; fileName = fileName.replace(" ", ""); fileName = fileName.replace("-", ""); fileName = fileName.replace(":", ""); item.write(new File(savePath + File.separator + fileName)); } else { item.write(new File(savePath + File.separator + fileName)); } Gson gson = new Gson(); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(gson.toJson(fileName)); } } } catch (Exception e) { e.printStackTrace(); } } }
From source file:com.fluidops.iwb.api.solution.ZipFileBasedSolutionService.java
private String filePrefixFor(URL solutionArtifact) { return FilenameUtils.removeExtension(new File(solutionArtifact.getPath()).getName()); }
From source file:MSUmpire.SpectrumParser.SpectrumParserBase.java
protected void FSElutionIndexWrite() throws IOException { try {// w ww . jav a 2 s. c o m Logger.getRootLogger() .debug("Writing RTidx to file:" + FilenameUtils.removeExtension(filename) + ".RTidxFS.."); FileOutputStream fout = new FileOutputStream(FilenameUtils.removeExtension(filename) + ".RTidxFS", false); FSTObjectOutput oos = new FSTObjectOutput(fout); oos.writeObject(ElutionTimeToScanNoMap); oos.close(); fout.close(); } catch (Exception ex) { Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex)); } try { Logger.getRootLogger() .debug("Writing Scanidx to file:" + FilenameUtils.removeExtension(filename) + ".ScanidxFS.."); FileOutputStream fout = new FileOutputStream(FilenameUtils.removeExtension(filename) + ".ScanidxFS", false); FSTObjectOutput oos = new FSTObjectOutput(fout); oos.writeObject(MsLevelList); oos.close(); fout.close(); } catch (Exception ex) { Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex)); } try { Logger.getRootLogger() .debug("Writing ScanRT to file:" + FilenameUtils.removeExtension(filename) + ".ScanRTFS.."); FileOutputStream fout = new FileOutputStream(FilenameUtils.removeExtension(filename) + ".ScanRTFS", false); FSTObjectOutput oos = new FSTObjectOutput(fout); oos.writeObject(ScanToElutionTime); oos.close(); fout.close(); } catch (Exception ex) { Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex)); } if (datatype != SpectralDataType.DataType.DDA) { try { Logger.getRootLogger().debug("Writing DIAWindows to file:" + FilenameUtils.removeExtension(filename) + ".DIAWindowsFS.."); FileOutputStream fout = new FileOutputStream( FilenameUtils.removeExtension(filename) + ".DIAWindowsFS", false); FSTObjectOutput oos = new FSTObjectOutput(fout); oos.writeObject(dIA_Setting.DIAWindows); oos.close(); fout.close(); } catch (Exception ex) { Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex)); } } if (datatype == SpectralDataType.DataType.WiSIM) { try { Logger.getRootLogger().debug("Writing MS1 windows to file:" + FilenameUtils.removeExtension(filename) + ".MS1WindowsFS.."); FileOutputStream fout = new FileOutputStream( FilenameUtils.removeExtension(filename) + ".MS1WindowsFS", false); FSTObjectOutput oos = new FSTObjectOutput(fout); oos.writeObject(dIA_Setting.MS1Windows); oos.close(); fout.close(); } catch (Exception ex) { Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex)); } } }
From source file:de.tudarmstadt.ukp.dkpro.core.api.io.JCasFileWriter_ImplBase.java
/** * Get the relative path from the CAS. If the CAS does not contain relative path information or * if {@link #PARAM_USE_DOCUMENT_ID} is set, the document ID is used. * * @param aJCas a CAS./*from www . ja v a 2s .com*/ * @return the relative target path. */ protected String getRelativePath(JCas aJCas) { DocumentMetaData meta = DocumentMetaData.get(aJCas); String baseUri = meta.getDocumentBaseUri(); String docUri = meta.getDocumentUri(); if (!useDocumentId && (baseUri != null)) { String relativeDocumentPath; if ((docUri == null) || !docUri.startsWith(baseUri)) { throw new IllegalStateException( "Base URI [" + baseUri + "] is not a prefix of document URI [" + docUri + "]"); } relativeDocumentPath = docUri.substring(baseUri.length()); if (stripExtension) { relativeDocumentPath = FilenameUtils.removeExtension(relativeDocumentPath); } return relativeDocumentPath; } else { String relativeDocumentPath; if (meta.getDocumentId() == null) { throw new IllegalStateException("Neither base URI/document URI nor document ID set"); } relativeDocumentPath = meta.getDocumentId(); if (escapeDocumentId) { try { relativeDocumentPath = URLEncoder.encode(relativeDocumentPath, "UTF-8"); } catch (UnsupportedEncodingException e) { // UTF-8 must be supported on all Java platforms per specification. This should // not happen. throw new IllegalStateException(e); } } return relativeDocumentPath; } }