Example usage for java.io FileSystem getSeparator

List of usage examples for java.io FileSystem getSeparator

Introduction

In this page you can find the example usage for java.io FileSystem getSeparator.

Prototype

public abstract char getSeparator();

Source Link

Document

Return the local filesystem's name-separator character.

Usage

From source file:org.jbpm.designer.repository.vfs.VFSRepository.java

public boolean copyDirectory(String sourceDirectory, String location) {
    sourceDirectory = UriUtils.encode(sourceDirectory);
    location = UriUtils.encode(location);
    if (!directoryExists(sourceDirectory)) {
        throw new IllegalArgumentException("Directory does not exist " + sourceDirectory);
    }//from  www.j  a va 2s.  c  o  m
    try {
        final FileSystem fileSystem = descriptor.getFileSystem();
        final Path sourcePath = fileSystem.provider()
                .getPath(URI.create(descriptor.getStringRepositoryRoot() + sourceDirectory));
        if (!Files.isDirectory(sourcePath)) {
            return false;
        }
        final String destinationPathRoot = descriptor.getStringRepositoryRoot() + location
                + fileSystem.getSeparator() + sourcePath.getFileName().toString();
        Files.walkFileTree(sourcePath, new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
                Path destinationPath = fileSystem.provider().getPath(URI
                        .create(destinationPathRoot + fileSystem.getSeparator() + sourcePath.relativize(dir)));
                fileSystem.provider().createDirectory(destinationPath);

                return FileVisitResult.CONTINUE;
            }

            @Override
            public FileVisitResult visitFile(Path currentFile, BasicFileAttributes basicFileAttributes)
                    throws IOException {

                if (!currentFile.endsWith(".gitignore")) {
                    Path destinationPath = fileSystem.provider().getPath(URI.create(destinationPathRoot
                            + fileSystem.getSeparator() + sourcePath.relativize(currentFile)));
                    createIfNotExists(destinationPath);

                    fileSystem.provider().copy(currentFile, destinationPath, null);
                }
                return FileVisitResult.CONTINUE;
            }

        });

        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:org.jbpm.designer.repository.vfs.VFSRepository.java

public boolean moveDirectory(String sourceDirectory, String location, String name) {
    sourceDirectory = UriUtils.encode(sourceDirectory);
    location = UriUtils.encode(location);
    if (!directoryExists(sourceDirectory)) {
        throw new IllegalArgumentException("Directory does not exist " + sourceDirectory);
    }/*  w  w  w  . j av  a  2s . c  o m*/
    try {
        final FileSystem fileSystem = descriptor.getFileSystem();
        final Path sourcePath = fileSystem.provider()
                .getPath(URI.create(descriptor.getStringRepositoryRoot() + sourceDirectory));
        if (!Files.isDirectory(sourcePath)) {
            return false;
        }
        if (name == null) {
            name = sourcePath.getFileName().toString();
        }
        final String destinationPathRoot = descriptor.getStringRepositoryRoot() + location
                + fileSystem.getSeparator() + name;

        Files.walkFileTree(sourcePath, new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult visitFile(Path currentFile, BasicFileAttributes basicFileAttributes)
                    throws IOException {
                Path destinationPath = fileSystem.provider().getPath(URI.create(
                        destinationPathRoot + fileSystem.getSeparator() + sourcePath.relativize(currentFile)));
                createIfNotExists(destinationPath);
                fileSystem.provider().move(currentFile, destinationPath, StandardCopyOption.REPLACE_EXISTING);

                return FileVisitResult.CONTINUE;
            }

            @Override
            public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException {
                if (e == null) {
                    try {
                        Path destinationPath = fileSystem.provider().getPath(URI.create(
                                destinationPathRoot + fileSystem.getSeparator() + sourcePath.relativize(dir)));
                        createIfNotExists(destinationPath);
                        fileSystem.provider().move(dir, destinationPath, StandardCopyOption.REPLACE_EXISTING);
                    } catch (Exception e1) {
                        fileSystem.provider().deleteIfExists(dir);
                    }
                    return FileVisitResult.CONTINUE;
                } else {
                    // directory iteration failed
                    throw e;
                }
            }

        });

        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:org.jbpm.designer.repository.vfs.VFSRepository.java

public boolean copyAsset(String uniqueId, String location) {
    location = UriUtils.encode(location);
    String decodedUniqueId = decodeUniqueId(uniqueId);
    if (!assetExists(decodedUniqueId)) {
        throw new IllegalArgumentException("Asset does not exist");
    }/*  w w w  .  j  a  va2  s. c  om*/
    try {
        FileSystem fileSystem = descriptor.getFileSystem();
        Path sourcePath = fileSystem.provider().getPath(URI.create(decodedUniqueId));
        Path destinationPath = fileSystem.provider().getPath(URI.create(descriptor.getStringRepositoryRoot()
                + location + fileSystem.getSeparator() + sourcePath.getFileName().toString()));
        createIfNotExists(destinationPath);

        CommentedOption commentedOption = new CommentedOption(getIdentity(),
                "Copied asset " + sourcePath.getFileName() + " into " + location);

        fileSystem.provider().copy(sourcePath, destinationPath, StandardCopyOption.REPLACE_EXISTING,
                commentedOption);

        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:org.jbpm.designer.repository.vfs.VFSRepository.java

public boolean moveAsset(String uniqueId, String location, String name) {
    name = UriUtils.encode(name);//from w  w w .j  av a 2s  . co m
    location = UriUtils.encode(location);
    String decodedUniqueId = decodeUniqueId(uniqueId);
    if (!assetExists(decodedUniqueId)) {
        throw new IllegalArgumentException("Asset does not exist");
    }
    try {
        FileSystem fileSystem = descriptor.getFileSystem();
        Path sourcePath = fileSystem.provider().getPath(URI.create(decodedUniqueId));
        if (name == null) {
            name = sourcePath.getFileName().toString();
        }

        Path destinationPath = fileSystem.provider().getPath(
                URI.create(descriptor.getStringRepositoryRoot() + location + fileSystem.getSeparator() + name));
        createIfNotExists(destinationPath);
        CommentedOption commentedOption = new CommentedOption(getIdentity(),
                "Moved asset " + sourcePath.getFileName() + " into " + location);
        fileSystem.provider().move(sourcePath, destinationPath, StandardCopyOption.REPLACE_EXISTING,
                commentedOption);

        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}