本文整理汇总了Java中java.nio.file.AtomicMoveNotSupportedException类的典型用法代码示例。如果您正苦于以下问题:Java AtomicMoveNotSupportedException类的具体用法?Java AtomicMoveNotSupportedException怎么用?Java AtomicMoveNotSupportedException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AtomicMoveNotSupportedException类属于java.nio.file包,在下文中一共展示了AtomicMoveNotSupportedException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFileSystemExceptions
import java.nio.file.AtomicMoveNotSupportedException; //导入依赖的package包/类
public void testFileSystemExceptions() throws IOException {
for (FileSystemException ex : Arrays.asList(new FileSystemException("a", "b", "c"),
new NoSuchFileException("a", "b", "c"),
new NotDirectoryException("a"),
new DirectoryNotEmptyException("a"),
new AtomicMoveNotSupportedException("a", "b", "c"),
new FileAlreadyExistsException("a", "b", "c"),
new AccessDeniedException("a", "b", "c"),
new FileSystemLoopException("a"))) {
FileSystemException serialize = serialize(ex);
assertEquals(serialize.getClass(), ex.getClass());
assertEquals("a", serialize.getFile());
if (serialize.getClass() == NotDirectoryException.class ||
serialize.getClass() == FileSystemLoopException.class ||
serialize.getClass() == DirectoryNotEmptyException.class) {
assertNull(serialize.getOtherFile());
assertNull(serialize.getReason());
} else {
assertEquals(serialize.getClass().toString(), "b", serialize.getOtherFile());
assertEquals(serialize.getClass().toString(), "c", serialize.getReason());
}
}
}
示例2: move
import java.nio.file.AtomicMoveNotSupportedException; //导入依赖的package包/类
@Override
public void move(Path source, Path target, CopyOption... options) throws IOException {
HashSet<CopyOption> copyOptions = Sets.newHashSet(options);
if (copyOptions.contains(StandardCopyOption.ATOMIC_MOVE)) {
throw new AtomicMoveNotSupportedException(source.toString(), target.toString(),
"ATOMIC_MOVE not supported yet");
}
if (Files.isDirectory(source)) {
MCRPath src = MCRFileSystemUtils.checkPathAbsolute(source);
MCRDirectory srcRootDirectory = getRootDirectory(src);
if (srcRootDirectory.hasChildren()) {
throw new IOException("Directory is not empty");
}
}
copy(source, target, options);
delete(source);
}
示例3: copyIfLocked
import java.nio.file.AtomicMoveNotSupportedException; //导入依赖的package包/类
@Override
public void copyIfLocked(final Path source, final Path target, final Mover mover) throws IOException {
checkNotNull(source);
checkNotNull(target);
try {
mover.accept(source, target);
}
catch (AtomicMoveNotSupportedException atomicMoveNotSupported) {
throw atomicMoveNotSupported;
}
catch (FileSystemException e) { // NOSONAR
// Windows can throw a FileSystemException on move or moveAtomic
// if the file is in use; in this case, copy and attempt to delete
// source
log.warn("Using copy to move {} to {}", source, target);
copy(source, target);
try {
delete(source);
}
catch (IOException deleteException) { // NOSONAR
log.error("Unable to delete {} after move: {}", source, deleteException.getMessage());
}
}
}
示例4: temporaryBlobMoveFallback
import java.nio.file.AtomicMoveNotSupportedException; //导入依赖的package包/类
@Test
public void temporaryBlobMoveFallback() throws Exception {
final byte[] content = new byte[TEST_DATA_LENGTH];
new Random().nextBytes(content);
doThrow(new AtomicMoveNotSupportedException("", "", "")).when(fileOperations).moveAtomic(any(), any());
final Blob blob = underTest.create(new ByteArrayInputStream(content), TEST_HEADERS);
verifyMoveOperations(blob);
final byte[] output = extractContent(blob);
assertThat("data must survive", content, is(equalTo(output)));
final BlobMetrics metrics = blob.getMetrics();
assertThat("size must be calculated correctly", metrics.getContentSize(), is(equalTo((long) TEST_DATA_LENGTH)));
}
示例5: close
import java.nio.file.AtomicMoveNotSupportedException; //导入依赖的package包/类
@Override
public void close() throws IOException {
try {
this.channel.position(0); // reset channel to beginning to compute full SHA1
String calculatedSha1 = ZsyncUtil.computeSha1(this.channel);
if (!this.sha1.equals(calculatedSha1)) {
throw new ChecksumValidationIOException(this.sha1, calculatedSha1);
}
try {
Files.move(this.tempPath, this.path, REPLACE_EXISTING, ATOMIC_MOVE);
} catch (AtomicMoveNotSupportedException e) {
Files.move(this.tempPath, this.path, REPLACE_EXISTING);
}
Files.setLastModifiedTime(this.path, fromMillis(this.mtime));
} finally {
this.channel.close();
this.listener.close();
}
}
示例6: sauvegarde
import java.nio.file.AtomicMoveNotSupportedException; //导入依赖的package包/类
public boolean sauvegarde(Object o) {
if (this.getParentFile() != null && !this.getParentFile().exists()) {
this.getParentFile().mkdirs();
}
IOMethod m;
m = new JsonIO();
// m = new GsonIO();
// m = new Jackson();
try {
File security = new File(this.getParent()+Adresse.separatorChar+"."+this.getName());
m.sauvegarde(security, o);
if(!this.exists()) {this.createNewFile();}
try {
Files.move(security.toPath(), this.toPath(), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE);
} catch(AtomicMoveNotSupportedException ex) {
Files.move(security.toPath(), this.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
if(!security.delete()) {security.deleteOnExit();}
} catch(Exception e) {
Logger.getLogger(Adresse.class.getName()).log(Level.SEVERE, "adresse : "+this.getAbsolutePath(), e);
DialogueBloquant.error("dialog file not saved");
return false;
}
return true;
}
示例7: replaceFile
import java.nio.file.AtomicMoveNotSupportedException; //导入依赖的package包/类
public synchronized static void replaceFile(final File sourceFile, final File destFile)
throws IOException {
if (sourceFile == null) {
throw new NullPointerException("sourceFile");
}
if (destFile == null) {
throw new NullPointerException("destFile");
}
Path sourcePath = Paths.get(sourceFile.getAbsolutePath());
Path destPath = Paths.get(destFile.getAbsolutePath());
try {
Files.move(sourcePath, destPath, FileReplaceOptions);
} catch (AtomicMoveNotSupportedException ex) {
Files.move(sourcePath, destPath, FallbackFileReplaceOptions);
}
}
示例8: rename
import java.nio.file.AtomicMoveNotSupportedException; //导入依赖的package包/类
private static void rename(Path sourceFile, Path targetFile) throws IOException {
try {
Files.move(sourceFile, targetFile, StandardCopyOption.ATOMIC_MOVE);
} catch (AtomicMoveNotSupportedException e) {
LOG.warn("Atomic rename from '{}' to '{}' not supported", sourceFile, targetFile);
Files.move(sourceFile, targetFile);
}
}
示例9: moveIntoPlace
import java.nio.file.AtomicMoveNotSupportedException; //导入依赖的package包/类
private static void moveIntoPlace(final File from, final File to) throws IOException {
try {
move(from.toPath(), to.toPath(), ATOMIC_MOVE);
} catch (final AtomicMoveNotSupportedException ex) {
move(from.toPath(), to.toPath(), REPLACE_EXISTING);
} finally {
deleteIfExists(from.toPath());
}
}
示例10: move
import java.nio.file.AtomicMoveNotSupportedException; //导入依赖的package包/类
@Override
public void move(Path srcpath, SecureDirectoryStream<Path> targetdir, Path targetpath) throws IOException {
checkClosed();
checkFileSystem(srcpath);
checkFileSystem(targetpath);
throw new AtomicMoveNotSupportedException(srcpath.toString(), targetpath.toString(),
"Currently not implemented");
}
示例11: moveAtomic
import java.nio.file.AtomicMoveNotSupportedException; //导入依赖的package包/类
@Override
public void moveAtomic(final Path source, final Path target) throws IOException {
checkNotNull(source);
checkNotNull(target);
DirectoryHelper.mkdir(target.getParent());
try {
Files.move(source, target, StandardCopyOption.ATOMIC_MOVE);
}
catch (UnsupportedOperationException e) { // NOSONAR
throw new AtomicMoveNotSupportedException(source.toString(), target.toString(), e.getMessage());
}
}
示例12: overwriteAtomic
import java.nio.file.AtomicMoveNotSupportedException; //导入依赖的package包/类
@Override
public void overwriteAtomic(final Path source, final Path target) throws IOException {
checkNotNull(source);
checkNotNull(target);
DirectoryHelper.mkdir(target.getParent());
try {
Files.move(source, target, StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING);
}
catch (UnsupportedOperationException e) { // NOSONAR
throw new AtomicMoveNotSupportedException(source.toString(), target.toString(), e.getMessage());
}
}
示例13: move
import java.nio.file.AtomicMoveNotSupportedException; //导入依赖的package包/类
private void move(final Path source, final Path target) throws IOException {
if (supportsAtomicMove) {
try {
fileOperations.copyIfLocked(source, target, fileOperations::moveAtomic);
return;
}
catch (AtomicMoveNotSupportedException e) { // NOSONAR
supportsAtomicMove = false;
log.warn("Disabling atomic moves for blob store {}, could not move {} to {}, reason deleted: {}",
blobStoreConfiguration.getName(), source, target, e.getReason());
}
}
log.trace("Using normal move for blob store {}, moving {} to {}", blobStoreConfiguration.getName(), source, target);
fileOperations.copyIfLocked(source, target, fileOperations::move);
}
示例14: overwrite
import java.nio.file.AtomicMoveNotSupportedException; //导入依赖的package包/类
private void overwrite(final Path source, final Path target) throws IOException {
if (supportsAtomicMove) {
try {
fileOperations.copyIfLocked(source, target, fileOperations::overwriteAtomic);
return;
}
catch (AtomicMoveNotSupportedException e) { // NOSONAR
supportsAtomicMove = false;
log.warn("Disabling atomic moves for blob store {}, could not overwrite {} with {}, reason deleted: {}",
blobStoreConfiguration.getName(), source, target, e.getReason());
}
}
log.trace("Using normal overwrite for blob store {}, overwriting {} with {}", blobStoreConfiguration.getName(), source, target);
fileOperations.copyIfLocked(source, target, fileOperations::overwrite);
}
示例15: temporaryBlobMoveFallbackPersists
import java.nio.file.AtomicMoveNotSupportedException; //导入依赖的package包/类
@Test
public void temporaryBlobMoveFallbackPersists() throws Exception {
final byte[] content = new byte[TEST_DATA_LENGTH];
new Random().nextBytes(content);
doThrow(new AtomicMoveNotSupportedException("", "", "")).when(fileOperations).moveAtomic(any(), any());
underTest.create(new ByteArrayInputStream(content), TEST_HEADERS);
underTest.create(new ByteArrayInputStream(content), TEST_HEADERS);
verify(fileOperations, times(1)).moveAtomic(any(), any());
verify(fileOperations, times(4)).move(any(), any());
}