本文整理汇总了Java中java.nio.file.CopyOption类的典型用法代码示例。如果您正苦于以下问题:Java CopyOption类的具体用法?Java CopyOption怎么用?Java CopyOption使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CopyOption类属于java.nio.file包,在下文中一共展示了CopyOption类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: copy
import java.nio.file.CopyOption; //导入依赖的package包/类
@Override
public Map<CloudPath,CloudMethod> copy(BlobStoreContext context, Set<CloudPath> sources, Path target, Set<CopyOption> options)
throws IOException {
boolean copyMethodReturns = !options.contains(CloudCopyOption.DONT_RETURN_COPY_METHOD);
Map<CloudPath,CloudMethod> copyMethodsMap = copyMethodReturns ? new HashMap<>() : null;
for (CloudPath source : sources) {
try {
copy(context, source, target, options);
} catch (IOException e) {
if (options.contains(CloudCopyOption.FAIL_SILENTLY)) {
LOG.warn("Copy from {} to {} failed, slient failure specified, continuing", source, target, e);
} else {
throw e;
}
}
}
return copyMethodsMap;
}
开发者ID:brdara,项目名称:java-cloud-filesystem-provider,代码行数:21,代码来源:DefaultCloudFileSystemImplementation.java
示例2: determineCloudMethodForCopyOrMoveOperations
import java.nio.file.CopyOption; //导入依赖的package包/类
protected CloudMethod determineCloudMethodForCopyOrMoveOperations(
String operationName, CloudPath source, Path target, Set<CopyOption> options) throws IOException {
// Don't copy a file to itself
if (source.equals(target)) {
throw new FileAlreadyExistsException("Cannot " + operationName + " a path to itself from '" + source.toAbsolutePath() +
"' -> '" + target.toAbsolutePath() + "'");
}
// Check if target exists and we are allowed to copy
if (Files.exists(target) && !options.contains(StandardCopyOption.REPLACE_EXISTING)) {
throw new FileAlreadyExistsException("Cannot copy from " + source.toAbsolutePath() +
" to " + target.toAbsolutePath() + ", the file already exists and file replace was not specified");
}
// Check if we can try a JClouds copy or we have to use the filesystem
if (target instanceof CloudPath) {
// Work out if we are using the same cloud settings - if we are then we can use a direct copy
CloudPath cloudPathTarget = (CloudPath)target;
if (source.getFileSystem().getCloudHostConfiguration().canOptimiseOperationsFor(cloudPathTarget)) {
return CloudMethod.CLOUD_OPTIMISED;
}
}
return CloudMethod.LOCAL_FILESYSTEM_FALLBACK;
}
开发者ID:brdara,项目名称:java-cloud-filesystem-provider,代码行数:26,代码来源:DefaultCloudFileSystemImplementation.java
示例3: move
import java.nio.file.CopyOption; //导入依赖的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);
}
示例4: move
import java.nio.file.CopyOption; //导入依赖的package包/类
@Override
public void move(Path source, Path target, CopyOption... options)
throws IOException
{
JPath jPath = (JPath) target;
copy(source, target, options);
Status status = jPath.getBfsFile().getStatus();
if (status.getType() == Status.FileType.NULL) {
throw new IOException(L.l("unable to move {0} to {1}", source.toUri(), target.toUri()));
}
delete(source);
}
示例5: copyRename
import java.nio.file.CopyOption; //导入依赖的package包/类
public String copyRename(String origin, String destination)// method to copy
// a
// file from a
// directory and
// rename it or
// change the
// extension
throws IOException {
Path FROM = Paths.get(origin);
String cnt = Integer.toString(counter);
counter++;
String res = destination.concat(cnt.concat(".txt"));
Path TO = Paths.get(res);
// overwrite the destination file if it exists, and copy
// the file attributes, including the rwx permissions
CopyOption[] options = new CopyOption[] { StandardCopyOption.REPLACE_EXISTING,
StandardCopyOption.COPY_ATTRIBUTES };
Files.copy(FROM, TO, options);
return res; // return a string of the path of the new txt file
}
示例6: copyFile
import java.nio.file.CopyOption; //导入依赖的package包/类
private void copyFile(Config config, Path sourcePath) throws IOException {
boolean subscribe = config.getCaption();
boolean left = config.getLeft();
boolean top = config.getTop();
int fontSize = config.getFontSize();
if (!subscribe || fontSize <= 0) {
Path targetPath = Paths.get(config.getDesktopFolder()+"\\"+sourcePath.getFileName().toString());
CopyOption options = StandardCopyOption.REPLACE_EXISTING;
Files.copy(sourcePath, targetPath, options);
} else {
logger.info("write path to " + sourcePath.toString());
BufferedImage image = PictureCaption.convert(sourcePath.toString(), sourcePath.toString(), left, top, fontSize);
String filename = sourcePath.getFileName().toString();
filename = filename.toLowerCase().replace("jpg", "png");
File outputfile = new File(config.getDesktopFolder()+"\\"+filename);
ImageIO.write(image, "png", outputfile);
}
}
示例7: retrieveIfNeeded
import java.nio.file.CopyOption; //导入依赖的package包/类
default boolean retrieveIfNeeded( FTPFile remote, Path target, CopyOption... options )
throws IOException
{
if( remote != null && target != null && isPathRetrievable( target, remote ) ) {
try( InputStream is = retrieveFileStream( remote ) ) {
if( is == null ) {
throw new FileNotFoundException( target.toString() );
}
Files.copy( is, target, options );
}
finally {
completePendingCommand();
}
}
return Files.exists( target, LinkOption.NOFOLLOW_LINKS ) && Files.isRegularFile( target, LinkOption.NOFOLLOW_LINKS );
}
示例8: extract
import java.nio.file.CopyOption; //导入依赖的package包/类
public boolean extract(String srcZip, String targetPath, OnCondition listener) throws IOException {
ZipFile in = new ZipFile(srcZip);
Enumeration<? extends ZipEntry> entries = in.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
String zipEntryPath = entry.getName();
if (listener.onCondition(zipEntryPath)) {
zipEntryPath = "/" + zipEntryPath;
File resFile = Paths.get(targetPath, zipEntryPath).toFile();
if (entry.isDirectory()) {
if (!resFile.exists() && !resFile.mkdir()) {
// Log.t(TAG, "can not make new Res Directory : " + resFile.getAbsolutePath());
return false;
}
} else {
Files.copy(in.getInputStream(entry),
resFile.toPath(), new CopyOption[] { StandardCopyOption.REPLACE_EXISTING });
}
}
}
in.close();
return true;
}
示例9: copyRecursively
import java.nio.file.CopyOption; //导入依赖的package包/类
public static void copyRecursively(final Path source,
final Path destination, final CopyOption... copyOptions)
throws IOException {
final Set<CopyOption> copyOptionsSet = new HashSet<>(
Arrays.asList(copyOptions));
if (!isDirectory(source))
throw new FileNotFoundException("Not a directory: " + source);
if (isDirectory(destination)
&& !copyOptionsSet.contains(REPLACE_EXISTING))
throw new FileAlreadyExistsException(destination.toString());
Path destinationParent = destination.getParent();
if (destinationParent != null && !isDirectory(destinationParent))
throw new FileNotFoundException("Not a directory: "
+ destinationParent);
RecursiveCopyFileVisitor visitor = new RecursiveCopyFileVisitor(
destination, copyOptionsSet, source);
Set<FileVisitOption> walkOptions = noneOf(FileVisitOption.class);
if (!copyOptionsSet.contains(NOFOLLOW_LINKS))
walkOptions = EnumSet.of(FOLLOW_LINKS);
walkFileTree(source, walkOptions, MAX_VALUE, visitor);
}
示例10: RecursiveCopyFileVisitor
import java.nio.file.CopyOption; //导入依赖的package包/类
RecursiveCopyFileVisitor(Path destination, Set<CopyOption> copyOptionsSet,
Path source) {
this.destination = destination;
this.source = source;
this.copyOptionsSet = new HashSet<>(copyOptionsSet);
HashSet<Object> linkOptionsSet = new HashSet<>();
for (CopyOption option : copyOptionsSet) {
copyOptionsSet.add(option);
if (option instanceof LinkOption)
linkOptionsSet.add((LinkOption) option);
}
this.linkOptions = linkOptionsSet
.toArray(new LinkOption[(linkOptionsSet.size())]);
this.ignoreErrors = copyOptionsSet.contains(IGNORE_ERRORS);
/*
* To avoid UnsupporteOperationException from native java.nio operations
* we strip our own options out
*/
copyOptionsSet.removeAll(EnumSet.allOf(RecursiveCopyOption.class));
copyOptions = copyOptionsSet.toArray(new CopyOption[(copyOptionsSet
.size())]);
}
示例11: move
import java.nio.file.CopyOption; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public void move(Path source, Path target, CopyOption... options) throws IOException {
source = ((TestPath) source).unwrap();
target = ((TestPath) target).unwrap();
checkIfRemoved(source);
Path sourceParent = source.getParent();
if (sourceParent != null) {
checkIfRemoved(sourceParent);
checkPermissions(sourceParent, true, AccessMode.WRITE);
}
Path targetParent = target.getParent();
if (targetParent != null) {
checkIfRemoved(targetParent);
checkPermissions(targetParent, true, AccessMode.WRITE);
}
provider.move(source, target, options);
}
示例12: move
import java.nio.file.CopyOption; //导入依赖的package包/类
@Override
public void move(
Path srcpath,
SecureDirectoryStream<Path> targetdir,
Path targetpath) throws IOException {
EphemeralFsPath efsSrcPath = cast(srcpath);
EphemeralFsPath efsTargetPath = cast(targetpath);
EphemeralFsSecureDirectoryStream efsTargetDir = cast(targetdir);
synchronized(efsSrcPath.fs.fsLock) {
EphemeralFsPath actualSrcPath = translate(efsSrcPath);
EphemeralFsPath actualTargetPath = efsTargetDir.translate(efsTargetPath);
efsSrcPath.fs.move(actualSrcPath, actualTargetPath, new CopyOption[] {StandardCopyOption.ATOMIC_MOVE});
}
}
示例13: copyFile
import java.nio.file.CopyOption; //导入依赖的package包/类
public void copyFile(boolean deleteSourceFile, byte[] srcPath,
byte[] targetPath, CopyOption... options) throws IOException {
List<CopyOption> opts = Arrays.asList(options);
if (!exists(srcPath)) {
throw new FileNotFoundException();
}
if (exists(targetPath)
&& !opts.contains(StandardCopyOption.REPLACE_EXISTING)) {
System.out.println("Its me");
throw new FileAlreadyExistsException(new String(targetPath));
}
beginWrite();
try {
TarEntry srcEntry = getTarEntryFromPath(srcPath);
byte[] data = entriesToData.get(srcEntry);
if (exists(targetPath)) {
deleteFile(targetPath, true);
}
TarEntry targetEntry = new TarEntry(TarHeader.createHeader(
new String(targetPath), data.length, srcEntry.getModTime()
.getTime(), srcEntry.isDirectory()));
addEntry(targetEntry, data);
} finally {
endWrite();
}
}
示例14: copyFile
import java.nio.file.CopyOption; //导入依赖的package包/类
/**
* Copy source file to target location. If {@code prompt} is true then
* prompt user to overwrite target if it exists. The {@code preserve}
* parameter determines if file attributes should be copied/preserved.
*/
private static void copyFile(Path source, Path target, boolean prompt, boolean preserve) {
CopyOption[] options = (preserve) ? new CopyOption[] { COPY_ATTRIBUTES, REPLACE_EXISTING } : new CopyOption[] { REPLACE_EXISTING };
try {
Files.createDirectories(target.getParent());
} catch (IOException e) {
e.printStackTrace();
}
try {
Files.copy(source, target, options);
} catch (IOException x) {
log.error(String.format("Unable to copy: %s: %n", source), x);
}
}
示例15: move
import java.nio.file.CopyOption; //导入依赖的package包/类
@Override
public void move(Path srcPath, SecureDirectoryStream<Path> targetDir, Path targetPath)
throws IOException {
checkOpen();
JimfsPath checkedSrcPath = checkPath(srcPath);
JimfsPath checkedTargetPath = checkPath(targetPath);
if (!(targetDir instanceof JimfsSecureDirectoryStream)) {
throw new ProviderMismatchException(
"targetDir isn't a secure directory stream associated with this file system");
}
JimfsSecureDirectoryStream checkedTargetDir = (JimfsSecureDirectoryStream) targetDir;
view.copy(
checkedSrcPath,
checkedTargetDir.view,
checkedTargetPath,
ImmutableSet.<CopyOption>of(),
true);
}