当前位置: 首页>>代码示例>>Java>>正文


Java FilenameUtils.getName方法代码示例

本文整理汇总了Java中org.apache.commons.io.FilenameUtils.getName方法的典型用法代码示例。如果您正苦于以下问题:Java FilenameUtils.getName方法的具体用法?Java FilenameUtils.getName怎么用?Java FilenameUtils.getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.io.FilenameUtils的用法示例。


在下文中一共展示了FilenameUtils.getName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test_runScript

import org.apache.commons.io.FilenameUtils; //导入方法依赖的package包/类
@Test
public void test_runScript() throws Exception {
    requestAddModule();
    String filename = FilenameUtils.getName(testScriptPath);
    if (filename == null) {
        logger.info("No script found - test escape");
    } else {
        MockMultipartFile file = new MockMultipartFile(
                "file",
                filename,
                "application/sql",
                new FileInputStream(testScriptPath));

        String genericModule = NamingUtils.getContainerName(applicationName, module, "johndoe");

        ResultActions result = mockMvc.perform(
                fileUpload("/module/{moduleName}/run-script", genericModule)
                        .file(file)
                        .session(session)
                        .contentType(MediaType.MULTIPART_FORM_DATA))
                .andDo(print());
        result.andExpect(status().isOk());
    }
}
 
开发者ID:oncecloud,项目名称:devops-cstack,代码行数:25,代码来源:AbstractModuleControllerTestIT.java

示例2: testGetDocById

import org.apache.commons.io.FilenameUtils; //导入方法依赖的package包/类
@Test
public void testGetDocById() throws MalformedURLException {
    createCollection();
    RestHeartClientResponse restHeartClientResponse = insertDocInDB();
    String documentUrlLocation = restHeartClientResponse.getDocumentUrlLocation();
    URL url = new URL(documentUrlLocation);
    String idCreate = FilenameUtils.getName(url.getPath());

    RestHeartClientResponse response = api.getDocumentById(dbName, collName, idCreate);
    Assert.assertNotNull("Response is null", response);

    JsonObject responseObject = response.getResponseObject();
    Assert.assertNotNull("Json object response is null", responseObject);

    String idRes = responseObject.get("_id").getAsJsonObject().get("$oid").getAsString();
    Assert.assertEquals("Id's do not match", idCreate, idRes);

    LOGGER.info(GsonUtils.toJson(response.getResponseObject()));
}
 
开发者ID:SoftGorilla,项目名称:restheart-java-client,代码行数:20,代码来源:RestHeartBasicClientApiTest.java

示例3: findFileName

import org.apache.commons.io.FilenameUtils; //导入方法依赖的package包/类
private String findFileName(String contentDisposition) {

		if (contentDisposition != null)
			try {
				Matcher matcher = CONTENT_DISPOSITION_PATTERN.matcher(contentDisposition);

				if (matcher.find()) {
					String match = matcher.group(1);

					if (match != null && !match.equals("")) {
						match = URLDecoder.decode(match, "UTF-8");
						return match;
					}
				}

			} catch (IllegalStateException ex) {
				// cannot find filename using content disposition http header.
				// Use url to find filename;
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
		return FilenameUtils.getName(downloadFileInfo.getUploadUrl().getPath());
	}
 
开发者ID:dhaval-mehta,项目名称:url-to-google-drive,代码行数:24,代码来源:DriveUploaderBuilder.java

示例4: loadMetadataFile

import org.apache.commons.io.FilenameUtils; //导入方法依赖的package包/类
private File loadMetadataFile(File[] tmpFolderList) throws VmidcBrokerValidationException {
    File metaDataFile = null;
    for (File tmpFolderFile : tmpFolderList) {
        String fileName = FilenameUtils.getName(tmpFolderFile.getName());
        if (fileName.equals(ImageMetadata.META_FILE_NAME)) {
            metaDataFile = tmpFolderFile;
            break;
        }
    }

    if (metaDataFile != null) {
        return metaDataFile;
    } else {
        throw new VmidcBrokerValidationException(
                VmidcMessages.getString(VmidcMessages_.UPLOAD_APPLIANCE_INVALID_METAFILE, ImageMetadata.META_FILE_NAME)
                );
    }
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:19,代码来源:ImportApplianceSoftwareVersionService.java

示例5: getFileFromResourcesByFilePath

import org.apache.commons.io.FilenameUtils; //导入方法依赖的package包/类
private File getFileFromResourcesByFilePath(String filePath) {
    URL url = BaseFileUploadSteps.class.getResource(filePath);
    String file = url.getFile();
    if (file.contains(".jar!/")) {
        try {
            File tempFile = new File(Files.createTempDir(), FilenameUtils
                    .getName(url.getFile()));
            IOUtils.copy(url.openStream(), org.apache.commons.io
                    .FileUtils.openOutputStream(tempFile));
            return tempFile;
        } catch (IOException e) {
            LOG.error(e.getMessage(), e);
        }
    }
    return new File(file);
}
 
开发者ID:tapack,项目名称:satisfy,代码行数:17,代码来源:BaseFileUploadSteps.java

示例6: getDownloadUrl

import org.apache.commons.io.FilenameUtils; //导入方法依赖的package包/类
/**
 * Get a signed url to view an attachment. The url will last 24 hours. The file name portion of the id is url escaped internally.
 *
 * @param id The id of the attachment.
 * @return Url
 */
public String getDownloadUrl(String id) {
    String filename = FilenameUtils.getName(id);
    String path = FilenameUtils.getFullPath(id);
    String escapedFullPath = FilenameUtils.concat(path, UrlEscapers.urlFragmentEscaper().escape(filename));
    return cloudStorage.generateSignedUrl(gcsDefaultBucket, escapedFullPath, DEFAULT_LINK_EXPIRY_DURATION);
}
 
开发者ID:3wks,项目名称:generator-thundr-gae-react,代码行数:13,代码来源:AttachmentService.java

示例7: getNodeName

import org.apache.commons.io.FilenameUtils; //导入方法依赖的package包/类
private static String getNodeName(URL file, GenerationConfig config) {
    try {
        String fileName = FilenameUtils.getName(URLDecoder.decode(file.toString(), "UTF-8"));
        String[] extensions = config.getFileExtensions();
        boolean extensionRemoved = false;
        for (int i = 0; i < extensions.length; i++) {
            String extension = extensions[i];
            if (extension.length() == 0) {
                continue;
            }
            if (!extension.startsWith(".")) {
                extension = "." + extension;
            }
            if (fileName.endsWith(extension)) {
                fileName = removeEnd(fileName, extension);
                extensionRemoved = true;
                break;
            }
        }
        if (!extensionRemoved) {
            fileName = FilenameUtils.getBaseName(fileName);
        }
        return fileName;
    } catch (UnsupportedEncodingException e) {
        throw new IllegalArgumentException(String.format("Unable to generate node name from URL: %s", file.toString()), e);
    }

}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:29,代码来源:Jsonschema2Pojo.java

示例8: testDeleteDocById

import org.apache.commons.io.FilenameUtils; //导入方法依赖的package包/类
@Test
public void testDeleteDocById() throws MalformedURLException {
    createCollection();
    RestHeartClientResponse restHeartClientResponse = insertDocInDB();
    String documentUrlLocation = restHeartClientResponse.getDocumentUrlLocation();
    URL url = new URL(documentUrlLocation);
    String id = FilenameUtils.getName(url.getPath());

    RestHeartClientResponse deleteDocByIdResponse = api.deleteDocumentById(dbName, collName, id);
    Assert.assertEquals(
        "response not as expected, Code" + deleteDocByIdResponse.getStatusCode() + ", ETag-"
            + deleteDocByIdResponse.getEtag(), 204,
        deleteDocByIdResponse.getStatusCode());
}
 
开发者ID:SoftGorilla,项目名称:restheart-java-client,代码行数:15,代码来源:RestHeartBasicClientApiTest.java

示例9: readFileAndSetInitialStateForAudioItem

import org.apache.commons.io.FilenameUtils; //导入方法依赖的package包/类
private void readFileAndSetInitialStateForAudioItem(final File singleFileFromOpenedDialog, final VBox vboxPlaylist)
        throws IOException {
    final AudioItem audioItem = new AudioItem();
    final String openDialogFilePath = singleFileFromOpenedDialog.getPath();
    LOGGER.info("Now is opening: " + openDialogFilePath);
    final String baseName = FilenameUtils.getName(openDialogFilePath);
    final String path = singleFileFromOpenedDialog.toURI().toASCIIString();
    final Media mediaSound = new Media(path);
    LOGGER.info("MediaSound " + mediaSound.getSource() + " opened");
    final MediaPlayer mediaPlayer = new MediaPlayer(mediaSound);
    final MediaView mediaView = new MediaView(mediaPlayer);

    setupTimeSliderDependsOnMediaPlayer(audioItem.getSlider(), audioItem.getLabel_for_time(), mediaPlayer);

    audioItem.getLabel_for_name().setText(baseName);
    audioItem.getChildren().addAll(mediaView);

    audioItem.getStop().setOnAction(action -> {
        mediaPlayer.stop();
        alreadyPlaying = false;
    });

    audioItem.getPlay().setOnAction(action -> {
        if (!alreadyPlaying) {
            final String formatted = formatDurationForMedia(mediaSound.getDuration());
            audioItem.getLabel_for_time().setText(formatted);
            mediaPlayer.play();
            alreadyPlaying = true;
        }
    });

    vboxPlaylist.getChildren().add(audioItem);

}
 
开发者ID:Evegen55,项目名称:main_carauto_board,代码行数:35,代码来源:AudioController.java

示例10: getName

import org.apache.commons.io.FilenameUtils; //导入方法依赖的package包/类
public String getName() {
    if (isFile()) {
        return title != null ? title : FilenameUtils.getBaseName(path);
    }

    return FilenameUtils.getName(path);
}
 
开发者ID:airsonic,项目名称:airsonic,代码行数:8,代码来源:MediaFile.java

示例11: extractNativeLibraries

import org.apache.commons.io.FilenameUtils; //导入方法依赖的package包/类
private File extractNativeLibraries(final File nativesDirectory, final String libraryPath) {
  final URL libraryUrl = Thread.currentThread().getContextClassLoader().getResource(libraryPath);
  if (libraryUrl == null) {
    throw new IllegalArgumentException(
        String.format("Unable to find native binary %s for library %s", libraryPath, key));
  }
  final String libraryName;
  libraryName = FilenameUtils.getName(libraryPath);
  final File libraryFile = new File(nativesDirectory, libraryName);
  libraryFile.getParentFile().mkdirs();
  try {
    final URLConnection urlConnection = libraryUrl.openConnection();
    try (final InputStream inputStream = urlConnection.getInputStream()) {
      try (final OutputStream outputStream =
          new BufferedOutputStream(new FileOutputStream(libraryFile))) {
        IOUtils.copy(inputStream, outputStream);
      }
    }
  } catch (final Exception exception) {
    throw new RuntimeException(exception);
  }
  if (deleteOnExit) {
    libraryFile.deleteOnExit();
  }
  // TODO make accessible for linux and mac
  return libraryFile;
}
 
开发者ID:klaushauschild1984,项目名称:java-natives,代码行数:28,代码来源:NativeLibrary.java

示例12: validate

import org.apache.commons.io.FilenameUtils; //导入方法依赖的package包/类
private void validate(EntityManager em, ImportFileRequest request, File tmpUploadFolder) throws Exception {

        if (!ServerUtil.isEnoughSpace()) {
            throw new VmidcException(VmidcMessages.getString("upload.plugin.nospace"));
        }

		File[] tmpFolderList = FileUtil.getFileListFromDirectory(tmpUploadFolder.getPath());
        for (File tmpFolderFile : tmpFolderList) {
            String fileName = FilenameUtils.getName(tmpFolderFile.getName());
            if (FilenameUtils.getExtension(fileName).equals("bar")) {
                this.barFile = tmpFolderFile;
                break;
            }
        }

        if (this.barFile == null) {
            throw new VmidcBrokerValidationException(
                    "Invalid upload folder. Should contain single .bar file.");
        }

        try (JarFile jar = new JarFile(this.barFile)) {
			Manifest manifest = jar.getManifest();
			Attributes attributes = manifest.getMainAttributes();
			String symbolicName = attributes.getValue("Deployment-SymbolicName");

			if (symbolicName == null) {
				throw new VmidcBrokerValidationException("uploaded file does not contain Deployment-SymbolicName: " + this.barFile);
			}

			this.deploymentName = symbolicName + ".bar";
        }

    }
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:34,代码来源:ImportPluginService.java

示例13: name

import org.apache.commons.io.FilenameUtils; //导入方法依赖的package包/类
public static String name(final String path) {
    final String normalized = normalize(path, true);
    if(String.valueOf(Path.DELIMITER).equals(normalized)) {
        return path;
    }
    return FilenameUtils.getName(normalized);
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:8,代码来源:PathNormalizer.java

示例14: getName

import org.apache.commons.io.FilenameUtils; //导入方法依赖的package包/类
@Override
public String getName() {
	if (fileData != null) {
		name = FilenameUtils.getName(fileData.getURL());
	}
	return super.getName();
}
 
开发者ID:HearthProject,项目名称:OneClient,代码行数:8,代码来源:CurseModInstaller.java

示例15: extractFile

import org.apache.commons.io.FilenameUtils; //导入方法依赖的package包/类
public static File extractFile(File zipFile, String path, File destDir) {

        destDir.mkdirs();

        new File(destDir, path).delete();

        //unzip -j taobao-android-debug.apk  res/drawable/abc_wb_textfield_cdf.jpg -d .
        boolean success = CmdExecutor.execute("", "unzip", "-o", "-j", zipFile.getAbsolutePath(), path, "-d",
                                              destDir.getAbsolutePath());

        if (success) {
            return new File(destDir, FilenameUtils.getName(path));
        }

        return ZipUtils.extractZipFileToFolder(zipFile, path, destDir);
    }
 
开发者ID:alibaba,项目名称:atlas,代码行数:17,代码来源:BetterZip.java


注:本文中的org.apache.commons.io.FilenameUtils.getName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。