List of usage examples for org.apache.commons.io FileUtils readFileToString
public static String readFileToString(File file) throws IOException
From source file:com.legstar.protobuf.cobol.ProtoCobolUtils.java
/** * Find java specific properties in a proto file. * <p/>// w w w .ja v a 2 s . co m * The java package name can be explicitly specified in the proto file or it * defaults to to the proto file package (if any). * <p/> * The java outer class name can be explicitly specified in the proto file * or inferred from the file name. * * @param protoFile the proto file to look at * @return the java properties extracted from the file * @throws IOException if file cannot be read */ public static ProtoFileJavaProperties getJavaProperties(File protoFile) throws IOException { String javaPackageName = null; String javaClassName = null; String content = FileUtils.readFileToString(protoFile); Matcher matcher = JAVA_PACKAGE_NAME_PATTERN.matcher(content); if (matcher.find()) { javaPackageName = matcher.group(1); } else { matcher = PACKAGE_NAME_PATTERN.matcher(content); if (matcher.find()) { javaPackageName = matcher.group(1); } } matcher = JAVA_OUTER_CLASS_NAME_PATTERN.matcher(content); if (matcher.find()) { javaClassName = matcher.group(1) + ".java"; } else { javaClassName = getDefaultJavaClassName(protoFile); } return new ProtoFileJavaProperties(javaPackageName, javaClassName); }
From source file:com.graphaware.test.data.CypherFilesPopulator.java
/** * {@inheritDoc}//from ww w . j a v a 2 s .c om */ @Override protected String[] statementGroups() { List<String> result = new LinkedList<>(); try { String[] files = files(); if (files == null) { return new String[0]; } for (String file : files) { result.add(FileUtils.readFileToString(new File(file))); } } catch (IOException e) { throw new RuntimeException(e); } return result.toArray(new String[result.size()]); }
From source file:com.cloudant.mazha.DocumentRevsTest.java
@Test public void deserialization_others() throws IOException { String s = FileUtils.readFileToString(new File("fixture/document_revs_others.json")); DocumentRevs documentRevs = jsonHelper.fromJson(new StringReader(s), DocumentRevs.class); Map<String, Object> others = documentRevs.getOthers(); Assert.assertThat(others.keySet(), hasSize(2)); Assert.assertThat(others.keySet(), hasItems("a", "b")); Assert.assertEquals("A", others.get("a")); Assert.assertEquals("B", others.get("b")); }
From source file:com.playonlinux.bash.ScriptLegacyTest.java
@Test public void testDetectType_passALegacyScript_FormatIsDetected() throws IOException { assertEquals(Script.Type.LEGACY, Script.detectScriptType(FileUtils .readFileToString(new File(this.getClass().getResource("legacyScriptExample.sh").getPath())))); }
From source file:com.kenshoo.facts.FactsToJsonFileTest.java
@Test public void writeFactsFile() throws Exception { HashMap<String, String> props = new HashMap<String, String>(); props.put("Dog", "Labrador"); props.put("Cat", "Lion"); factsToJsonFile = prepareMock(props, null); String jsonFacts = FileUtils .readFileToString(factsToJsonFile.toJsonFileFromMapFacts(props, FACTS_JSON_FILE_NAME)); HashMap<String, String> factsFromFile = new Gson().fromJson(jsonFacts, HashMap.class); Assert.assertEquals("Number of facts got from file is wrong", factsFromFile.size(), 2); Assert.assertEquals("Fact is different", factsFromFile.get("Dog"), "Labrador"); Assert.assertEquals("Fact is different", factsFromFile.get("Cat"), "Lion"); verify(factsToJsonFile, times(1)).getExternalFactsFolder(); verify(factsToJsonFile, times(1)).toJsonFileFromMapFacts(same(props), same(FACTS_JSON_FILE_NAME)); verify(factsToJsonFile, times(1)).toJsonFileFromMapFacts(same(props), same(FACTS_JSON_FILE_NAME), isNull(Set.class)); }
From source file:com.ucb.stylometer.parser.TXTParser.java
@Override public String parse(String filePath) { String sample = ""; try {//from w ww .ja va 2 s .com sample = FileUtils.readFileToString(new File(filePath)); } catch (IOException ex) { Logger.getLogger(TXTParser.class.getName()).log(Level.SEVERE, "Error while parsing file.", ex); } return sample; }
From source file:com.mirth.connect.model.converters.tests.HL7SerializerTest.java
@Test public void testFromXmlDefault() throws Exception { String input = FileUtils.readFileToString(new File("tests/test-hl7-output.xml")); String output = FileUtils.readFileToString(new File("tests/test-hl7-input.txt")); ER7Serializer serializer = new ER7Serializer(defaultProperties); Assert.assertEquals(output, TestUtil.convertCRToCRLF(serializer.fromXML(input))); }
From source file:com.dianping.maven.plugin.tools.misc.file.ProjectMetaGeneratorTest.java
@Test public void test() throws Exception { String expected = "<projects>\n" + " <project name=\"shoppic-service\">\n" + " <port>2000</port>\n" + " </project>\n" + " <project name=\"group-service\">\n" + " <port>2001</port>\n" + " </project>\n" + " <project name=\"account-service\">\n" + " <port>2002</port>\n" + " </project>\n" + " <project name=\"user-service\">\n" + " <port>2003</port>\n" + " </project>\n" + "</projects>"; ProjectMetaContext context = new ProjectMetaContext("org.h2.Driver", "jdbc:h2:mem:hawk;DB_CLOSE_DELAY=-1", "", ""); ProjectMetaGenerator smg = new ProjectMetaGenerator(); smg.generate(file, context);//from w ww . jav a 2 s . c o m Assert.assertEquals(expected, FileUtils.readFileToString(file)); }
From source file:aurelienribon.gdxsetupui.ui.Main.java
private static void parseArgs(String[] args) { for (int i = 0; i < args.length; i++) { if (args[i].equals("-testliburl") && i < args.length) { Ctx.testLibUrl = args[i + 1]; } else if (args[i].equals("-testlibdef") && i < args.length) { File file = new File(args[i + 1]); try { Ctx.testLibDef = new LibraryDef(FileUtils.readFileToString(file)); } catch (IOException ex) { System.err.println("[warning]Error while trying to read the test library file"); }/* www .j a v a2 s.co m*/ } } }
From source file:com.us.bo.UserBo.java
public void sendMail(User user) { try {//from w ww. j a v a2 s . c o m Map<String, Object> data = MapHelper.hashMap(); data.put("userName", user.getLoginID()); data.put("usermail", user.getMail()); String path = "http://127.0.0.1:10000/img/app/AddProfile.do?name=%s&mail=%s&active=%s"; data.put("url", String.format(path, user.getLoginID(), user.getMail(), HashUtil.hashAll(user.getLoginID(), user.getMail()))); String reader = FileUtils.readFileToString(ResourceUtils.getFile("classpath:/ftls/mails/newUser.html")); String mailContent = FtlUtil.render2Str(data, reader); Email email = Email.newMail(user.getMail(), "chongqinghxh@163.com", "?", mailContent); mailBo.send(email); } catch (Exception e) { e.printStackTrace(); } }