private static String readLinkImpl(long handle) throws IOException {
  int size=MAXIMUM_REPARSE_DATA_BUFFER_SIZE;
  NativeBuffer buffer=NativeBuffers.getNativeBuffer(size);
  try {
    try {
      DeviceIoControlGetReparsePoint(handle,buffer.address(),size);
    }
 catch (    WindowsException x) {
      if (x.lastError() == ERROR_NOT_A_REPARSE_POINT)       throw new NotLinkException(null,null,x.errorString());
      x.rethrowAsIOException((String)null);
    }
    final short OFFSETOF_REPARSETAG=0;
    final short OFFSETOF_PATHOFFSET=8;
    final short OFFSETOF_PATHLENGTH=10;
    final short OFFSETOF_PATHBUFFER=16 + 4;
    int tag=(int)unsafe.getLong(buffer.address() + OFFSETOF_REPARSETAG);
    if (tag != IO_REPARSE_TAG_SYMLINK) {
      throw new NotLinkException(null,null,"Reparse point is not a symbolic link");
    }
    short nameOffset=unsafe.getShort(buffer.address() + OFFSETOF_PATHOFFSET);
    short nameLengthInBytes=unsafe.getShort(buffer.address() + OFFSETOF_PATHLENGTH);
    if ((nameLengthInBytes % 2) != 0)     throw new FileSystemException(null,null,"Symbolic link corrupted");
    char[] name=new char[nameLengthInBytes / 2];
    unsafe.copyMemory(null,buffer.address() + OFFSETOF_PATHBUFFER + nameOffset,name,Unsafe.ARRAY_CHAR_BASE_OFFSET,nameLengthInBytes);
    String target=stripPrefix(new String(name));
    if (target.length() == 0) {
      throw new IOException("Symbolic link target is invalid");
    }
    return target;
  }
  finally {
    buffer.release();
  }
}

private static String readLinkImpl ( long handle ) throws IOException { int size = MAXIMUM_REPARSE_DATA_BUFFER_SIZE ; NativeBuffer buffer = NativeBuffers . getNativeBuffer ( size ) ; try { try { DeviceIoControlGetReparsePoint ( handle , buffer . address ( ) , size ) ; } catch ( WindowsException x ) { if ( x . lastError ( ) == ERROR_NOT_A_REPARSE_POINT ) throw new NotLinkException ( null , null , x . errorString ( ) ) ; x . rethrowAsIOException ( ( String ) null ) ; } final short OFFSETOF_REPARSETAG = 0 ; final short OFFSETOF_PATHOFFSET = 8 ; final short OFFSETOF_PATHLENGTH = 10 ; final short OFFSETOF_PATHBUFFER = 16 + 4 ; int tag = ( int ) unsafe . getLong ( buffer . address ( ) + OFFSETOF_REPARSETAG ) ; if ( tag != IO_REPARSE_TAG_SYMLINK ) { throw new NotLinkException ( null , null , "Reparse point is not a symbolic link" ) ; } short nameOffset = unsafe . getShort ( buffer . address ( ) + OFFSETOF_PATHOFFSET ) ; short nameLengthInBytes = unsafe . getShort ( buffer . address ( ) + OFFSETOF_PATHLENGTH ) ; if ( ( nameLengthInBytes % 2 ) != 0 ) throw new FileSystemException ( null , null , "Symbolic link corrupted" ) ; char [ ] name = new char [ nameLengthInBytes / 2 ] ; unsafe . copyMemory ( null , buffer . address ( ) + OFFSETOF_PATHBUFFER + nameOffset , name , Unsafe . ARRAY_CHAR_BASE_OFFSET , nameLengthInBytes ) ; String target = stripPrefix ( new String ( name ) ) ; if ( target . length ( ) == 0 ) { throw new IOException ( "Symbolic link target is invalid" ) ; } return target ; } finally { buffer . release ( ) ; } }
returns target of a symbolic link given the handle of an open file ( that should be a link ) .
