List of usage examples for org.apache.commons.io FileUtils toFile
public static File toFile(URL url)
URL
to a File
. From source file:com.minimalgap.transformer.subtitles.SubtilesSAXParserTest.java
@BeforeMethod public void createParser() { saxParserExample = new SubtilesSAXParser(FILE_DEST); File sourceFile = FileUtils.toFile(getClass().getClassLoader().getResource(FILE_SOURCE)); Assert.assertTrue(sourceFile.exists()); sourcePath = sourceFile.getAbsolutePath(); }
From source file:cz.incad.kramerius.k5indexer.FieldsConfig.java
public FieldsConfig() throws IOException, JSONException { String path = Constants.WORKING_DIR + File.separator + "k5indexer" + File.separator + "fields.json"; File f = new File(path); if (!f.exists() || !f.canRead()) { f = FileUtils .toFile(KrameriusDocument.class.getResource("/cz/incad/kramerius/k5indexer/res/fields.json")); }/*from w ww . j a v a 2s . com*/ String json = FileUtils.readFileToString(f, "UTF-8"); fieldsConfig = new JSONObject(json); mappings = fieldsConfig.getJSONObject("mappings"); streams = fieldsConfig.getJSONObject("datastreams"); }
From source file:com.garethahealy.camel.file.loadbalancer.example1.routes.HandlesOneFileMultipleReadersTest.java
@Override protected void doPreSetup() throws Exception { File directory = FileUtils.toFile(new URL("file:" + rootDirectory)); FileUtils.deleteDirectory(directory); directory.mkdir();//from w ww . ja va2s .co m URL file1 = HandlesOneFileMultipleReadersTest.class.getClassLoader() .getResource("example-files/afile1.log"); Assert.assertNotNull(file1); FileUtils.copyFileToDirectory(FileUtils.toFile(file1), directory); LOG.info("Moved files to: " + directory.getAbsolutePath()); }
From source file:com.itemanalysis.psychometrics.factoranalysis.ExploratoryFactorAnalysisTest.java
/** * Correlation matrix from Harman74.cor$cov in R psych package. * @return//from w ww . j a va 2 s.co m */ private double[][] readHarman74Data() { double[][] harman74 = new double[24][24]; try { File f = FileUtils.toFile(this.getClass().getResource("/testdata/harman74.txt")); BufferedReader br = new BufferedReader(new FileReader(f)); String line = ""; String[] s = null; int row = 0; while ((line = br.readLine()) != null) { s = line.split(","); for (int j = 0; j < s.length; j++) { harman74[row][j] = Double.parseDouble(s[j]); } row++; } br.close(); } catch (IOException ex) { ex.printStackTrace(); } return harman74; }
From source file:com.garethahealy.camel.file.loadbalancer.example1.routes.Read99FilesWithThreeReadersTest.java
@Override protected void doPreSetup() throws Exception { File directory = FileUtils.toFile(new URL("file:" + rootDirectory)); FileUtils.deleteDirectory(directory); directory.mkdir();/*w w w.j a v a 2 s .c o m*/ for (int i = 0; i < 99; i++) { FileUtils.writeStringToFile( FileUtils.toFile(new URL("file:" + rootDirectory + "/file" + Integer.toString(i) + ".log")), "file" + Integer.toString(i)); } LOG.info("Wrote files to: " + directory.getAbsolutePath()); }
From source file:net.pms.util.FileUtilTest.java
@Test public void testGetFileCharset_WINDOWS_1251() throws Exception { File file = FileUtils.toFile(CLASS.getResource("russian-cp1251.srt")); assertThat(FileUtil.getFileCharset(file)).isEqualTo(Constants.CHARSET_WINDOWS_1251); }
From source file:com.garethahealy.camel.file.loadbalancer.example1.routes.ReadThreeFilesWithThreeReadersTest.java
@Override protected void doPreSetup() throws Exception { File directory = FileUtils.toFile(new URL("file:" + rootDirectory)); FileUtils.deleteDirectory(directory); directory.mkdir();// w ww. j a v a 2s.c o m URL file1 = ReadThreeFilesWithThreeReadersTest.class.getClassLoader() .getResource("example-files/afile1.log"); URL file2 = ReadThreeFilesWithThreeReadersTest.class.getClassLoader() .getResource("example-files/bfile2.log"); URL file3 = ReadThreeFilesWithThreeReadersTest.class.getClassLoader() .getResource("example-files/cfile3.log"); Assert.assertNotNull(file1); Assert.assertNotNull(file2); Assert.assertNotNull(file3); FileUtils.copyFileToDirectory(FileUtils.toFile(file1), directory); FileUtils.copyFileToDirectory(FileUtils.toFile(file2), directory); FileUtils.copyFileToDirectory(FileUtils.toFile(file3), directory); LOG.info("Moved files to: " + directory.getAbsolutePath()); }
From source file:dk.nsi.haiba.lprimporter.testdata.SQLStatementsFromcpr34200CSV.java
private void generateAdministrationData() throws IOException { File file = FileUtils.toFile(getClass().getClassLoader().getResource("data/cpr34200.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 .com*/ continue; } String[] splits = line.split(";"); String recnum = splits[0]; String sygehus = splits[1]; String afdeling = splits[2]; String type = splits[3]; String cpr = splits[4]; String idate = splits[5]; String udate = splits[6]; String itime = splits[7]; if (itime.length() == 0) { itime = "0"; } String utime = splits[8]; if (utime.length() == 0) { utime = "0"; } StringBuffer sql = new StringBuffer(); sql.append( "INSERT INTO T_ADM (V_RECNUM, C_SGH, C_AFD, V_CPR, D_INDDTO,D_UDDTO,V_INDTIME,V_UDTIME, C_PATTYPE) VALUES ("); sql.append(recnum); sql.append(", '"); sql.append(sygehus); sql.append("', '"); sql.append(afdeling); sql.append("', '"); sql.append(cpr); sql.append("', '"); sql.append(idate); sql.append("', '"); sql.append(udate); sql.append("', "); sql.append(itime); sql.append(", "); sql.append(utime); sql.append(", "); sql.append(type); sql.append(");"); System.out.println(sql.toString()); } }
From source file:ee.ria.xroad.common.conf.globalconfextension.OcspFetchIntervalSchemaValidatorTest.java
private String getClasspathFilename(String fileName) { URL schemaLocation = ResourceUtils.class.getClassLoader().getResource(fileName); File f = FileUtils.toFile(schemaLocation); return f.getPath(); }
From source file:cz.incad.kramerius.client.tools.IndexConfig.java
public IndexConfig() throws IOException, JSONException { String path = System.getProperty("user.home") + File.separator + ".kramerius4" + File.separator + "k5client" + File.separator + "fields.json"; // File f = new File(path); // if (!f.exists() || !f.canRead()) { // f = FileUtils.toFile(IndexConfig.class.getResource("/cz/incad/kramerius/client/tools/fields.json")); // }/*from w ww . ja va 2s .c o m*/ File fdef = FileUtils.toFile(IndexConfig.class.getResource("/cz/incad/kramerius/client/tools/fields.json")); String json = FileUtils.readFileToString(fdef, "UTF-8"); fieldsConfig = new JSONObject(json); File f = new File(path); if (f.exists() && f.canRead()) { json = FileUtils.readFileToString(f, "UTF-8"); JSONObject confCustom = new JSONObject(json); Iterator keys = confCustom.keys(); while (keys.hasNext()) { String key = (String) keys.next(); LOGGER.log(Level.INFO, "key {0} will be overrided", key); fieldsConfig.put(key, confCustom.get(key)); } } mappings = fieldsConfig.getJSONObject("mappings"); }