本文整理匯總了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;
}
}
示例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;
}
}
示例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();
}
}
示例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());
}
}
}
示例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;
}
示例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);
}
}
示例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();
}
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例15: validateFileExtension
import org.apache.commons.io.FilenameUtils; //導入方法依賴的package包/類
private boolean validateFileExtension(String fileName) {
String extension = FilenameUtils.getExtension(fileName);
return extension.equals("bar");
}