private Path emptyPath() { return newPath( fs, "", host, isRealPath, true ); }
@Override public Path normalize() { if ( isNormalized ) { return this; } return newPath( fs, FilenameUtils.normalize( new String( path ), !usesWindowsFormat ), host, isRealPath, true ); }
@Override public Path getName( int index ) throws IllegalArgumentException { if ( isRoot && index > 0 ) { throw new IllegalArgumentException(); } if ( index < 0 ) { throw new IllegalArgumentException(); } if ( index >= offsets.size() ) { throw new IllegalArgumentException(); } return newPath( fs, substring( index ), host, isRealPath, false ); }
@Override public Path subpath( int beginIndex, int endIndex ) throws IllegalArgumentException { if ( beginIndex < 0 ) { throw new IllegalArgumentException(); } if ( beginIndex >= offsets.size() ) { throw new IllegalArgumentException(); } if ( endIndex > offsets.size() ) { throw new IllegalArgumentException(); } if ( beginIndex >= endIndex ) { throw new IllegalArgumentException(); } return newPath( fs, substring( beginIndex, endIndex - 1 ), host, isRealPath, false ); }
@Override public Path resolve( final Path other ) { checkNotNull( "other", other ); if ( other.isAbsolute() ) { return other; } if ( other.toString().trim().length() == 0 ) { return this; } final StringBuilder sb = new StringBuilder(); sb.append( new String( path ) ); if ( path[ path.length - 1 ] != getSeparator() ) { sb.append( getSeparator() ); } sb.append( other.toString() ); return newPath( fs, sb.toString(), host, isRealPath, false ); }
@Override public Path resolve( final String other ) throws InvalidPathException { checkNotNull( "other", other ); return resolve( newPath( fs, other, host, isRealPath, false ) ); }
@Override public Path toRealPath( final LinkOption... options ) throws IOException, SecurityException { if ( isRealPath ) { return this; } return newPath( fs, FilenameUtils.normalize( toString(), !usesWindowsFormat ), host, true, true ); }
@Override public Path resolveSibling( final String other ) throws InvalidPathException { checkNotNull( "other", other ); return resolveSibling( newPath( fs, other, host, isRealPath, false ) ); }
@Override public Path toAbsolutePath() throws IOException, SecurityException { if ( isAbsolute() ) { return this; } if ( host.isEmpty() ) { return newPath( fs, FilenameUtils.normalize( defaultDirectory() + toString(), !usesWindowsFormat ), host, isRealPath, true ); } return newPath( fs, defaultDirectory() + toString( false ), host, isRealPath, true ); }
@Override public Path getParent() { if ( getNameCount() <= 0 ) { return null; } if ( getNameCount() == 1 ) { return getRoot(); } return newPath( fs, substring( -1, getNameCount() - 2 ), host, isRealPath, isNormalized ); }
return newPath( fs, sb.toString(), host, isRealPath, false );