FilesystemMetadataLoader implements MetadataLoader { public Map<String, String> loadMetadata(File file) { Map<String, String> fileSystemPropertyMap = new HashMap<String, String>(); String os = System.getProperty("os.name"); logger.debug("OS {}", os); boolean windows = os.contains("Windows"); try { if (windows) { String filePath = file.getAbsolutePath(); URL programURL = this.getClass().getClassLoader().getResource("extractWindowsFileSystemProperties.exe"); URI programURI = programURL.toURI(); String programPath = new File(programURI).getAbsolutePath(); String[] commandArray = { programPath, filePath }; java.lang.Process p = Runtime.getRuntime().exec(commandArray); StringBuffer errorBuffer = new StringBuffer(); try { String output = StreamGobbler.executeCommand(p); String[] lines = output.split("\n"); logger.debug("ExtractWindowsFileSystemProperties execution ok"); if (lines.length > 0) { fileSystemPropertyMap.put(fsPropCreator, lines[0]); } if (lines.length > 1) { fileSystemPropertyMap.put(fsPropCreationDate, lines[1]); } if (lines.length > 2) { fileSystemPropertyMap.put(fsPropModifyDate, lines[2]); } } catch (ProcessErrorException e) { logger.error("Error while running ExtractWindowsFileSystemProperties {}", errorBuffer.toString()); } } else { String[] commandArray = { "/bin/ls", "-l", file.getAbsolutePath() }; java.lang.Process p = Runtime.getRuntime().exec(commandArray); try { String output = StreamGobbler.executeCommand(p); String[] lines = output.split("\n"); if (lines.length > 0) { String[] lineSplit = lines[0].split(" "); fileSystemPropertyMap.put(fsPropCreator, lineSplit[2]); } } catch (ProcessErrorException e) { logger.error("Error while running /bin/ls {}", e.getMessage()); } Date dateLastModified = new Date(file.lastModified()); String lastModifyDate = Util.ISO8601format(dateLastModified); fileSystemPropertyMap.put(fsPropCreationDate, lastModifyDate); fileSystemPropertyMap.put(fsPropModifyDate, lastModifyDate); } } catch (IOException e) { logger.error("", e); } catch (URISyntaxException e) { logger.error("", e); } return fileSystemPropertyMap; }  boolean hasMetadata(File file); Map<String, String> loadMetadata(File file);  }
@Test public final void testLoadMetadata() { Map<String, String> metadata = metadataLoader.loadMetadata(file); assertEquals(3, metadata.size()); assertNotNull(metadata.get(FilesystemMetadataLoader.fsPropCreationDate)); assertNotNull(metadata.get(FilesystemMetadataLoader.fsPropCreator)); assertNotNull(metadata.get(FilesystemMetadataLoader.fsPropModifyDate)); }