Class WindowsShortcut


  • public class WindowsShortcut
    extends Object
    Represents a Windows shortcut (typically visible to Java only as a '.lnk' file). Retrieved 2011-09-23 from http://stackoverflow.com/questions/309495/windows-shortcut-lnk-parser-in-java/672775#672775 Written by: (the stack overflow users, obviously!) Apache Commons VFS dependency removed by crysxd (why were we using that!?) https://github.com/crysxd Headerified, refactored and commented by Code Bling http://stackoverflow.com/users/675721/code-bling Network file support added by Stefan Cordes http://stackoverflow.com/users/81330/stefan-cordes Adapted by Sam Brightman http://stackoverflow.com/users/2492/sam-brightman Based on information in 'The Windows Shortcut File Format' by Jesse Hager <jessehager@iname.com> And somewhat based on code from the book 'Swing Hacks: Tips and Tools for Killer GUIs' by Joshua Marinacci and Chris Adamson ISBN: 0-596-00907-0 http://www.oreilly.com/catalog/swinghks/
    Since:
    13692
    • Method Detail

      • isPotentialValidLink

        public static boolean isPotentialValidLink​(File file)
                                            throws IOException
        Provides a quick test to see if this could be a valid link ! If you try to instantiate a new WindowShortcut and the link is not valid, Exceptions may be thrown and Exceptions are extremely slow to generate, therefore any code needing to loop through several files should first check this.
        Parameters:
        file - the potential link
        Returns:
        true if may be a link, false otherwise
        Throws:
        IOException - if an IOException is thrown while reading from the file
      • getRealFilename

        public String getRealFilename()
        Returns the name of the filesystem object pointed to by this shortcut.
        Returns:
        the name of the filesystem object pointed to by this shortcut
      • isLocal

        public boolean isLocal()
        Tests if the shortcut points to a local resource.
        Returns:
        true if the 'local' bit is set in this shortcut, false otherwise
      • isDirectory

        public boolean isDirectory()
        Tests if the shortcut points to a directory.
        Returns:
        true if the 'directory' bit is set in this shortcut, false otherwise
      • getBytes

        private static byte[] getBytes​(InputStream in)
                                throws IOException
        Gets all the bytes from an InputStream
        Parameters:
        in - the InputStream from which to read bytes
        Returns:
        array of all the bytes contained in 'in'
        Throws:
        IOException - if an IOException is encountered while reading the data from the InputStream
      • getBytes

        private static byte[] getBytes​(InputStream in,
                                       Integer max)
                                throws IOException
        Gets up to max bytes from an InputStream
        Parameters:
        in - the InputStream from which to read bytes
        max - maximum number of bytes to read
        Returns:
        array of all the bytes contained in 'in'
        Throws:
        IOException - if an IOException is encountered while reading the data from the InputStream
      • isMagicPresent

        private static boolean isMagicPresent​(byte[] link)
      • parseLink

        private void parseLink​(byte[] link)
                        throws ParseException
        Gobbles up link data by parsing it and storing info in member fields
        Parameters:
        link - all the bytes from the .lnk file
        Throws:
        ParseException - if a parsing error occurs
      • bytesToWord

        private static int bytesToWord​(byte[] bytes,
                                       int off)
      • bytesToDword

        private static int bytesToDword​(byte[] bytes,
                                        int off)