List of usage examples for org.apache.commons.io FileUtils toFile
public static File toFile(URL url)
URL
to a File
. From source file:dk.nsi.haiba.lprimporter.testdata.SQLStatementsFromCSVFiles.java
private void generateAdministrationData() throws IOException { File file = FileUtils.toFile(getClass().getClassLoader().getResource("data/T_ADM.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 va 2 s . co m*/ continue; } String[] splits = line.split(","); String cpr = splits[0]; String sygehus = splits[1]; String afdeling = splits[2]; String idate = splits[3]; String itime = splits[4]; if (itime.length() == 0) { itime = "0"; } String udate = splits[5]; String utime = splits[6]; if (utime.length() == 0) { utime = "0"; } String dummy = splits[7]; String recnum = splits[8]; 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) 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(");"); System.out.println(sql.toString()); } }
From source file:dk.nsi.haiba.lprimporter.testdata.SQLStatementsFromCPR83174CSV.java
private void generateAdministrationData() throws IOException { File file = FileUtils.toFile(getClass().getClassLoader().getResource("data/cpr83174ADM.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 va 2 s .c o m continue; } //v_recnum;c_sgh;c_afd;c_pattype;v_cpr;d_inddto;d_uddto;v_indtime;v_udtime 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:net.pms.util.FileUtilTest.java
@Test public void testGetFileCharset_IBM866() throws Exception { File file = FileUtils.toFile(CLASS.getResource("russian-ibm866.srt")); assertThat(FileUtil.getFileCharset(file)).isEqualTo(Constants.CHARSET_IBM866); }
From source file:cz.incad.vdkcommon.oai.HarvesterJobData.java
public HarvesterJobData(VDKJobData jdata) throws Exception { this.jdata = jdata; this.configFile = jdata.getConfigFile(); this.homeDir = System.getProperty("user.home") + File.separator + ".vdkcr" + File.separator; //String path = this.homeDir + this.configFile + ".json"; File fdef = FileUtils.toFile(Options.class.getResource("/cz/incad/vdkcommon/oai.json")); String json = FileUtils.readFileToString(fdef, "UTF-8"); opts = new JSONObject(json); // File f = new File(this.configFile); // 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); // opts.put(key, confCustom.get(key)); // } // }/* ww w . ja v a 2s .co m*/ this.name = jdata.getString("knihovna"); this.oaiDir = jdata.getString("oaiDir", ".vdkcr") + File.separator; this.statusFile = jdata.getStatusFile(); this.saveToDisk = jdata.getBoolean("saveToDisk", true); this.fullIndex = jdata.getBoolean("fullIndex", false); this.onlyHarvest = jdata.getBoolean("onlyHarvest", false); this.noDate = jdata.getBoolean("noDate", false); this.startIndex = jdata.getInt("startIndex", -1); this.pathToData = jdata.getString("indexDirectory"); this.sdfoai = new SimpleDateFormat(jdata.getString("oaiDateFormat")); this.sdf = new SimpleDateFormat(jdata.getString("filePathFormat")); this.metadataPrefix = jdata.getString("metadataPrefix"); this.interval = Interval.parseString(jdata.getString("interval")); logger.info("HarvesterJobData initialized"); }
From source file:com.itemanalysis.psychometrics.reliability.CronbachAlphaTest.java
public double[][] getData() { double[][] x = new double[1000][50]; try {// w w w .j a v a 2 s. c om File f = FileUtils.toFile(this.getClass().getResource("/testdata/scaling.txt")); BufferedReader br = new BufferedReader(new FileReader(f)); String line = ""; String[] s = null; int row = 0; br.readLine();// eliminate column names by skipping first row while ((line = br.readLine()) != null) { s = line.split(","); for (int j = 0; j < 50; j++) { x[row][j] = Double.parseDouble(s[j]); } row++; } br.close(); } catch (IOException ex) { ex.printStackTrace(); } return x; }
From source file:com.canoo.webtest.util.WebtestEmbeddingUtil.java
/** * Copies WebTest resources (ie webtest.xml, tools/*, the XSLs, CSSs and pictures, ...) package in WebTest jar file * into the provide folder. Indeed different Ant tasks can't work with resources in a jar file. * @param targetFolder the folder in which resources should be copied to * @throws java.io.IOException if the resources can be accessed or copied *///from w ww . ja v a 2 s.co m static void copyWebTestResources(final File targetFolder) throws IOException { final String resourcesPrefix = "com/canoo/webtest/resources/"; final URL webtestXmlUrl = WebtestEmbeddingUtil.class.getClassLoader() .getResource(resourcesPrefix + "webtest.xml"); if (webtestXmlUrl == null) { throw new IllegalStateException("Can't find resource " + resourcesPrefix + "webtest.xml"); } else if (webtestXmlUrl.toString().startsWith("jar:file")) { final String urlJarFileName = webtestXmlUrl.toString().replaceFirst("^jar:file:([^\\!]*).*$", "$1"); final String jarFileName = URLDecoder.decode(urlJarFileName, Charset.defaultCharset().name()); final JarFile jarFile = new JarFile(jarFileName); final String urlPrefix = StringUtils.removeEnd(webtestXmlUrl.toString(), "webtest.xml"); for (final Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements();) { final JarEntry jarEntry = entries.nextElement(); if (jarEntry.getName().startsWith(resourcesPrefix)) { final String relativeName = StringUtils.removeStart(jarEntry.getName(), resourcesPrefix); final URL url = new URL(urlPrefix + relativeName); final File targetFile = new File(targetFolder, relativeName); FileUtils.forceMkdir(targetFile.getParentFile()); FileUtils.copyURLToFile(url, targetFile); } } } else if (webtestXmlUrl.toString().startsWith("file:")) { // we're probably developing and/or have a custom version of the resources in classpath final File webtestXmlFile = FileUtils.toFile(webtestXmlUrl); final File resourceFolder = webtestXmlFile.getParentFile(); FileUtils.copyDirectory(resourceFolder, targetFolder); } else { throw new IllegalStateException( "Resource " + resourcesPrefix + "webtest.xml is not in a jar file: " + webtestXmlUrl); } }
From source file:com.itemanalysis.psychometrics.scaling.KelleyRegressedScoreTest.java
public double[][] getData() { double[][] x = new double[1000][50]; try {//from www . j a v a2 s. c om File f = FileUtils.toFile(this.getClass().getResource("/testdata/scaling.txt")); BufferedReader br = new BufferedReader(new FileReader(f)); String line = ""; String[] s = null; int row = 0; br.readLine();//eliminate column names by skipping first row while ((line = br.readLine()) != null) { s = line.split(","); for (int j = 0; j < 50; j++) { x[row][j] = Double.parseDouble(s[j]); } row++; } br.close(); } catch (IOException ex) { ex.printStackTrace(); } return x; }
From source file:net.pms.util.FileUtilTest.java
@Test public void testGetFileCharset_KOI8_R() throws Exception { File file = FileUtils.toFile(CLASS.getResource("russian-koi8-r.srt")); assertThat(FileUtil.getFileCharset(file)).isEqualTo(Constants.CHARSET_KOI8_R); }
From source file:com.greenpepper.runner.CommandLineRunnerTest.java
private void createOutputDirectory() { URL testDirectory = getClass().getResource("."); File parentDirectory = FileUtils.toFile(testDirectory); outputDir = new File(parentDirectory, "specs"); }
From source file:fr.inria.maestro.lga.algo.ppr.power.PowerIterationTest.java
private static double[] loadResult(final String name) throws IOException { final File folder = FileUtils.toFile(PowerIterationTest.class.getResource("/pr_gold")); return loadFromFile(new File(folder, name)); }