@Throws(IOException::class) fun isPotentialValidLink(file: File): Boolean { var isPotentiallyValid: Boolean FileInputStream(file).use { fis -> val minimumLength = 0x64 isPotentiallyValid = file.isFile() && file.getName().toLowerCase() .endsWith(".lnk") && fis.available() >= minimumLength && isMagicPresent( com.sun.org.apache.xml.internal.security.utils.XMLUtils.getBytes( fis, 32 ) ) } return isPotentiallyValid }
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 .