List of usage examples for org.apache.commons.io FileUtils readFileToString
public static String readFileToString(File file) throws IOException
From source file:com.carrotgarden.maven.aws.cfn.TestCarrotCloudForm.java
public void testStack() throws Exception { final File templateFile = new File("./src/test/resources/ec2-builder.template"); final String stackName = "builder"; final String stackTemplate = FileUtils.readFileToString(templateFile); final Map<String, String> stackParams = new HashMap<String, String>(); final long timeout = 6 * 60; // seconds /** admin-cfn */ final String accessKey = ""; final String secretKey = ""; final AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); ////w w w . j a va 2 s.c o m final CarrotCloudForm formation = new CarrotCloudForm(logger, stackName, stackTemplate, stackParams, timeout, credentials, null); formation.stackCreate(); assertTrue(true); formation.stackDelete(); }
From source file:com.aionemu.gameserver.configs.shedule.RiftSchedule.java
public static RiftSchedule load() { RiftSchedule rs;// w w w. ja v a2s . c o m try { String xml = FileUtils.readFileToString(new File("./config/shedule/rift_schedule.xml")); rs = JAXBUtil.deserialize(xml, RiftSchedule.class); } catch (Exception e) { throw new RuntimeException("Failed to initialize rifts", e); } return rs; }
From source file:com.aionemu.gameserver.configs.schedule.RiftSchedule.java
public static RiftSchedule load() { RiftSchedule rs;/* w w w . ja va 2s . c o m*/ try { String xml = FileUtils.readFileToString(new File("./config/schedule/rift_schedule.xml")); rs = JAXBUtil.deserialize(xml, RiftSchedule.class); } catch (Exception e) { throw new RuntimeException("Failed to initialize Rifts", e); } return rs; }
From source file:com.centeractive.ws.builder.MessageComplianceTest.java
public static String getContent(String folderPath, String fileName) { URL fileUrl = ResourceUtils.getResourceWithAbsolutePackagePath(folderPath, fileName); File file = null;/* w w w. j a v a 2 s . co m*/ try { file = new File(fileUrl.toURI()); } catch (URISyntaxException e) { file = new File(fileUrl.getPath()); } try { return FileUtils.readFileToString(file); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.betfair.cougar.marshalling.impl.databinding.xml.XMLUtils.java
public static Schema getSchema(JAXBContext context) { Result result = new ResultImplementation(); SchemaOutputResolver outputResolver = new SchemaOutputResolverImpl(result); File tempFile = null;//from w w w . j av a2 s.c o m try { context.generateSchema(outputResolver); String schemaFile = result.getSystemId(); if (schemaFile != null) { tempFile = new File(URI.create(schemaFile)); String content = FileUtils.readFileToString(tempFile); // JAXB nicely generates a schema with element refs, unfortunately it also adds the nillable attribute to the // referencing element, which is invalid, it has to go on the target. this string manipulation is to move the // nillable attribute to the correct place, preserving it's value. Map<String, Boolean> referenceElementsWithNillable = new HashMap<>(); BufferedReader br = new BufferedReader(new StringReader(content)); String line; while ((line = br.readLine()) != null) { if (line.contains("<xs:element") && line.contains(" ref=\"") && line.contains(" nillable=\"")) { // we've got a reference element with nillable set int refStartIndex = line.indexOf(" ref=\"") + 6; int refEndIndex = line.indexOf("\"", refStartIndex); int nillableStartIndex = line.indexOf(" nillable=\"") + 11; int nillableEndIndex = line.indexOf("\"", nillableStartIndex); String ref = line.substring(refStartIndex, refEndIndex); if (ref.startsWith("tns:")) { ref = ref.substring(4); } String nillable = line.substring(nillableStartIndex, nillableEndIndex); referenceElementsWithNillable.put(ref, Boolean.valueOf(nillable)); } } // if we got some hits, then we need to rewrite this schema if (!referenceElementsWithNillable.isEmpty()) { StringBuilder sb = new StringBuilder(); br = new BufferedReader(new StringReader(content)); while ((line = br.readLine()) != null) { // these we need to remove the nillable section from if (line.contains("<xs:element") && line.contains(" ref=\"") && line.contains(" nillable=\"")) { int nillableStartIndex = line.indexOf(" nillable=\""); int nillableEndIndex = line.indexOf("\"", nillableStartIndex + 11); line = line.substring(0, nillableStartIndex) + line.substring(nillableEndIndex + 1); } else if (line.contains("<xs:element name=\"")) { for (String key : referenceElementsWithNillable.keySet()) { // this we need to add the nillable back to String elementTagWithName = "<xs:element name=\"" + key + "\""; if (line.contains(elementTagWithName)) { int endOfElementName = line.indexOf(elementTagWithName) + elementTagWithName.length(); line = line.substring(0, endOfElementName) + " nillable=\"" + referenceElementsWithNillable.get(key) + "\"" + line.substring(endOfElementName); break; } } } sb.append(line).append("\n"); } content = sb.toString(); } SchemaFactory sf = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI); return sf.newSchema(new StreamSource(new StringReader(content))); } } catch (IOException e) { throw new PanicInTheCougar(e); } catch (SAXException e) { throw new PanicInTheCougar(e); } finally { if (tempFile != null) tempFile.delete(); } return null; }
From source file:com.chiorichan.factory.parsers.LessImportParser.java
@Override public String resolveMethod(String... args) throws Exception { File imp = FileFunc.isAbsolute(args[0]) || args[0].startsWith("\\") || rootDir == null ? new File(args[0]) : new File(rootDir, args[0]); try {//from w ww .java 2 s . co m return FileUtils.readFileToString(imp); } catch (IOException e) { Log.get("ScriptFactory").warning( "Attempted to import file '" + imp.getName() + "' but got error '" + e.getMessage() + "'"); return "/* Attempted to import file '" + imp.getName() + "' but got error '" + e.getMessage() + "' */"; } }
From source file:ACE.Doc.java
public Doc(String path) { try {//from w w w .j a v a2 s . co m this.text = FileUtils.readFileToString(new File(path)); } catch (IOException ex) { Logger.getLogger(Doc.class.getName()).log(Level.SEVERE, null, ex); } entities = new HashMap<>(); relations = new ArrayList<>(); }
From source file:com.badlogicgames.packr.Packr.java
public static void main(String[] args) throws IOException { if (args.length > 1) { Map<String, String> arguments = parseArgs(args); Config config = new Config(); config.platform = Platform.valueOf(arguments.get("platform")); config.jdk = arguments.get("jdk"); config.executable = arguments.get("executable"); config.jar = arguments.get("appjar"); config.mainClass = arguments.get("mainclass"); if (arguments.get("vmargs") != null) { config.vmArgs = Arrays.asList(arguments.get("vmargs").split(";")); }/*from w ww .jav a2 s. c o m*/ config.outDir = arguments.get("outdir"); if (arguments.get("minimizejre") != null) { if (new File(arguments.get("minimizejre")).exists()) { config.minimizeJre = FileUtils.readFileToString(new File(arguments.get("minimizejre"))) .split("\r?\n"); } else { InputStream in = Packr.class.getResourceAsStream("/minimize/" + arguments.get("minimizejre")); if (in != null) { config.minimizeJre = IOUtils.toString(in).split("\r?\n"); in.close(); } else { config.minimizeJre = new String[0]; } } } if (arguments.get("resources") != null) config.resources = Arrays.asList(arguments.get("resources").split(";")); new Packr().pack(config); } else { if (args.length == 0) { printHelp(); } else { JsonObject json = JsonObject.readFrom(FileUtils.readFileToString(new File(args[0]))); Config config = new Config(); config.platform = Platform.valueOf(json.get("platform").asString()); config.jdk = json.get("jdk").asString(); config.executable = json.get("executable").asString(); config.jar = json.get("appjar").asString(); config.mainClass = json.get("mainclass").asString(); if (json.get("vmargs") != null) { for (JsonValue val : json.get("vmargs").asArray()) { config.vmArgs.add(val.asString()); } } config.outDir = json.get("outdir").asString(); if (json.get("minimizejre") != null) { if (new File(json.get("minimizejre").asString()).exists()) { config.minimizeJre = FileUtils .readFileToString(new File(json.get("minimizejre").asString())).split("\r?\n"); } else { InputStream in = Packr.class.getResourceAsStream("/minimize/" + json.get("minimizejre")); if (in != null) { config.minimizeJre = IOUtils.toString(in).split("\r?\n"); in.close(); } else { config.minimizeJre = new String[0]; } } } if (json.get("resources") != null) { config.resources = toStringArray(json.get("resources").asArray()); } new Packr().pack(config); } } }
From source file:com.opengamma.util.db.script.FileDbScript.java
@Override public String getScript() throws IOException { return FileUtils.readFileToString(getFile()); }
From source file:de.schaeuffelhut.android.openvpn.tun.DeviceDetails.java
private static String readKernelVersion() { final String procVersion; try {//w ww. ja v a 2 s .c o m procVersion = FileUtils.readFileToString(new File("/proc/version")); } catch (IOException e) { // LOG via ACRA Log.e("OpenVPN-Settings", "reading /proc/version", e); return "unknown"; } if (procVersion.startsWith("Linux version ")) return procVersion.substring("Linux version ".length(), procVersion.indexOf(" ", "Linux version ".length())); return procVersion; }