本文整理汇总了Java中org.apache.commons.io.FileExistsException类的典型用法代码示例。如果您正苦于以下问题:Java FileExistsException类的具体用法?Java FileExistsException怎么用?Java FileExistsException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileExistsException类属于org.apache.commons.io包,在下文中一共展示了FileExistsException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: injectCorruptReplica
import org.apache.commons.io.FileExistsException; //导入依赖的package包/类
@Override
public void injectCorruptReplica(ExtendedBlock block) throws IOException {
Preconditions.checkState(!dataset.contains(block),
"Block " + block + " already exists on dataset.");
try (FsVolumeReferences volRef = dataset.getFsVolumeReferences()) {
FsVolumeImpl volume = (FsVolumeImpl) volRef.get(0);
FinalizedReplica finalized = new FinalizedReplica(
block.getLocalBlock(),
volume,
volume.getFinalizedDir(block.getBlockPoolId()));
File blockFile = finalized.getBlockFile();
if (!blockFile.createNewFile()) {
throw new FileExistsException(
"Block file " + blockFile + " already exists.");
}
File metaFile = FsDatasetUtil.getMetaFile(blockFile, 1000);
if (!metaFile.createNewFile()) {
throw new FileExistsException(
"Meta file " + metaFile + " already exists."
);
}
}
}
示例2: writeStringToFile
import org.apache.commons.io.FileExistsException; //导入依赖的package包/类
/**
* writes string to file
* @param string string to write
* @param file file to which the string shall be written
* @throws FileExistsException is thrown if file already exists
*/
public static void writeStringToFile(String string, String file) throws
FileExistsException {
LOGGER.debug("file " + file);
if(Files.exists(Paths.get(file)))
throw new FileExistsException("File " + file + "already exists");
File f = new File(file);
f.getParentFile().mkdirs();
try {
PrintWriter out = new PrintWriter(f);
out.write(string);
out.close();
} catch (FileNotFoundException e) {
LOGGER.error(e.getMessage());
assert false;
}
}
示例3: writeAntlrAritfactsTo
import org.apache.commons.io.FileExistsException; //导入依赖的package包/类
/**
* write antlr artifacts to destination
* @param dest directory to which the artifacts should be written
*/
public void writeAntlrAritfactsTo(String dest) {
MemoryTupleSet ms = getAllCompiledObjects();
for(MemoryTuple tup : ms) {
MemorySource src = tup.getSource();
try {
FileUtils.writeStringToFile(src.getCharContent(false).toString(),
Paths.get(dest, src.getClassName()).toString() + "" +
".java");
} catch (FileExistsException e) {
LOGGER.error(e.getMessage());
}
}
}
示例4: saveProfile
import org.apache.commons.io.FileExistsException; //导入依赖的package包/类
public static File saveProfile(String name, boolean overrideExisting) throws IOException, FileExistsException, ConfigurationException {
if (StringUtils.isEmpty(name))
throw new IOException("No name given!");
if (!name.matches(PROFILE_NAME_REGEX))
throw new IOException("Invalid profile name "+name+" - only alphanumeric characters and underscores are allowed!");
if (isPredefinedProfile(name))
throw new IOException("Cannot ovverride a predefined profile!");
if (getAvailableProfiles().contains(name) && !overrideExisting) {
throw new FileExistsException("Profile "+name+" already exists!");
}
File profileFile = new File(PROFILES_FOLDER+"/"+name+PROFILE_SUFFIX);
logger.info("storing new profile: "+profileFile.getAbsolutePath());
config.save(profileFile);
return profileFile;
}
示例5: changeUserAvatar
import org.apache.commons.io.FileExistsException; //导入依赖的package包/类
@Override
public User changeUserAvatar(Long userId, MultipartFile avatarFile) throws IOException {
User user = findUser(userId);
File currentAvatarFile = new File(platformResourceConfigurationProperties.getImageLibraryDirectory() + "/user-avatar/" + user.getAvatarFileName());
if (currentAvatarFile.exists()) {
if (!currentAvatarFile.delete()) {
throw new FileExistsException();
}
}
PasswordEncoder encoder = new BCryptPasswordEncoder();
String newAvatarFileName = encoder.encode(avatarFile.getName() + new Date().getTime()).replaceAll("\"", "s").replaceAll("/", "a").replace(".", "sde");
File newAvatarFile = new File(platformResourceConfigurationProperties.getImageLibraryDirectory() + "/user-avatar/" + newAvatarFileName);
FileOutputStream out = new FileOutputStream(newAvatarFile);
out.write(avatarFile.getBytes());
out.close();
user.setAvatarFileName(newAvatarFileName);
updateUser(user);
return findUser(userId);
}
示例6: changeIcon
import org.apache.commons.io.FileExistsException; //导入依赖的package包/类
@PreAuthorize("hasPermission(#id, '" + AclClassName.Values.LAYOUT + "', '" + PermissionName.Values.LAYOUT_EDIT + "')")
@Override
public Layout changeIcon(Long id, MultipartFile iconFile) throws IOException {
Layout layout = findLayout(id);
File currentAvatarFile = new File(platformResourceConfigurationProperties.getImageLibraryDirectory() + "/layout-miniature/" + layout.getIconFileName());
if (currentAvatarFile.exists()) {
if (!currentAvatarFile.delete()) {
throw new FileExistsException();
}
}
PasswordEncoder encoder = new BCryptPasswordEncoder();
String newIconFileName = encoder.encode(iconFile.getName() + new Date().getTime()).replaceAll("\"", "s").replaceAll("/", "a").replace(".", "sde");
File newIconFile = new File(platformResourceConfigurationProperties.getImageLibraryDirectory() + "/layout-miniature/" + newIconFileName);
FileOutputStream out = new FileOutputStream(newIconFile);
out.write(iconFile.getBytes());
out.close();
layout.setIconFileName(newIconFileName);
updateLayout(layout);
return findLayout(id);
}
示例7: downloadDistributeStormCode
import org.apache.commons.io.FileExistsException; //导入依赖的package包/类
/**
* Don't need synchronize, due to EventManager will execute serially
*
* @param conf
* @param topologyId
* @param masterCodeDir
* @throws IOException
* @throws TException
*/
private void downloadDistributeStormCode(Map conf, String topologyId, String masterCodeDir) throws IOException, TException {
// STORM_LOCAL_DIR/supervisor/tmp/(UUID)
String tmproot = StormConfig.supervisorTmpDir(conf) + File.separator + UUID.randomUUID().toString();
// STORM_LOCAL_DIR/supervisor/stormdist/topologyId
String stormroot = StormConfig.supervisor_stormdist_root(conf, topologyId);
JStormServerUtils.downloadCodeFromMaster(conf, tmproot, masterCodeDir, topologyId, true);
// tmproot/stormjar.jar
String localFileJarTmp = StormConfig.stormjar_path(tmproot);
// extract dir from jar
JStormUtils.extract_dir_from_jar(localFileJarTmp, StormConfig.RESOURCES_SUBDIR, tmproot);
File srcDir = new File(tmproot);
File destDir = new File(stormroot);
try {
FileUtils.moveDirectory(srcDir, destDir);
} catch (FileExistsException e) {
FileUtils.copyDirectory(srcDir, destDir);
FileUtils.deleteQuietly(srcDir);
}
}
示例8: writeDataset
import org.apache.commons.io.FileExistsException; //导入依赖的package包/类
/**
* Writes the created dataset to the given file
*
* @param file
* The file to write the dataset to.
* @throws IOException
* If the file could not be written
*/
public void writeDataset(final File file) throws IOException
{
// Check if the file already exists
if (file.exists())
throw new FileExistsException(file);
// Ensure that the directory exists for the file
if (!file.getParentFile().mkdirs())
throw new IOException("Cannot create directory " + file.getParent());
// Write all the annotated identifiers
final FileWriter fw = new FileWriter(file);
for (final AnnotatedIdentifiable ai : this.dataset)
fw.append(ai.toString() + "\n");
fw.close();
}
示例9: moveFileToHiddenDirectory
import org.apache.commons.io.FileExistsException; //导入依赖的package包/类
private void moveFileToHiddenDirectory(File source) throws IOException {
boolean exists = true;
int i = 0;
while (exists) {
File backup = FileUtils.toFile(getHiddenDirectoryPathForFile(source, String.valueOf(i)));
try {
FileUtils.moveFile(source, backup);
exists = false;
} catch (FileExistsException ex) {
LOG.error("Exception moving file to hidden folder because {}. Retrying...", ex.getMessage());
exists = true;
}
i++;
if (i > maxFileExistRetrys) {
throw new IOException(String.format("moveFileToHiddenDirectory has hit %s for %s" + maxFileExistRetrys, source.getName()));
}
}
}
示例10: addProfileAttachment
import org.apache.commons.io.FileExistsException; //导入依赖的package包/类
@Override
public ProfileAttachment addProfileAttachment(final String profileId, final String attachmentName,
final InputStream file) throws ProfileException {
String storeName = "/" + profileId + "/" + FilenameUtils.removeExtension(attachmentName);
try {
ObjectId currentId = checkIfAttachmentExist(storeName);
String mimeType = getAttachmentContentType(attachmentName);
FileInfo fileInfo;
if (currentId != null) { // Update !!!
fileInfo = profileRepository.updateFile(currentId, file, storeName, mimeType, true);
} else {
fileInfo = profileRepository.saveFile(file, storeName, mimeType);
}
return fileInfoToProfileAttachment(fileInfo);
} catch (MongoDataException | FileExistsException | FileNotFoundException e) {
throw new ProfileException("Unable to attach file to profile '" + profileId + "'", e);
}
}
示例11: moveFile
import org.apache.commons.io.FileExistsException; //导入依赖的package包/类
private void moveFile(String currentAbsolutePath, String newAbsolutePath) throws BuenOjoFileException{
try {
FileUtils.moveFile(new File(currentAbsolutePath), new File(newAbsolutePath));
} catch (FileExistsException fe){
log.error(fe.getMessage());
throw new BuenOjoFileException("no se pudo mover el archivo: " +currentAbsolutePath+" al destino"+ newAbsolutePath + " porque ese archivo ya existe");
} catch (IOException e) {
log.error(e.getMessage());
throw new BuenOjoFileException("no se pudo mover el archivo: " +currentAbsolutePath+" al destino: "+ newAbsolutePath + e.getMessage());
}
}
示例12: gen
import org.apache.commons.io.FileExistsException; //导入依赖的package包/类
/**
* Create a keystore for the given path and store various keys in it which are needed for JWT.
*
* @param keystorePath
* @param keystorePassword
* @throws NoSuchAlgorithmException
* Thrown if the HmacSHA256 algorithm could not be found
* @throws KeyStoreException
* @throws IOException
* @throws CertificateException
*/
public static void gen(String keystorePath, String keystorePassword)
throws NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException {
Objects.requireNonNull(keystorePassword, "The keystore password must be specified.");
File keystoreFile = new File(keystorePath);
if (keystoreFile.exists()) {
throw new FileExistsException(keystoreFile);
}
KeyGenerator keygen = KeyGenerator.getInstance("HmacSHA256");
SecretKey key = keygen.generateKey();
KeyStore keystore = KeyStore.getInstance("jceks");
keystore.load(null, null);
// This call throws an exception
keystore.setKeyEntry("HS256", key, keystorePassword.toCharArray(), null);
FileOutputStream fos = new FileOutputStream(keystoreFile);
try {
keystore.store(fos, keystorePassword.toCharArray());
fos.flush();
} finally {
fos.close();
}
// SecretKey keyRetrieved = (SecretKey) keystore.getKey("theKey", keystorePassword.toCharArray());
// System.out.println(keyRetrieved.getAlgorithm());
}
示例13: getConfigs
import org.apache.commons.io.FileExistsException; //导入依赖的package包/类
private void getConfigs() throws IOException {
File configZip;
File customConfig = new File(synchronizationData.cohereDir, "customConfig.zip");
File localConfig = new File(localhost, "config");
try {
FileUtils.moveDirectory(new File("config"), localConfig); //Move config folder
}
catch (FileExistsException ignored) {}
if (synchronizationData.updateConfigs || !customConfig.exists()) { //Download the new config if updateConfigs is true
uiProgress.info("Downloading configs", 3);
configZip = new File(synchronizationData.cohereDir, "config.zip");
if (configZip.exists())
configZip.delete();
configZip.createNewFile();
FileOutputStream fstream = new FileOutputStream(configZip);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
POSTGetter.get(synchronizationData.url + "/config", stream);
stream.writeTo(fstream);
fstream.close();
stream.close();
}
else { //Otherwise, use the old configs.
uiProgress.info("Using previous configs", 3);
configZip = customConfig;
}
logger.info("Extracting configs", 2);
UnzipUtility.unzip(configZip.getPath(), new File(".").getPath());
}
示例14: moveDirectory
import org.apache.commons.io.FileExistsException; //导入依赖的package包/类
/**
* Moves a directory.
* <p>
* When the destination directory is on another file system, do a "copy and delete".
*
* @param srcDir the directory to be moved
* @param destDir the destination directory
* @throws NullPointerException if source or destination is {@code null}
* @throws FileExistsException if the destination directory exists
* @throws IOException if source or destination is invalid
* @throws IOException if an IO error occurs moving the file
* @since 1.4
*/
public static void moveDirectory(File srcDir, File destDir) throws IOException {
if (srcDir == null) {
throw new NullPointerException("Source must not be null");
}
if (destDir == null) {
throw new NullPointerException("Destination must not be null");
}
if (!srcDir.exists()) {
throw new FileNotFoundException("Source '" + srcDir + "' does not exist");
}
if (!srcDir.isDirectory()) {
throw new IOException("Source '" + srcDir + "' is not a directory");
}
if (destDir.exists()) {
throw new FileExistsException("Destination '" + destDir + "' already exists");
}
boolean rename = srcDir.renameTo(destDir);
if (!rename) {
if (destDir.getCanonicalPath().startsWith(srcDir.getCanonicalPath())) {
throw new IOException("Cannot move directory: "+srcDir+" to a subdirectory of itself: "+destDir);
}
copyDirectory( srcDir, destDir );
deleteDirectory( srcDir );
if (srcDir.exists()) {
throw new IOException("Failed to delete original directory '" + srcDir +
"' after copy to '" + destDir + "'");
}
}
}
示例15: moveFile
import org.apache.commons.io.FileExistsException; //导入依赖的package包/类
/**
* Moves a file.
* <p>
* When the destination file is on another file system, do a "copy and delete".
*
* @param srcFile the file to be moved
* @param destFile the destination file
* @throws NullPointerException if source or destination is {@code null}
* @throws FileExistsException if the destination file exists
* @throws IOException if source or destination is invalid
* @throws IOException if an IO error occurs moving the file
* @since 1.4
*/
public static void moveFile(File srcFile, File destFile) throws IOException {
if (srcFile == null) {
throw new NullPointerException("Source must not be null");
}
if (destFile == null) {
throw new NullPointerException("Destination must not be null");
}
if (!srcFile.exists()) {
throw new FileNotFoundException("Source '" + srcFile + "' does not exist");
}
if (srcFile.isDirectory()) {
throw new IOException("Source '" + srcFile + "' is a directory");
}
if (destFile.exists()) {
throw new FileExistsException("Destination '" + destFile + "' already exists");
}
if (destFile.isDirectory()) {
throw new IOException("Destination '" + destFile + "' is a directory");
}
boolean rename = srcFile.renameTo(destFile);
if (!rename) {
copyFile( srcFile, destFile );
if (!srcFile.delete()) {
FileUtils.deleteQuietly(destFile);
throw new IOException("Failed to delete original file '" + srcFile +
"' after copy to '" + destFile + "'");
}
}
}