List of usage examples for org.apache.commons.io FilenameUtils getExtension
public static String getExtension(String filename)
From source file:com.ramforth.webserver.http.templates.WebFileTemplate.java
private String getMimeTypeForFile() { String extension = FilenameUtils.getExtension(((File) getTemplate()).getName()); return getMimeTypeForExtension(extension); }
From source file:com.releasequeue.server.ReleaseQueueServer.java
@Override public HttpResponse uploadPackage(FilePath packagePath, String distribution, String component) throws MalformedURLException, IOException { String repoType = FilenameUtils.getExtension(packagePath.toString()); String uploadPath = String.format("%s/%s/repositories/%s/packages?distribution=%s&component=%s", this.basePath, this.userName, repoType, distribution, component); URL uploadPackageUrl = new URL(this.serverUrl, uploadPath); CloseableHttpClient httpClient = HttpClients.createDefault(); HttpPost uploadFile = new HttpPost(uploadPackageUrl.toString()); setAuthHeader(uploadFile);// w ww. ja va 2 s . c om MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.addBinaryBody("file", new File(packagePath.toString()), ContentType.APPLICATION_OCTET_STREAM, packagePath.getName()); HttpEntity multipart = builder.build(); uploadFile.setEntity(multipart); HttpResponse response = httpClient.execute(uploadFile); return response; }
From source file:ch.cyberduck.core.aquaticprime.DonationKeyFactory.java
@Override public List<License> open() throws AccessDeniedException { final List<License> keys = super.open(); if (keys.isEmpty()) { if (log.isInfoEnabled()) { log.info("No donation key found"); }//from w ww.ja v a 2 s. c o m // No key found. Look for receipt in sandboxed application container for (Local file : LocalFactory.get(PreferencesFactory.get().getProperty("application.support.path")) .list().filter(new Filter<Local>() { @Override public boolean accept(final Local file) { return "cyberduckreceipt".equals(FilenameUtils.getExtension(file.getName())); } @Override public Pattern toPattern() { return Pattern.compile(".*\\.cyberduckreceipt"); } })) { final ReceiptVerifier verifier = new ReceiptVerifier(file); if (verifier.verify(new DisabledLicenseVerifierCallback())) { keys.add(new Receipt(file, verifier.getGuid())); } } } if (keys.isEmpty()) { return Collections.singletonList(LicenseFactory.EMPTY_LICENSE); } return keys; }
From source file:com.liferay.sync.engine.util.MSOfficeFileUtil.java
public static boolean isTempRenamedFile(Path sourceFilePath, Path targetFilePath) { String extension = FilenameUtils.getExtension(sourceFilePath.toString()); if (extension.equals("pub")) { String fileName = String.valueOf(targetFilePath.getFileName()); if (fileName.startsWith("pub") && fileName.endsWith(".tmp")) { return true; }/* ww w .java 2 s . c om*/ } else if (hasExtension(extension, _excelExtensions) || hasExtension(extension, _powerpointExtensions)) { Matcher matcher = _tempRenamedFilePattern.matcher(String.valueOf(targetFilePath.getFileName())); if (matcher.matches()) { return true; } } else if (hasExtension(extension, _wordExtensions)) { String fileName = String.valueOf(targetFilePath.getFileName()); if (fileName.startsWith("~WR") && fileName.endsWith(".tmp")) { return true; } } return false; }
From source file:net.sourceforge.javydreamercsw.validation.manager.web.file.ImageDisplay.java
@Override public boolean supportFile(String name) { return validExtensions.contains(FilenameUtils.getExtension(name)); }
From source file:de.htwg_konstanz.ebus.wholesaler.demo.workclasses.Upload.java
/** * Receives the XML File and generates an InputStream. * * @param request HttpServletRequest/*from w w w . j a v a2s . c o m*/ * @return InputStream Stream of the uploaded file * @throws FileUploadException Exception Handling for File Upload * @throws IOException Exception Handling for IO Exceptions */ public InputStream upload(final HttpServletRequest request) throws FileUploadException, IOException { // Check Variable to check if it is a File Uploade boolean isMultipart = ServletFileUpload.isMultipartContent(request); if (isMultipart) { //Create a factory for disk-based file items DiskFileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); //Console Out Starting the Upload progress. System.out.println("\n - - - UPLOAD"); // List of all uploaded Files List files = upload.parseRequest(request); // Returns the uploaded File Iterator iter = files.iterator(); FileItem element = (FileItem) iter.next(); String fileName = element.getName(); String extension = FilenameUtils.getExtension(element.getName()); // check if file extension is xml, when not then it will be aborted if (!extension.equals("xml")) { return null; } System.out.println("Extension:" + extension); System.out.println("\nFilename: " + fileName); // Escaping Special Chars fileName = fileName.replace('/', '\\'); fileName = fileName.substring(fileName.lastIndexOf('\\') + 1); // Converts the File into an Input Strem InputStream is; is = element.getInputStream(); return is; } return null; }
From source file:com.googlecode.fascinator.common.MagicMimeTypeIdentifierWrapper.java
@Override public String identify(byte[] firstBytes, String fileName, URI uri) { String ext = FilenameUtils.getExtension(fileName); String mimeType = mimeTypes.getString(null, ext); if (mimeType != null) { return mimeType; }/*from w w w . j av a 2 s . c om*/ return identifier.identify(firstBytes, fileName, uri); }
From source file:com.sangupta.jerry.util.ZipUtils.java
/** * Read a given file from the ZIP file and store it in a temporary file. The * temporary file is set to be deleted on exit of application. * /* w ww.j av a2s . c o m*/ * @param zipFile * the zip file from which the file needs to be read * * @param fileName * the name of the file that needs to be extracted * * @return the {@link File} handle for the extracted file in the temp * directory * * @throws IllegalArgumentException * if the zipFile is <code>null</code> or the fileName is * <code>null</code> or empty. */ public static File readFileFromZip(File zipFile, String fileName) throws FileNotFoundException, IOException { if (zipFile == null) { throw new IllegalArgumentException("zip file to extract from cannot be null"); } if (AssertUtils.isEmpty(fileName)) { throw new IllegalArgumentException("the filename to extract cannot be null/empty"); } LOGGER.debug("Reading {} from {}", fileName, zipFile.getAbsolutePath()); ZipInputStream stream = null; BufferedOutputStream outStream = null; File tempFile = null; try { byte[] buf = new byte[1024]; stream = new ZipInputStream(new FileInputStream(zipFile)); ZipEntry entry; while ((entry = stream.getNextEntry()) != null) { String entryName = entry.getName(); if (entryName.equals(fileName)) { tempFile = File.createTempFile(FilenameUtils.getName(entryName), FilenameUtils.getExtension(entryName)); tempFile.deleteOnExit(); outStream = new BufferedOutputStream(new FileOutputStream(tempFile)); int readBytes; while ((readBytes = stream.read(buf, 0, 1024)) > -1) { outStream.write(buf, 0, readBytes); } stream.close(); outStream.close(); return tempFile; } } } finally { IOUtils.closeQuietly(stream); IOUtils.closeQuietly(outStream); } return tempFile; }
From source file:gobblin.util.recordcount.LateFileRecordCountProvider.java
/** * Construct filename for a late file. If the file does not exists in the output dir, retain the original name. * Otherwise, append a LATE_COMPONENT{RandomInteger} to the original file name. * For example, if file "part1.123.avro" exists in dir "/a/b/", the returned path will be "/a/b/part1.123.late12345.avro". *//*from ww w . j a v a 2 s.c om*/ public Path constructLateFilePath(String originalFilename, FileSystem fs, Path outputDir) throws IOException { if (!fs.exists(new Path(outputDir, originalFilename))) { return new Path(outputDir, originalFilename); } return constructLateFilePath(FilenameUtils.getBaseName(originalFilename) + LATE_COMPONENT + new Random().nextInt(Integer.MAX_VALUE) + SEPARATOR + FilenameUtils.getExtension(originalFilename), fs, outputDir); }
From source file:com.anrisoftware.prefdialog.miscswing.filechoosers.FileFilterExtension.java
/** * Tests if the specified file path have the extension of the file filter. * * @param path/* www . j av a 2 s.c o m*/ * the {@link String}. * * @return {@code true} if the specified path have the extension of the file * filter. */ public boolean fileHaveExtension(String path) { return FilenameUtils.getExtension(path).equals(getExtension()); }