List of usage examples for org.apache.commons.io FilenameUtils getExtension
public static String getExtension(String filename)
From source file:ch.cyberduck.core.AbstractPath.java
/** * @return the extension if any or null otherwise */ public String getExtension() { return FilenameUtils.getExtension(this.getName()); }
From source file:com.yattatech.util.SeminaryUtil.java
public static String copyImageFileToSeminaryFolder(String imagePath) { if (!IMAGE_COPY) { return imagePath; }/*from ww w . j av a2 s. c om*/ if (isInImageFolder(imagePath)) { return imagePath; } final File file = new File(imagePath); if (file.exists()) { final String ext = FilenameUtils.getExtension(imagePath); final String path = getSeminaryImagePath() + java.util.UUID.randomUUID().toString() + '.' + ext; InputStream in = null; OutputStream out = null; try { in = new FileInputStream(imagePath); out = new FileOutputStream(path); IOUtils.copy(in, out); return path; } catch (IOException ioe) { LOGGER.log(Level.SEVERE, ioe.getMessage()); } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } } return null; }
From source file:com.qwazr.extractor.ParserTest.java
protected Path getTempFile(String fileName) throws IOException { Path tempFile = Files.createTempFile("oss_extractor", "." + FilenameUtils.getExtension(fileName)); try (final OutputStream out = Files.newOutputStream(tempFile); final BufferedOutputStream bOut = new BufferedOutputStream(out);) { InputStream inputStream = getStream(fileName); IOUtils.copy(inputStream, bOut); }// w w w .j a v a 2s . c o m return tempFile; }
From source file:ch.elexis.base.ch.ebanking.esr.ESRFile.java
/** * ein ESR-File einlesen// ww w.j av a 2 s .c om * * @param filename * vollstndiger Pfadname der Datei * @return true wenn die Datei erfolgreich gelesen werden konnte */ public Result<List<ESRRecord>> read(File file, final IProgressMonitor monitor) { if (!file.exists()) { return new Result<List<ESRRecord>>(Result.SEVERITY.ERROR, 1, Messages.ESRFile_esrfile_not_founde, null, true); } if (!file.canRead()) { return new Result<List<ESRRecord>>(Result.SEVERITY.ERROR, 2, Messages.ESRFile_cannot_read_esr, null, true); } byte[] md5 = FileTool.checksum(file); name = file.getName(); if (md5 != null) { hash = StringTool.enPrintableStrict(md5); } else { hash = name; } Query<ESRRecord> qesr = new Query<ESRRecord>(ESRRecord.class); qesr.add("File", "=", hash); //$NON-NLS-1$ //$NON-NLS-2$ List<ESRRecord> list = qesr.execute(); if (list.size() > 0) { return new Result<List<ESRRecord>>(Result.SEVERITY.ERROR, 4, Messages.ESRFile_file_already_read, null, true); } String fileName = file.getName(); if ("xml".equalsIgnoreCase(FilenameUtils.getExtension(fileName))) { try (InputStream inputStream = new FileInputStream(file)) { Camt054Parser camt054Parser = new Camt054Parser(); List<Camt054Record> inputs = camt054Parser.parseRecords(inputStream); for (Camt054Record camt054Record : inputs) { ESRRecord esr = new ESRRecord(hash, camt054Record); list.add(esr); monitor.worked(1); } return new Result<List<ESRRecord>>(Result.SEVERITY.OK, 0, "OK", list, false); //$NON-NLS-1$ } catch (Exception ex) { ExHandler.handle(ex); return new Result<List<ESRRecord>>(Result.SEVERITY.ERROR, 3, Messages.ESRFile_ExceptionParsing, list, true); } } else { try (InputStreamReader ir = new InputStreamReader(new FileInputStream(file)); BufferedReader br = new BufferedReader(ir)) { String in; // String date=new TimeTool().toString(TimeTool.DATE_COMPACT); LinkedList<String> records = new LinkedList<String>(); while ((in = br.readLine()) != null) { for (int i = 0; i < in.length(); i += 128) { int eidx = i + 125; if (eidx >= in.length()) { eidx = in.length() - 1; } records.add(in.substring(i, eidx)); } } for (String s : records) { ESRRecord esr = new ESRRecord(hash, s); list.add(esr); monitor.worked(1); } return new Result<List<ESRRecord>>(Result.SEVERITY.OK, 0, "OK", list, false); //$NON-NLS-1$ } catch (Exception ex) { ExHandler.handle(ex); return new Result<List<ESRRecord>>(Result.SEVERITY.ERROR, 3, Messages.ESRFile_ExceptionParsing, list, true); } } }
From source file:com.kamike.misc.FsNameUtils.java
public static String getNameInZip(String prefix, String disk, String name, String fid, String uid, Date date) { String extension = FilenameUtils.getExtension(name); //?/*from w w w . java2 s . c o m*/ return getNameInZip(prefix, disk, getShortDate(date), name, fid, uid, extension); }
From source file:com.siberhus.tdfl.excel.DefaultExcelWorkbookFactory.java
private String getFileExtension(Resource resource) { String ext = FilenameUtils.getExtension(resource.getFilename()); ext = ext.toUpperCase(); return ext; }
From source file:com.splunk.shuttl.archiver.importexport.BucketExporterIntegrationTest.java
private void exportingBucketWithRealDataToCsvCreatesCsvBucket() { Bucket realBucket = TUtilsBucket.createRealBucket(); Bucket csvBucket = bucketExporter.exportBucket(realBucket, BucketFormat.CSV); assertEquals(realBucket.getName(), csvBucket.getName()); assertEquals(BucketFormat.CSV, csvBucket.getFormat()); assertEquals(1, csvBucket.getDirectory().listFiles().length); File csvFile = csvBucket.getDirectory().listFiles()[0]; assertEquals("csv", FilenameUtils.getExtension(csvFile.getName())); long csvFileSize = csvFile.length(); assertTrue(0 < csvFileSize);/* w w w. j ava2 s. c o m*/ }
From source file:edu.ku.brc.helpers.ImageFilter.java
/** * Returns true if the file type is ok.//from ww w . j a v a 2 s.c o m * @param filename the name of the file * @return true is ok, false is not */ public boolean isImageFile(final String filename) { String extension = FilenameUtils.getExtension(filename); if (extension != null) { return hash.get(extension.toLowerCase()) != null; } return false; }
From source file:com.eufar.asmm.server.UploadImage.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("UploadImage - the function started"); DiskFileItemFactory factory = new DiskFileItemFactory(); factory.setSizeThreshold(MAX_MEMORY_SIZE); String uploadFolder = getServletContext().getRealPath("") + DATA_DIRECTORY; ServletFileUpload upload = new ServletFileUpload(factory); upload.setSizeMax(MAX_REQUEST_SIZE); double maxSize = (MAX_REQUEST_SIZE / 1024) / 1024; System.out.println("UploadImage - max image size: " + maxSize + " Mbytes"); try {//w w w .j a va 2 s .c o m @SuppressWarnings("rawtypes") List items = upload.parseRequest(request); @SuppressWarnings("rawtypes") Iterator iter = items.iterator(); while (iter.hasNext()) { Object obj = iter.next(); org.apache.commons.fileupload.FileItem item = (org.apache.commons.fileupload.FileItem) obj; String fileExt = FilenameUtils.getExtension(item.getName()); if (fileExt.matches("(jpg|jpeg|bmp|png|JPG|JPEG|BMP|PNG)")) { System.out.println("UploadImage - image accepted"); if (!item.isFormField()) { File uploadedFile = File.createTempFile("tmp_", "." + fileExt, new File(uploadFolder)); item.write(uploadedFile); double fileSize = item.getSize(); fileSize = (fileSize / 1024) / 1024; response.setCharacterEncoding("UTF-8"); response.setContentType("text/html"); response.getWriter().write(uploadedFile.getName()); System.out.println("UploadImage - " + uploadedFile.getPath() + ": upload ok..."); System.out.println("UploadImage - " + uploadedFile.getPath() + ": " + fileSize + " MBytes"); if (new File(uploadedFile.getPath()).isFile()) { System.out.println("PrintFunction - picture (webapps): the file exists."); } else { System.out.println("PrintFunction - picture (webapps): the file doesn't exist."); } if (new File(uploadedFile.getPath()).isFile()) { System.out.println("PrintFunction - picture (webapps): the file can be read."); } else { System.out.println("PrintFunction - picture (webapps): the file can't be read."); } } else { System.out.println("UploadImage - a problem occured with the file format"); } } else { System.out.println("UploadImage - image rejected: wrong format"); response.setCharacterEncoding("UTF-8"); response.setContentType("text/html"); response.getWriter().write("format"); } } } catch (Exception ex) { System.out.println("UploadImage - a problem occured: " + ex); response.getWriter().write("ERROR:" + ex.getMessage()); } }
From source file:com.siberhus.web.ckeditor.utils.MimeUtils.java
public static String getDefaultMimeType(String fileName) { String fileExt = FilenameUtils.getExtension(fileName); if (fileExt != null) { String mimeType = MIME_TYPES.get(fileExt.toLowerCase()); if (mimeType != null) { return mimeType; }/*from w w w . j av a2s.com*/ return "application/octet-stream"; } else { return "text/plain"; } }