List of usage examples for org.apache.commons.io FileUtils toFile
public static File toFile(URL url)
URL
to a File
. From source file:net.pms.formats.v2.SubtitleUtilsTest.java
@Test public void testShiftSubtitlesTimingWithUtfConversion_charsetConversion_withoutTimeShift() throws IOException { final DLNAMediaSubtitle inputSubtitles = new DLNAMediaSubtitle(); inputSubtitles.setType(ASS);// w w w . j a va2s . c o m inputSubtitles.setExternalFile(FileUtils.toFile(CLASS.getResource("../../util/russian-cp1251.srt"))); final DLNAMediaSubtitle convertedSubtitles = SubtitleUtils .shiftSubtitlesTimingWithUtfConversion(inputSubtitles, 0); assertThat(convertedSubtitles.isExternalFileUtf8()).isTrue(); }
From source file:net.pms.formats.v2.SubtitleUtilsTest.java
@Test public void testShiftSubtitlesTimingWithUtfConversion_doNotConvertUtf8_withoutTimeShift() throws IOException { final DLNAMediaSubtitle inputSubtitles = new DLNAMediaSubtitle(); inputSubtitles.setType(ASS);/*from ww w . ja v a 2 s . c om*/ inputSubtitles .setExternalFile(FileUtils.toFile(CLASS.getResource("../../util/russian-utf8-without-bom.srt"))); final DLNAMediaSubtitle convertedSubtitles = SubtitleUtils .shiftSubtitlesTimingWithUtfConversion(inputSubtitles, 0); assertThat(convertedSubtitles.getExternalFile()).hasSameContentAs(inputSubtitles.getExternalFile()); }
From source file:net.pms.util.FileUtilTest.java
@Test public void testIsDirectoryReadable() { assertThat(FileUtil.isDirectoryReadable(null)).isFalse(); assertThat(FileUtil.isDirectoryReadable(new File("no such directory"))).isFalse(); assertThat(FileUtil.isDirectoryReadable(FileUtils.toFile(CLASS.getResource("english-utf8-with-bom.srt")))) .isFalse();/*from w ww . j a v a2 s.c o m*/ File file = FileUtils.toFile(CLASS.getResource("english-utf8-with-bom.srt")); assertThat(FileUtil.isFileReadable(file)).isTrue(); File dir = file.getParentFile(); assertThat(dir).isNotNull(); assertThat(dir.isDirectory()).isTrue(); assertThat(FileUtil.isDirectoryReadable(dir)).isTrue(); }
From source file:net.pms.util.FileUtilTest.java
@Test public void testIsDirectoryWritable() { assertThat(FileUtil.isDirectoryWritable(null)).isFalse(); assertThat(FileUtil.isDirectoryWritable(new File("no such directory"))).isFalse(); assertThat(FileUtil.isDirectoryWritable(FileUtils.toFile(CLASS.getResource("english-utf8-with-bom.srt")))) .isFalse();/*from w w w. j a v a 2 s . co m*/ File file = FileUtils.toFile(CLASS.getResource("english-utf8-with-bom.srt")); assertThat(FileUtil.isFileReadable(file)).isTrue(); File dir = file.getParentFile(); assertThat(dir).isNotNull(); assertThat(dir.isDirectory()).isTrue(); assertThat(FileUtil.isDirectoryWritable(dir)).isTrue(); }
From source file:net.pms.dlna.RootFolder.java
/** * Creates, populates and returns a virtual folder mirroring the * contents of the system's iPhoto folder. * Mac OS X only./*from www . j a v a 2 s. c o m*/ * * @return iPhotoVirtualFolder the populated <code>VirtualFolder</code>, or null if one couldn't be created. */ private DLNAResource getiPhotoFolder() { VirtualFolder iPhotoVirtualFolder = null; if (Platform.isMac()) { logger.debug("Adding iPhoto folder"); InputStream inputStream = null; try { // This command will show the XML files for recently opened iPhoto databases Process process = Runtime.getRuntime().exec("defaults read com.apple.iApps iPhotoRecentDatabases"); inputStream = process.getInputStream(); List<String> lines = IOUtils.readLines(inputStream); logger.debug("iPhotoRecentDatabases: {}", lines); if (lines.size() >= 2) { // we want the 2nd line String line = lines.get(1); // Remove extra spaces line = line.trim(); // Remove quotes line = line.substring(1, line.length() - 1); URI uri = new URI(line); URL url = uri.toURL(); File file = FileUtils.toFile(url); logger.debug("Resolved URL to file: {} -> {}", url, file.getAbsolutePath()); // Load the properties XML file. Map<String, Object> iPhotoLib = Plist.load(file); // The list of all photos Map<?, ?> photoList = (Map<?, ?>) iPhotoLib.get("Master Image List"); // The list of events (rolls) List<Map<?, ?>> listOfRolls = (List<Map<?, ?>>) iPhotoLib.get("List of Rolls"); iPhotoVirtualFolder = new VirtualFolder("iPhoto Library", null); for (Map<?, ?> roll : listOfRolls) { Object rollName = roll.get("RollName"); if (rollName != null) { VirtualFolder virtualFolder = new VirtualFolder(rollName.toString(), null); // List of photos in an event (roll) List<?> rollPhotos = (List<?>) roll.get("KeyList"); for (Object photo : rollPhotos) { Map<?, ?> photoProperties = (Map<?, ?>) photoList.get(photo); if (photoProperties != null) { Object imagePath = photoProperties.get("ImagePath"); if (imagePath != null) { RealFile realFile = new RealFile(new File(imagePath.toString())); virtualFolder.addChild(realFile); } } } iPhotoVirtualFolder.addChild(virtualFolder); } } } else { logger.info("iPhoto folder not found"); } } catch (XmlParseException e) { logger.error("Something went wrong with the iPhoto Library scan: ", e); } catch (URISyntaxException e) { logger.error("Something went wrong with the iPhoto Library scan: ", e); } catch (IOException e) { logger.error("Something went wrong with the iPhoto Library scan: ", e); } finally { IOUtils.closeQuietly(inputStream); } } return iPhotoVirtualFolder; }
From source file:com.greenpepper.maven.plugin.SpecificationRunnerMojo.java
private void extractHtmlReportSummary() throws IOException, URISyntaxException { final String path = "html-summary-report"; final File jarFile = new File(getClass().getProtectionDomain().getCodeSource().getLocation().getPath()); forceMkdir(reportsDirectory);//from w w w. ja v a 2 s . co m if (jarFile.isFile()) { // Run with JAR file JarFile jar = new JarFile(jarFile); Enumeration<JarEntry> entries = jar.entries(); //gives ALL entries in jar while (entries.hasMoreElements()) { JarEntry jarEntry = entries.nextElement(); String name = jarEntry.getName(); if (name.startsWith(path)) { //filter according to the path File file = getFile(reportsDirectory, substringAfter(name, path)); if (jarEntry.isDirectory()) { forceMkdir(file); } else { forceMkdir(file.getParentFile()); if (!file.exists()) { copyInputStreamToFile(jar.getInputStream(jarEntry), file); } } } } jar.close(); } else { // Run with IDE URL url = getClass().getResource("/" + path); if (url != null) { File apps = FileUtils.toFile(url); if (apps.isDirectory()) { copyDirectory(apps, reportsDirectory); } else { throw new IllegalStateException( format("Internal resource '%s' should be a directory.", apps.getAbsolutePath())); } } else { throw new IllegalStateException(format("Internal resource '/%s' should be here.", path)); } } }
From source file:gov.nih.nci.caintegrator.mockito.AbstractMockitoTest.java
private void setUpNCIAFacade() throws Exception { nciaFacade = mock(NCIAFacade.class); final File validFile = FileUtils .toFile(this.getClass().getResource(TestDataFiles.VALID_FILE_RESOURCE_PATH)); when(nciaFacade.getAllCollectionNameProjects(any(ServerConnectionProfile.class))) .thenReturn(new ArrayList<String>()); when(nciaFacade.getImageSeriesAcquisitions(anyString(), any(ServerConnectionProfile.class))) .thenReturn(Arrays.asList(new ImageSeriesAcquisition())); when(nciaFacade.retrieveDicomFiles(any(NCIADicomJob.class))).thenReturn(validFile); }
From source file:com.greenpepper.maven.plugin.SpecificationRunnerMojo.java
private void runInForkedRunner(Repository repository, String test, File repositoryReportsFolder) throws MojoExecutionException { File outputFile = new File(repositoryReportsFolder, test); SystemUnderTest systemUnderTest = new SystemUnderTest(); systemUnderTest.setName(repository.getSystemUnderTest()); systemUnderTest.setProject(Project.newInstance(repository.getProjectName())); Specification specification = Specification.newInstance(test); com.greenpepper.server.domain.Repository repositoryRunner = com.greenpepper.server.domain.Repository .newInstance(repository.getName()); RepositoryType repositoryType = RepositoryType.newInstance("FILE"); repositoryType.setRepositoryClass(repository.getType()); EnvironmentType java = EnvironmentType.newInstance("JAVA"); repositoryType.registerClassForEnvironment(repository.getType(), java); repositoryRunner.setBaseTestUrl(repository.getRoot()); repositoryRunner.setType(repositoryType); specification.setRepository(repositoryRunner); systemUnderTest.setFixtureFactory(systemUnderDevelopment); systemUnderTest.setFixtureFactoryArgs(systemUnderDevelopmentArgs); specification.setDialectClass(repository.getDialect()); String runnerName = repository.getRunnerName(); if (runnerName == null) { if (runnerMap.size() == 1) { runnerName = runnerMap.keySet().iterator().next(); } else {/*w w w . jav a2s. c o m*/ runnerName = DEFAULT_RUNNER_NAME; } } Runner defaultRunner = runnerMap.get(runnerName); ExecutorService executorService = executorMap.get(runnerName); if (defaultRunner != null && executorService != null) { if (defaultRunner.getForkCount() == 1) { defaultRunner.setRedirectOutputToFile(redirectOutputToFile); } // We will try to get the external-link after the test (for version of Greepepper < 4.1 ) defaultRunner.setRepositoryIndex(this.repositoryIndexes.get(repository.getName())); TestResultsIndex testResultsIndex = testResultsIndexes.get(repository.getName()); RunnerTask runnerTask = new RunnerTask(specification, systemUnderTest, outputFile.getAbsolutePath(), defaultRunner, getLog(), testResultsIndex); if (defaultRunner.isIncludeProjectClasspath()) { TreeSet<String> classpath = new TreeSet<String>(); for (URL url : createClasspath()) { classpath.add(FileUtils.toFile(url).getAbsolutePath()); } systemUnderTest.setSutClasspaths(classpath); } Future<?> future = executorService.submit(runnerTask); RunnerResult runnerResult = new RunnerResult(runnerTask, future); runnerResults.add(runnerResult); } else { getLog().warn(format( "No runner found for executing %s in repository %s. Runner '%s' was specified (or falled back to)", specification.getName(), repository.getName(), runnerName)); } }
From source file:at.gv.egiz.pdfas.web.helper.PdfAsHelper.java
private static String getTemplateSL() throws IOException { String xml = FileUtils/* ww w . ja v a2 s . c o m*/ .readFileToString(FileUtils.toFile(PdfAsHelper.class.getResource("/template_sl.html"))); return xml; }
From source file:at.gv.egiz.pdfas.web.helper.PdfAsHelper.java
public static String getErrorRedirectTemplateSL() throws IOException { String xml = FileUtils//from w w w.j a va 2 s. c om .readFileToString(FileUtils.toFile(PdfAsHelper.class.getResource("/template_error_redirect.html"))); return xml; }