Example usage for java.nio.file FileSystem getSeparator

List of usage examples for java.nio.file FileSystem getSeparator

Introduction

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

Prototype

public abstract String getSeparator();

Source Link

Document

Returns the name separator, represented as a string.

Usage

From source file:Main.java

public static void main(String[] args) throws IOException {
    FileSystem fileSystem = FileSystems.getDefault();
    System.out.println(fileSystem.getSeparator());
}

From source file:Main.java

public static void main(String[] args) {
    FileSystem fs = FileSystems.getDefault();

    System.out.println("Read-only file system: " + fs.isReadOnly());
    System.out.println("File name separator: " + fs.getSeparator());

    for (FileStore store : fs.getFileStores()) {
        printDetails(store);//from  ww  w  .  j  av a  2  s . co  m
    }
    for (Path root : fs.getRootDirectories()) {
        System.out.println(root);
    }
}

From source file:com.spotify.docker.client.CompressedDirectory.java

@VisibleForTesting
static PathMatcher goPathMatcher(FileSystem fs, String pattern) {
    // Supposed to work the same way as Go's path.filepath.match.Match:
    // http://golang.org/src/path/filepath/match.go#L34

    final String notSeparatorPattern = getNotSeparatorPattern(fs.getSeparator());

    final String starPattern = String.format("%s*", notSeparatorPattern);

    final StringBuilder patternBuilder = new StringBuilder();

    boolean inCharRange = false;
    boolean inEscape = false;

    // This is of course hugely inefficient, but it passes most of the test suite, TDD ftw...
    for (int i = 0; i < pattern.length(); i++) {
        final char c = pattern.charAt(i);
        if (inCharRange) {
            if (inEscape) {
                patternBuilder.append(c);
                inEscape = false;//from   w w w.  j  ava  2s . c o  m
            } else {
                switch (c) {
                case '\\':
                    patternBuilder.append('\\');
                    inEscape = true;
                    break;
                case ']':
                    patternBuilder.append(']');
                    inCharRange = false;
                    break;
                default:
                    patternBuilder.append(c);
                }
            }
        } else {
            if (inEscape) {
                patternBuilder.append(Pattern.quote(Character.toString(c)));
                inEscape = false;
            } else {
                switch (c) {
                case '*':
                    patternBuilder.append(starPattern);
                    break;
                case '?':
                    patternBuilder.append(notSeparatorPattern);
                    break;
                case '[':
                    patternBuilder.append("[");
                    inCharRange = true;
                    break;
                case '\\':
                    inEscape = true;
                    break;
                default:
                    patternBuilder.append(Pattern.quote(Character.toString(c)));
                }
            }
        }
    }

    return fs.getPathMatcher("regex:" + patternBuilder.toString());
}

From source file:com.liferay.sync.engine.service.SyncAccountService.java

public static SyncAccount setFilePathName(long syncAccountId, String targetFilePathName) {

    // Sync account

    SyncAccount syncAccount = fetchSyncAccount(syncAccountId);

    String sourceFilePathName = syncAccount.getFilePathName();

    syncAccount.setFilePathName(targetFilePathName);

    update(syncAccount);/*from   ww  w. j  a va 2s.  c o  m*/

    // Sync file

    SyncFile syncFile = SyncFileService.fetchSyncFile(sourceFilePathName);

    syncFile.setFilePathName(targetFilePathName);

    SyncFileService.update(syncFile);

    // Sync files

    if (syncFile.isFolder()) {
        SyncFileService.renameSyncFiles(sourceFilePathName, targetFilePathName);
    }

    // Sync sites

    FileSystem fileSystem = FileSystems.getDefault();

    List<SyncSite> syncSites = SyncSiteService.findSyncSites(syncAccountId);

    for (SyncSite syncSite : syncSites) {
        String syncSiteFilePathName = syncSite.getFilePathName();

        syncSiteFilePathName = StringUtils.replaceOnce(syncSiteFilePathName,
                sourceFilePathName + fileSystem.getSeparator(), targetFilePathName + fileSystem.getSeparator());

        syncSite.setFilePathName(syncSiteFilePathName);

        SyncSiteService.update(syncSite);
    }

    return syncAccount;
}

From source file:com.liferay.sync.engine.util.FileUtilTest.java

@Test
public void testGetFilePathName() {
    FileSystem fileSystem = FileSystems.getDefault();

    Assert.assertEquals("test" + fileSystem.getSeparator() + "test", FileUtil.getFilePathName("test", "test"));
}

From source file:com.liferay.sync.engine.util.FileUtilTest.java

@Test
public void testGetFilePath() {
    FileSystem fileSystem = FileSystems.getDefault();

    Path filePath = FileUtil.getFilePath("test", "test");

    Assert.assertEquals("test" + fileSystem.getSeparator() + "test", filePath.toString());
}

From source file:com.liferay.sync.engine.service.persistence.SyncFilePersistence.java

public List<SyncFile> findByParentFilePathName(String parentFilePathName) throws SQLException {

    QueryBuilder<SyncFile, Long> queryBuilder = queryBuilder();

    Where<SyncFile, Long> where = queryBuilder.where();

    FileSystem fileSystem = FileSystems.getDefault();

    parentFilePathName = StringUtils.replace(parentFilePathName + fileSystem.getSeparator(), "\\", "\\\\");

    where.like("filePathName", new SelectArg(parentFilePathName + "%"));

    return where.query();
}

From source file:com.liferay.sync.engine.service.persistence.SyncFilePersistence.java

public void updateByParentFilePathName(String parentFilePathName, int state, int uiEvent) throws SQLException {

    UpdateBuilder<SyncFile, Long> updateBuilder = updateBuilder();

    updateBuilder.updateColumnValue("state", state);
    updateBuilder.updateColumnValue("uiEvent", uiEvent);

    Where<SyncFile, Long> where = updateBuilder.where();

    FileSystem fileSystem = FileSystems.getDefault();

    parentFilePathName = StringUtils.replace(parentFilePathName + fileSystem.getSeparator(), "\\", "\\\\");

    where.like("filePathName", new SelectArg(parentFilePathName + "%"));

    updateBuilder.update();/* w ww .j  av a2s  . co  m*/
}

From source file:com.liferay.sync.engine.service.persistence.SyncFilePersistence.java

public List<SyncFile> findByPF_L(String parentFilePathName, long localSyncTime) throws SQLException {

    QueryBuilder<SyncFile, Long> queryBuilder = queryBuilder();

    Where<SyncFile, Long> where = queryBuilder.where();

    FileSystem fileSystem = FileSystems.getDefault();

    parentFilePathName = StringUtils.replace(parentFilePathName + fileSystem.getSeparator(), "\\", "\\\\");

    where.like("filePathName", new SelectArg(parentFilePathName + "%"));

    where.lt("localSyncTime", localSyncTime);
    where.or(where.eq("state", SyncFile.STATE_SYNCED), where.eq("uiEvent", SyncFile.UI_EVENT_UPLOADING));
    where.ne("type", SyncFile.TYPE_SYSTEM);

    where.and(4);//  w  w  w . j a v a  2  s .c  om

    return where.query();
}

From source file:com.liferay.sync.engine.service.persistence.SyncFilePersistence.java

public SyncFile fetchByPF_S_First(String parentFilePathName, int state) throws SQLException {

    QueryBuilder<SyncFile, Long> queryBuilder = queryBuilder();

    queryBuilder.limit(1L);/*from  w ww  . j  a  v a2  s . c  o  m*/

    Where<SyncFile, Long> where = queryBuilder.where();

    FileSystem fileSystem = FileSystems.getDefault();

    parentFilePathName = StringUtils.replace(parentFilePathName + fileSystem.getSeparator(), "\\", "\\\\");

    where.like("filePathName", new SelectArg(parentFilePathName + "%"));

    where.eq("state", state);
    where.ne("uiEvent", SyncFile.UI_EVENT_DELETED_LOCAL);
    where.ne("uiEvent", SyncFile.UI_EVENT_DELETED_REMOTE);
    where.ne("uiEvent", SyncFile.UI_EVENT_TRASHED_LOCAL);
    where.ne("uiEvent", SyncFile.UI_EVENT_TRASHED_REMOTE);

    where.and(6);

    return where.queryForFirst();
}