< prev index next >

src/java.base/windows/classes/sun/nio/fs/WindowsLinkSupport.java

Print this page
rev 52979 : 8215281: Use String.isEmpty() when applicable in java.base
Reviewed-by: TBD


 312 
 313             int tag = (int)unsafe.getLong(buffer.address() + OFFSETOF_REPARSETAG);
 314             if (tag != IO_REPARSE_TAG_SYMLINK) {
 315                 // FIXME: exception doesn't have file name
 316                 throw new NotLinkException(null, null, "Reparse point is not a symbolic link");
 317             }
 318 
 319             // get offset and length of target
 320             short nameOffset = unsafe.getShort(buffer.address() + OFFSETOF_PATHOFFSET);
 321             short nameLengthInBytes = unsafe.getShort(buffer.address() + OFFSETOF_PATHLENGTH);
 322             if ((nameLengthInBytes % 2) != 0)
 323                 throw new FileSystemException(null, null, "Symbolic link corrupted");
 324 
 325             // copy into char array
 326             char[] name = new char[nameLengthInBytes/2];
 327             unsafe.copyMemory(null, buffer.address() + OFFSETOF_PATHBUFFER + nameOffset,
 328                 name, Unsafe.ARRAY_CHAR_BASE_OFFSET, nameLengthInBytes);
 329 
 330             // remove special prefix
 331             String target = stripPrefix(new String(name));
 332             if (target.length() == 0) {
 333                 throw new IOException("Symbolic link target is invalid");
 334             }
 335             return target;
 336         } finally {
 337             buffer.release();
 338         }
 339     }
 340 
 341     /**
 342      * Resolve all symbolic-links in a given absolute and normalized path
 343      */
 344     private static WindowsPath resolveAllLinks(WindowsPath path)
 345         throws IOException
 346     {
 347         assert path.isAbsolute();
 348         WindowsFileSystem fs = path.getFileSystem();
 349 
 350         // iterate through each name element of the path, resolving links as
 351         // we go.
 352         int linkCount = 0;




 312 
 313             int tag = (int)unsafe.getLong(buffer.address() + OFFSETOF_REPARSETAG);
 314             if (tag != IO_REPARSE_TAG_SYMLINK) {
 315                 // FIXME: exception doesn't have file name
 316                 throw new NotLinkException(null, null, "Reparse point is not a symbolic link");
 317             }
 318 
 319             // get offset and length of target
 320             short nameOffset = unsafe.getShort(buffer.address() + OFFSETOF_PATHOFFSET);
 321             short nameLengthInBytes = unsafe.getShort(buffer.address() + OFFSETOF_PATHLENGTH);
 322             if ((nameLengthInBytes % 2) != 0)
 323                 throw new FileSystemException(null, null, "Symbolic link corrupted");
 324 
 325             // copy into char array
 326             char[] name = new char[nameLengthInBytes/2];
 327             unsafe.copyMemory(null, buffer.address() + OFFSETOF_PATHBUFFER + nameOffset,
 328                 name, Unsafe.ARRAY_CHAR_BASE_OFFSET, nameLengthInBytes);
 329 
 330             // remove special prefix
 331             String target = stripPrefix(new String(name));
 332             if (target.isEmpty()) {
 333                 throw new IOException("Symbolic link target is invalid");
 334             }
 335             return target;
 336         } finally {
 337             buffer.release();
 338         }
 339     }
 340 
 341     /**
 342      * Resolve all symbolic-links in a given absolute and normalized path
 343      */
 344     private static WindowsPath resolveAllLinks(WindowsPath path)
 345         throws IOException
 346     {
 347         assert path.isAbsolute();
 348         WindowsFileSystem fs = path.getFileSystem();
 349 
 350         // iterate through each name element of the path, resolving links as
 351         // we go.
 352         int linkCount = 0;


< prev index next >