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 testGetSubCpOptionForMencoder() throws Exception { File file_big5 = FileUtils.toFile(CLASS.getResource("../../util/chinese-big5.srt")); DLNAMediaSubtitle sub1 = new DLNAMediaSubtitle(); sub1.setExternalFile(file_big5);// w w w . j a v a 2 s . com assertThat(getSubCpOptionForMencoder(sub1)).isEqualTo("enca:zh:big5"); File file_gb18030 = FileUtils.toFile(CLASS.getResource("../../util/chinese-gb18030.srt")); DLNAMediaSubtitle sub2 = new DLNAMediaSubtitle(); sub2.setExternalFile(file_gb18030); assertThat(getSubCpOptionForMencoder(sub2)).isEqualTo("enca:zh:big5"); File file_cp1251 = FileUtils.toFile(CLASS.getResource("../../util/russian-cp1251.srt")); DLNAMediaSubtitle sub3 = new DLNAMediaSubtitle(); sub3.setExternalFile(file_cp1251); assertThat(getSubCpOptionForMencoder(sub3)).isEqualTo("enca:ru:cp1251"); File file_ibm866 = FileUtils.toFile(CLASS.getResource("../../util/russian-ibm866.srt")); DLNAMediaSubtitle sub4 = new DLNAMediaSubtitle(); sub4.setExternalFile(file_ibm866); assertThat(getSubCpOptionForMencoder(sub4)).isEqualTo("enca:ru:cp1251"); File file_koi8_r = FileUtils.toFile(CLASS.getResource("../../util/russian-koi8-r.srt")); DLNAMediaSubtitle sub5 = new DLNAMediaSubtitle(); sub5.setExternalFile(file_koi8_r); assertThat(getSubCpOptionForMencoder(sub5)).isEqualTo("enca:ru:cp1251"); }
From source file:cat.calidos.morfeu.utils.injection.DataFetcherModule.java
@Produces @Named("fileData") public InputStream fetchFileData(URI uri) throws FetchingException { try {/*from w w w . j a v a 2 s.c o m*/ log.trace("Fetching local data from {}", uri); return FileUtils.openInputStream(FileUtils.toFile(uri.toURL())); } catch (Exception e) { throw new FetchingException("Problem fetching local data at '" + uri + "'", e); } }
From source file:net.pms.util.FileUtilTest.java
@Test public void testGetFileCharset_UTF32_LE() throws Exception { File file = FileUtils.toFile(CLASS.getResource("russian-utf32-le.srt")); assertThat(FileUtil.getFileCharset(file)).isEqualTo(Constants.CHARSET_UTF_32LE); }
From source file:com.orange.ocara.model.export.docx.AuditDocxExporter.java
private void copyAuditObjectComment(AuditObject auditObject, Comment comment, File commentDir) throws IOException, Ole10NativeException { switch (comment.getType()) { case PHOTO:/*from w ww .j a va 2 s. c o m*/ FileUtils.copyFileToDirectory(FileUtils.toFile(new URL(comment.getAttachment())), commentDir); break; case AUDIO: { String baseName = FilenameUtils.getBaseName(comment.getAttachment()); File from = FileUtils.toFile(new URL(comment.getAttachment())); File to = new File(commentDir, String.format("%s.bin", baseName)); createOleObject(from, to); break; } default: break; } }
From source file:de.tuberlin.uebb.jbop.access.ClassAccessor.java
/** * To file./*w ww . ja v a2 s . c om*/ * * @param clazz * the clazz * @return the file * @throws JBOPClassException * the jBOP class exception */ static Path toPath(final Class<?> clazz) throws JBOPClassException { final CodeSource cs = clazz.getProtectionDomain().getCodeSource(); final URL resource = cs.getLocation(); if (resource == null) { throw new JBOPClassException("The Classfile for Class<" + clazz.getName() + "> couldn't be determined.", null); } String filename = FilenameUtils.normalize(FileUtils.toFile(resource).getAbsolutePath()); final String path = toClassPath(clazz); if (filename.endsWith(".jar")) { filename = filename + "!" + path; } else { filename = filename + "/" + path; } return Paths.get(filename); }
From source file:dk.nsi.haiba.lprimporter.testdata.SQLStatementsFromCSVFiles.java
private void generateProceduresData() throws IOException { File file = FileUtils.toFile(getClass().getClassLoader().getResource("data/T_PROCEDURER.csv")); boolean first = true; List<String> lines = FileUtils.readLines(file); for (String line : lines) { if (first) { // first row is column metadata first = false;/*from w ww. j a v a 2 s . c om*/ continue; } String[] splits = line.split(","); String recnum = splits[0]; String code = splits[1]; String odate = splits[2]; String otime = splits[3]; if (otime.length() == 0) { otime = "0"; } String tillaeg = splits[4]; String sygehus = splits[5]; String afdeling = splits[6]; String type = "A"; StringBuffer sql = new StringBuffer(); sql.append( "INSERT INTO T_PROCEDURER (V_RECNUM, C_OPR, C_TILOPR, C_OPRART, D_ODTO, V_OTIME, C_OSGH, C_OAFD) VALUES ("); sql.append(recnum); sql.append(", '"); sql.append(code); sql.append("', '"); sql.append(tillaeg); sql.append("', '"); sql.append(type); sql.append("', '"); sql.append(odate); sql.append("', "); sql.append(otime); sql.append(", '"); sql.append(sygehus); sql.append("', '"); sql.append(afdeling); sql.append("');"); System.out.println(sql.toString()); } }
From source file:net.pms.util.FileUtilTest.java
@Test public void testGetFileCharset_UTF32_BE() throws Exception { File file = FileUtils.toFile(CLASS.getResource("russian-utf32-be.srt")); assertThat(FileUtil.getFileCharset(file)).isEqualTo(Constants.CHARSET_UTF_32BE); }
From source file:com.garethahealy.camel.file.loadbalancer.example1.routes.ReadThreeFilesWithThreeReadersTest.java
@Test public void readThreeFilesWithThreeReaders() throws InterruptedException, MalformedURLException { Map<String, String> answer = getRouteToEndpointPriority(); //Used for debugging purposes, in-case we need to know which endpoint has what priority LOG.info("EndpointSetup: " + answer.toString()); MockEndpoint first = getMockEndpoint("mock:endFirst"); first.setExpectedMessageCount(1);//from w w w .j a v a 2s . c o m first.setResultWaitTime(TimeUnit.SECONDS.toMillis(15)); first.setAssertPeriod(TimeUnit.SECONDS.toMillis(1)); MockEndpoint second = getMockEndpoint("mock:endSecond"); second.setExpectedMessageCount(1); second.setResultWaitTime(TimeUnit.SECONDS.toMillis(15)); second.setAssertPeriod(TimeUnit.SECONDS.toMillis(1)); MockEndpoint third = getMockEndpoint("mock:endThird"); third.setExpectedMessageCount(1); third.setResultWaitTime(TimeUnit.SECONDS.toMillis(15)); third.setAssertPeriod(TimeUnit.SECONDS.toMillis(1)); //Wait for the files to be processed sleep(10); File firstDirectory = FileUtils.toFile(new URL("file:" + rootDirectory + "/.camel0")); File secondDirectory = FileUtils.toFile(new URL("file:" + rootDirectory + "/.camel1")); File thirdDirectory = FileUtils.toFile(new URL("file:" + rootDirectory + "/.camel2")); Assert.assertTrue(".camel0 doesnt exist", firstDirectory.exists()); Assert.assertTrue(".camel1 doesnt exist", secondDirectory.exists()); Assert.assertTrue(".camel2 doesnt exist", thirdDirectory.exists()); Collection<File> firstFiles = FileUtils.listFiles(firstDirectory, FileFilterUtils.fileFileFilter(), null); Collection<File> secondFiles = FileUtils.listFiles(secondDirectory, FileFilterUtils.fileFileFilter(), null); Collection<File> thirdFiles = FileUtils.listFiles(thirdDirectory, FileFilterUtils.fileFileFilter(), null); Assert.assertNotNull(firstFiles); Assert.assertNotNull(secondFiles); Assert.assertNotNull(thirdFiles); //Check the files are unique, and we haven't copied the same file twice firstFiles.removeAll(secondFiles); firstFiles.removeAll(thirdFiles); secondFiles.removeAll(firstFiles); secondFiles.removeAll(thirdFiles); thirdFiles.removeAll(firstFiles); thirdFiles.removeAll(secondFiles); //Each directory should of only copied one file Assert.assertEquals(new Integer(1), new Integer(firstFiles.size())); Assert.assertEquals(new Integer(1), new Integer(secondFiles.size())); Assert.assertEquals(new Integer(1), new Integer(thirdFiles.size())); //Assert the endpoints last, as there seems to be a strange bug where they fail but the files have been processed, //so that would suggest the MockEndpoints are reporting a false-positive first.assertIsSatisfied(); second.assertIsSatisfied(); third.assertIsSatisfied(); }
From source file:dk.nsi.haiba.lprimporter.testdata.SQLStatementsFromCPR83174CSV.java
private void generateProceduresData() throws IOException { File file = FileUtils.toFile(getClass().getClassLoader().getResource("data/cpr83174PROC.csv")); boolean first = true; List<String> lines = FileUtils.readLines(file); for (String line : lines) { if (first) { // first row is column metadata first = false;/* w ww. java 2 s . co m*/ continue; } //V_RECNUM;C_OPR;D_ODTO;V_OTIME;C_TILOPR;C_OSGH;C_OAFD String[] splits = line.split(";"); String recnum = splits[0]; String code = splits[1]; String odate = splits[2]; String otime = splits[3]; if (otime.length() == 0) { otime = "0"; } String tillaeg = splits[4]; String sygehus = splits[5]; String afdeling = splits[6]; String type = "A"; StringBuffer sql = new StringBuffer(); sql.append( "INSERT INTO T_PROCEDURER (V_RECNUM, C_OPR, C_TILOPR, C_OPRART, D_ODTO, V_OTIME, C_OSGH, C_OAFD) VALUES ("); sql.append(recnum); sql.append(", '"); sql.append(code); sql.append("', '"); sql.append(tillaeg); sql.append("', '"); sql.append(type); sql.append("', '"); sql.append(odate); sql.append("', "); sql.append(otime); sql.append(", '"); sql.append(sygehus); sql.append("', '"); sql.append(afdeling); sql.append("');"); System.out.println(sql.toString()); } }
From source file:com.github.rabid_fish.proxy.servlet.SoapServlet.java
void writeWsdl(Writer writer) throws IOException { final String path = "/wsdl/math.wsdl"; File file = FileUtils.toFile(getClass().getResource(path)); String wsdl = FileUtils.readFileToString(file); writer.append(wsdl);/*from w ww.j a va 2 s. c o m*/ }