< prev index next >
src/java.base/unix/classes/sun/nio/fs/UnixPath.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 23,42 ****
* questions.
*/
package sun.nio.fs;
! import java.nio.*;
! import java.nio.file.*;
! import java.nio.charset.*;
! import java.io.*;
! import java.net.URI;
! import java.util.*;
import java.lang.ref.SoftReference;
!
! import static sun.nio.fs.UnixNativeDispatcher.*;
! import static sun.nio.fs.UnixConstants.*;
/**
* Solaris/Linux implementation of java.nio.file.Path
*/
--- 23,57 ----
* questions.
*/
package sun.nio.fs;
! import java.io.IOException;
import java.lang.ref.SoftReference;
! import java.net.URI;
! import java.nio.ByteBuffer;
! import java.nio.CharBuffer;
! import java.nio.charset.CharsetEncoder;
! import java.nio.charset.CoderResult;
! import java.nio.charset.CodingErrorAction;
! import java.nio.file.InvalidPathException;
! import java.nio.file.LinkOption;
! import java.nio.file.ProviderMismatchException;
! import java.nio.file.Path;
! import java.nio.file.WatchEvent;
! import java.nio.file.WatchKey;
! import java.nio.file.WatchService;
! import java.util.Arrays;
! import java.util.Objects;
! import java.util.stream.Stream;
!
! import static sun.nio.fs.UnixConstants.EINVAL;
! import static sun.nio.fs.UnixConstants.ELOOP;
! import static sun.nio.fs.UnixConstants.O_NOFOLLOW;
! import static sun.nio.fs.UnixConstants.O_RDONLY;
! import static sun.nio.fs.UnixNativeDispatcher.open;
! import static sun.nio.fs.UnixNativeDispatcher.realpath;
/**
* Solaris/Linux implementation of java.nio.file.Path
*/
*** 320,329 ****
--- 335,367 ----
System.arraycopy(path, 0, result, 0, len);
return new UnixPath(getFileSystem(), result);
}
@Override
+ public String getExtension() {
+ final int length = path.length;
+
+ int lastDotIndex = -1;
+ for (int i = length - 1; i >= 0; i--) {
+ byte b = path[i];
+ if (b == '.') {
+ lastDotIndex = i;
+ break;
+ } else if (b == '/') {
+ break;
+ }
+ }
+
+ if (lastDotIndex < 0 || lastDotIndex == length - 1) {
+ return "";
+ }
+
+ int offset = lastDotIndex + 1;
+ return Util.toString(path, offset, length - offset);
+ }
+
+ @Override
public int getNameCount() {
initOffsets();
return offsets.length;
}
< prev index next >