當前位置: 首頁>>代碼示例>>Java>>正文


Java FilenameUtils.getExtension方法代碼示例

本文整理匯總了Java中org.apache.commons.io.FilenameUtils.getExtension方法的典型用法代碼示例。如果您正苦於以下問題:Java FilenameUtils.getExtension方法的具體用法?Java FilenameUtils.getExtension怎麽用?Java FilenameUtils.getExtension使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.io.FilenameUtils的用法示例。


在下文中一共展示了FilenameUtils.getExtension方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: isValid

import org.apache.commons.io.FilenameUtils; //導入方法依賴的package包/類
@Override
public boolean isValid(final String value, final ConstraintValidatorContext context) {
    try {
        if (StringUtils.isEmpty(value)) {
            return true; // do not validate empty value there are other constraints for that e.g. @NotNull, @Size etc...
        }

        final Path path = Paths.get(value);

        if (checkIfExists && !path.toFile().exists()) {
            return false;
        }

        final String fileExt = FilenameUtils.getExtension(value);
        return allowableFileExtensions.isEmpty() ||
               !allowableFileExtensions.stream().filter(fileExt::equalsIgnoreCase).findFirst().orElse(StringUtils.EMPTY).isEmpty();

    } catch (final InvalidPathException e) {
        LOGGER.error(e.getMessage(), e);
        return false;
    }
}
 
開發者ID:cerner,項目名稱:jwala,代碼行數:23,代碼來源:PathValidator.java

示例2: transform

import org.apache.commons.io.FilenameUtils; //導入方法依賴的package包/類
@Override
public Resource transform(HttpServletRequest request, Resource resource, ResourceTransformerChain transformerChain) throws IOException {
    resource = transformerChain.transform(request, resource);

    final String fileName = resource.getFilename();
    final String fileExt = FilenameUtils.getExtension(fileName);
    switch (fileExt) {
        case "js":
        case "json":
        case "css":
        case "html":
            log.trace("format {} supported for Text-Injection", fileExt);
            return transformText(fileName, resource);
        default:
            log.trace("unsupported Resource-Type: {}", fileExt);
            return resource;
    }
}
 
開發者ID:redlink-gmbh,項目名稱:smarti,代碼行數:19,代碼來源:PropertyInjectionTransformer.java

示例3: exportImage

import org.apache.commons.io.FilenameUtils; //導入方法依賴的package包/類
public void exportImage() {
  try {
    File file = IOUtility.selectFileToSave(FileType.IMAGE);
    if (file != null) {
      Rectangle drawingArea = getDrawingArea();
      String extension = FilenameUtils.getExtension(file.getName());
      if (extension.equals("svg")) {
        SVGGraphics2D svgGenerator = IOUtility.getSVGGraphics(drawingArea.getSize());
        paintDrawing(svgGenerator, drawingArea.x, drawingArea.y);
        svgGenerator.stream(new FileWriter(file));
        svgGenerator.dispose();
      } else {
        BufferedImage bi = new BufferedImage(drawingArea.width, drawingArea.height, BufferedImage.TYPE_INT_RGB);
        Graphics g = bi.createGraphics();
        paintDrawing(g, drawingArea.x, drawingArea.y);
        ImageIO.write(bi, extension, file);
        g.dispose();
      }
    }
  } catch (Exception e) {
    e.printStackTrace();
  }
}
 
開發者ID:onprom,項目名稱:onprom,代碼行數:24,代碼來源:UMLDiagramPanel.java

示例4: loadFile

import org.apache.commons.io.FilenameUtils; //導入方法依賴的package包/類
private static int[] loadFile(File file) throws IOException {
    String ext = FilenameUtils.getExtension(file.getName());
    try (InputStream is = new FileInputStream(file)) {
        if ("zip".equalsIgnoreCase(ext)) {
            try (ZipInputStream zis = new ZipInputStream(is)) {
                ZipEntry entry;
                while ((entry = zis.getNextEntry()) != null) {
                    String name = entry.getName();
                    String entryExt = FilenameUtils.getExtension(name);
                    if (Stream.of("gb", "gbc", "rom").anyMatch(e -> e.equalsIgnoreCase(entryExt))) {
                        return load(zis, (int) entry.getSize());
                    }
                    zis.closeEntry();
                }
            }
            throw new IllegalArgumentException("Can't find ROM file inside the zip.");
        } else {
            return load(is, (int) file.length());
        }
    }
}
 
開發者ID:trekawek,項目名稱:coffee-gb,代碼行數:22,代碼來源:Cartridge.java

示例5: validate

import org.apache.commons.io.FilenameUtils; //導入方法依賴的package包/類
public static boolean validate(String container) {
	if (container != null) {
		String[] names = StringUtils.split(container, "/");
		IResource resource = wsRoot.findMember(new Path("/" + names[0]));
		IPath loc = resource.getLocation();
		File prjLoc = new File(loc.toString());
		File[] res = prjLoc.listFiles();
		HashMap<String, ArrayList<File>> fileGroups = new HashMap<String, ArrayList<File>>();
		HashMap<String, Integer> groupCnt = new HashMap<String, Integer>();
		for (File file : res) {
			String extension = FilenameUtils.getExtension(file.getName());
			ArrayList<File> list = fileGroups.get(extension);
			int cnt = (groupCnt.get(extension) == null) ? 0 : groupCnt.get(extension).intValue();
			if (list == null)
				list = new ArrayList<File>();
			list.add(file);
			cnt++;
			groupCnt.put(extension, new Integer(cnt));
			fileGroups.put(extension, list);
		}
		return !validate(groupCnt);
	}
	return false;
}
 
開發者ID:dstl,項目名稱:Open_Source_ECOA_Toolset_AS5,代碼行數:25,代碼來源:GenerationUtils.java

示例6: recordUncompressedFiles

import org.apache.commons.io.FilenameUtils; //導入方法依賴的package包/類
public void recordUncompressedFiles(ExtFile apkFile, Collection<String> uncompressedFilesOrExts) throws AndrolibException {
    try {
        Directory unk = apkFile.getDirectory();
        Set<String> files = unk.getFiles(true);
        String ext;

        for (String file : files) {
            if (isAPKFileNames(file) && !NO_COMPRESS_PATTERN.matcher(file).find()) {
                if (unk.getCompressionLevel(file) == 0) {
                    ext = FilenameUtils.getExtension(file);
                    if (ext.isEmpty()) {
                        ext = file;
                    }
                    if (! uncompressedFilesOrExts.contains(ext)) {
                        uncompressedFilesOrExts.add(ext);
                    }
                }
            }
        }
    } catch (DirectoryException ex) {
        throw new AndrolibException(ex);
    }
}
 
開發者ID:imkiva,項目名稱:AndroidApktool,代碼行數:24,代碼來源:Androlib.java

示例7: generateChannelApk

import org.apache.commons.io.FilenameUtils; //導入方法依賴的package包/類
private void generateChannelApk(final File inputFile, final File outputDir, final String channel, final String alias, final Map<String, String> extraInfo) {
    final String channelName = alias == null ? channel : alias;
    final String name = FilenameUtils.getBaseName(inputFile.getName());
    final String extension = FilenameUtils.getExtension(inputFile.getName());
    final String newName = name + "_" + channelName + "." + extension;
    final File channelApk = new File(outputDir, newName);
    try {
        FileUtils.copyFile(inputFile, channelApk);
        ChannelWriter.put(channelApk, channel, extraInfo);
    } catch (IOException | SignatureNotFoundException e) {
        e.printStackTrace();
    }
}
 
開發者ID:Meituan-Dianping,項目名稱:walle,代碼行數:14,代碼來源:Batch2Command.java

示例8: accept

import org.apache.commons.io.FilenameUtils; //導入方法依賴的package包/類
public boolean accept(File file) {
    if (file.isDirectory()) {
        return true;
    }
    String extension = FilenameUtils.getExtension(file.getName());
    if (!extension.isEmpty()) {
        for (FileType ft : fileType) {
            if (ft.contains(extension))
                return true;
        }
    }
    return false;
}
 
開發者ID:onprom,項目名稱:onprom,代碼行數:14,代碼來源:FileTypeFilter.java

示例9: getNamesWithOnlyExtensionOufOfNames

import org.apache.commons.io.FilenameUtils; //導入方法依賴的package包/類
public static String[] getNamesWithOnlyExtensionOufOfNames(String[] names) {
    String[] ausgabe = new String[names.length];
    int i = 0;
    for(String g : names) {
        ausgabe[i] = FilenameUtils.getExtension(g);
        i++;
    }
    return ausgabe;
}
 
開發者ID:Panzer1119,項目名稱:JAddOn,代碼行數:10,代碼來源:JUtils.java

示例10: getFileExtension

import org.apache.commons.io.FilenameUtils; //導入方法依賴的package包/類
/**
 * Gets file's extension, including .gz postfix if present
 * @param fileName the name of the file
 * @return file's extension
 */
public static String getFileExtension(String fileName) {
    String result = fileName;
    boolean compressed = false;
    if (fileName.endsWith(GZ_EXTENSION)) {
        result = fileName.substring(0, fileName.length() - GZ_EXTENSION.length());
        compressed = true;
    }
    result = FilenameUtils.getExtension(result);
    return '.' + (compressed ? (result + GZ_EXTENSION) : result);
}
 
開發者ID:react-dev26,項目名稱:NGB-master,代碼行數:16,代碼來源:Utils.java

示例11: getContextFactory

import org.apache.commons.io.FilenameUtils; //導入方法依賴的package包/類
public static ContextFactory getContextFactory(Path path) {
	String extension = FilenameUtils.getExtension(path.toString());
	ContextFactory factory = cache.get(extension);
	if (factory == null) {
		throw new NullPointerException(" No factory found for : " + path);
	}
	return factory;
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:9,代碼來源:GraphWalkerFacade.java

示例12: extractPiFromFileName

import org.apache.commons.io.FilenameUtils; //導入方法依賴的package包/類
/**
 * 
 * @param file
 * @return
 * @should extract file name correctly
 */
public static String extractPiFromFileName(Path file) {
    String fileExtension = FilenameUtils.getExtension(file.getFileName().toString());
    if (MetsIndexer.ANCHOR_UPDATE_EXTENSION.equals("." + fileExtension) || "delete".equals(fileExtension) || "purge".equals(fileExtension)) {
        String pi = FilenameUtils.getBaseName(file.getFileName().toString());
        if (pi.contains("#")) {
            pi = pi.substring(0, pi.indexOf("#"));
        }
        logger.info("Record identifier extracted from file name: {}", pi);
        return pi;
    }

    return null;
}
 
開發者ID:intranda,項目名稱:goobi-viewer-indexer,代碼行數:20,代碼來源:Utils.java

示例13: userRegist

import org.apache.commons.io.FilenameUtils; //導入方法依賴的package包/類
@RequestMapping(method=RequestMethod.POST)
public ModelAndView userRegist(@Valid User reguser,  BindingResult result,
		MultipartFile idPicPath,
		HttpServletRequest request) throws Exception{
	ModelAndView mv = new ModelAndView();
	//if(result.hasErrors()){
	//	mv.setViewName("useradd");
	//}else{
		// ��ȡWebContent����Ŀ¼���·��
		String path = request.getServletContext().getRealPath("/upload");
	
		// �����ϴ���ͼƬ�ļ�
		String fileName = idPicPath.getOriginalFilename(); // ԭʼ�ļ���
		// �ļ��� = "����ַ������" + ".��׺��"
		String ext = FilenameUtils.getExtension(fileName);
		fileName = UUID.randomUUID().toString() + "." + ext;
				//System.currentTimeMillis() 
				//Math.random() * 100000
		
		File file = 
				new File(path + "/" + fileName);
		idPicPath.transferTo(file);  // "���Ϊ"ָ��Ŀ���ļ�
		
		reguser.setIdpicpath("upload/" + fileName); // �ļ����·��(д����ݿ�)
		
		int count = userService.insertUser(reguser);
		if(count > 0) {
			// ע��ɹ�����ת���û��б�ҳ��
			// �ض��� response.sendRedirect("/user");
			mv.setViewName("redirect:/user");
		}else{
			mv.setViewName("useradd");
		}
	//}
	return mv;
}
 
開發者ID:Marui0325,項目名稱:y2t187test,代碼行數:37,代碼來源:UserControl.java

示例14: getThumbUrl

import org.apache.commons.io.FilenameUtils; //導入方法依賴的package包/類
/**
 * 縮略圖文件URL/ID編輯 <br>
 * 取縮略圖
 * 
 * @param orgiUrl 原圖URL
 * @param width 文件寬
 * @param height 文件高
 * @return 縮略圖URl
 */
public static String getThumbUrl(String orgiUrl, int width, int height) {

    if (orgiUrl == null) {
        return null;
    }

    String extension = FilenameUtils.getExtension(orgiUrl);
    if (extension == null) {
        return orgiUrl;
    }

    if ("jpg".equalsIgnoreCase(extension)) {
        // 縮略圖
    } else if ("png".equalsIgnoreCase(extension)) {
        // 縮略圖
    } else {
        return orgiUrl;
    }

    int extensionPos = orgiUrl.length() - extension.length() - 1;

    StringBuffer stringBuffer = new StringBuffer();
    stringBuffer.append(orgiUrl.substring(0, extensionPos));
    stringBuffer.append("_").append(width).append("x").append(height);
    stringBuffer.append(orgiUrl.substring(extensionPos));

    return stringBuffer.toString();
}
 
開發者ID:ccfish86,項目名稱:sctalk,代碼行數:38,代碼來源:ThumbUrlUtils.java

示例15: validateFileExtension

import org.apache.commons.io.FilenameUtils; //導入方法依賴的package包/類
private boolean validateFileExtension(String fileName) {
    String extension = FilenameUtils.getExtension(fileName);
    return extension.equals("bar");
}
 
開發者ID:opensecuritycontroller,項目名稱:osc-core,代碼行數:5,代碼來源:PluginUploader.java


注:本文中的org.apache.commons.io.FilenameUtils.getExtension方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。