List of usage examples for org.apache.commons.io FileUtils readFileToString
public static String readFileToString(File file) throws IOException
From source file:hu.bme.mit.trainbenchmark.benchmark.sesame.checkers.SesameChecker.java
public SesameChecker(final SesameDriver driver, final BenchmarkConfig bc) throws IOException { super();//from w ww . j a v a 2s . com this.driver = driver; this.query = bc.getQuery(); final String queryPath = bc.getWorkspacePath() + "/hu.bme.mit.trainbenchmark.benchmark.rdf/src/main/resources/queries/" + bc.getQuery() + ".sparql"; this.queryDefinition = FileUtils.readFileToString(new File(queryPath)); }
From source file:com.blockwithme.longdb.tools.Utils.java
/** Attempts to read file with name - 'OriginalFileName'.crc32 if present : * Assumes that the content inside 'OriginalFileName'.crc32 file is equal to * the CRC32 value of the Original file. Calculates CRC32 value of the * current file and Compares it with the original value. In case if the * .crc32 file is not found, or the file size is not 8 bytes this method * returns false, If the file is found but the values don't match this * method throws a RuntimeExcepiton.//from ww w. j a va 2 s .com * * @param theFile * the file * @param isCompressed * true if compressed * @return true, if checksum successful * @throws Exception */ // TODO: When do we need to differentiate the "no crc file" and // "bad crc" cases? Is it not a failure, one way or another? public static boolean checkSum(final File theFile, final boolean isCompressed) throws Exception { final File crcFile = new File(theFile.getAbsolutePath() + ".crc32"); if (!crcFile.exists() || crcFile.length() != INT_BYTES * 2) { return false; } final String crcCode = FileUtils.readFileToString(crcFile); final long expectedCRC = Long.valueOf(crcCode, 16); // $codepro.audit.disable // handleNumericParsingErrors if (getCRC32(theFile, isCompressed) != expectedCRC) throw new RuntimeException("CRC-32 validation failed for file:" + theFile.getAbsolutePath()); return true; }
From source file:annis.visualizers.component.graph.DebugVisualizer.java
@Override public void createDotContent(VisualizerInput input, StringBuilder sb) { try {//from ww w . j a v a 2 s . c o m File tmpFile = File.createTempFile("annisdebugvis", ".dot"); tmpFile.deleteOnExit(); Salt2DOT converter = new Salt2DOT(); converter.salt2Dot(input.getDocument().getSDocumentGraph(), URI.createFileURI(tmpFile.getCanonicalPath())); sb.append(FileUtils.readFileToString(tmpFile)); if (!tmpFile.delete()) { log.warn("Cannot delete " + tmpFile.getAbsolutePath()); } } catch (IOException ex) { log.error("could not create temporary file for dot", ex); } }
From source file:com.genericworkflownodes.knime.nodegeneration.model.meta.FeatureMeta.java
/** * Constructs the feature meta information given the node source directory. * // w w w.j av a2s.c o m * @param sourceDirectory */ public FeatureMeta(NodesSourceDirectory sourceDirectory, GeneratedPluginMeta pluginMeta) { super(pluginMeta.getId(), pluginMeta.getGeneratedPluginVersion()); try { name = pluginMeta.getName(); description = FileUtils.readFileToString(sourceDirectory.getDescriptionFile()); copyright = FileUtils.readFileToString(sourceDirectory.getCopyrightFile()); license = FileUtils.readFileToString(sourceDirectory.getLicenseFile()); } catch (IOException e) { throw new InvalidParameterException("Could not read meta information.\n" + e.getMessage()); } }
From source file:it.drwolf.ridire.utility.test.NewsCleaner.java
public NewsCleaner() throws IOException { // this.removeDirtyHtml(); File dir2 = new File(DIR2); List<File> dir2files = new ArrayList(FileUtils.listFiles(dir2, null, false)); for (File f : dir2files) { String content = FileUtils.readFileToString(f); content = StringEscapeUtils.unescapeHtml(content); content = content.replaceAll("\\\\\n", " "); File nf = new File(f.getAbsolutePath().substring(0, f.getAbsolutePath().length() - 5)); FileUtils.writeStringToFile(nf, content, "UTF-8"); }/*w w w.j av a2s . com*/ }
From source file:com.github.psorobka.appium.StopServerMojo.java
@Override public void execute() throws MojoExecutionException { try {/*from w w w . j a va 2s . co m*/ getLog().info("Stopping Appium server..."); int pid = Integer.parseInt(FileUtils.readFileToString(new File(target, "appium.pid"))); getLog().debug("Appium server PID " + pid); PidProcess process; if (Os.isFamily(Os.FAMILY_WINDOWS)) { WindowsProcess windowsProcess = (WindowsProcess) Processes.newPidProcess(pid); windowsProcess.setIncludeChildren(true); process = windowsProcess; } else { process = Processes.newPidProcess(pid); } if (!process.isAlive()) { throw new MojoExecutionException("Appium server is not running"); } ProcessUtil.destroyGracefullyOrForcefullyAndWait(process, 30, TimeUnit.SECONDS, 10, TimeUnit.SECONDS); if (process.isAlive()) { throw new MojoExecutionException("Failed to stop Appium server"); } getLog().info("Appium server stopped"); } catch (InterruptedException | TimeoutException | IOException ex) { throw new MojoExecutionException("Failed to stop Appium server", ex); } }
From source file:mx.itesm.imb.ImbBusController.java
@SuppressWarnings("unchecked") public static void generateImbBusController(final File rooProject, final File busProject) { Writer writer;//from w ww.j a v a 2 s . c om File typeReference; File controllerFile; int basePackageIndex; String imbTypePackage; String webConfiguration; VelocityContext context; Collection<String> types; String controllerPackage; Iterator<File> typesIterator; try { // Copy imb types FileUtils.copyDirectory(new File(rooProject, "/src/main/java/imb"), new File(busProject, "/src/main/java/imb")); FileUtils.copyFile(new File(rooProject, "/src/main/resources/schema.xsd"), new File(busProject, "/src/main/resources/schema.xsd")); imbTypePackage = null; types = new ArrayList<String>(); typesIterator = FileUtils.iterateFiles(new File(busProject, "/src/main/java/imb"), new String[] { "java" }, true); while (typesIterator.hasNext()) { typeReference = typesIterator.next(); if ((!typeReference.getName().equals("ObjectFactory.java")) && (!typeReference.getName().equals("package-info.java"))) { if (FileUtils.readFileToString(typeReference).contains("public class")) { types.add(typeReference.getName().replace(".java", "")); if (imbTypePackage == null) { imbTypePackage = typeReference.getPath() .substring( typeReference.getPath().indexOf("src/main/java") + "src/main/java".length() + 1, typeReference.getPath().indexOf(typeReference.getName()) - 1) .replace(File.separatorChar, '.'); } } } } // Add rest configuration FileUtils.copyFile( new File(rooProject, "/src/main/resources/META-INF/spring/applicationContext-contentresolver.xml"), new File(busProject, "/src/main/resources/META-INF/spring/applicationContext-contentresolver.xml")); context = new VelocityContext(); context.put("types", types); context.put("imbTypePackage", imbTypePackage); webConfiguration = FileUtils .readFileToString(new File(busProject, "src/main/webapp/WEB-INF/spring/webmvc-config.xml")); basePackageIndex = webConfiguration.indexOf("base-package=\"") + "base-package=\"".length(); controllerPackage = webConfiguration.substring(basePackageIndex, webConfiguration.indexOf('"', basePackageIndex)) + ".web"; context.put("controllerPackage", controllerPackage); context.put("typePackage", controllerPackage.replace(".web", ".domain")); controllerFile = new File(busProject, "/src/main/java/" + controllerPackage.replace('.', '/') + "/ImbBusController.java"); writer = new FileWriter(controllerFile); ImbBusController.controllerTemplate.merge(context, writer); writer.close(); } catch (Exception e) { System.out.println("Error while configuring IMB Bus: " + e.getMessage()); } }
From source file:com.sangupta.codefix.FixCopyright.java
protected String processEachFile(File file) throws IOException { // read contents String contents = FileUtils.readFileToString(file).trim(); // check if file contains comments or not boolean hasCopyright = CopyrightHelper.checkCopyrightExists(contents); if (!hasCopyright) { // append the copyright and move on contents = this.copyrightNotice + SYSTEM_NEW_LINE + contents; FileUtils.writeStringToFile(file, contents); return "adding copyright"; }//from w ww. ja va 2s. co m // remove comment int index = CopyrightHelper.findCopyrightEnd(contents); if (index == -1) { System.out.println("No proper ending of comment detected, skipping!"); } contents = contents.substring(index + 1); contents = this.copyrightNotice + SYSTEM_NEW_LINE + StringUtils.stripStart(contents, null); FileUtils.writeStringToFile(file, contents); return "copyright updated!"; }
From source file:com.smash.revolance.ui.database.FileSystemStorageTests.java
@Test public void storageShouldStoreDataInFileSystem() throws StorageException, IOException { storage.store("key", "data"); String content = FileUtils.readFileToString(new File(dbRoot, "key")); assertThat(content, is("data")); }
From source file:com.github.rabid_fish.proxy.mock.MockMapHelper.java
protected String readFileFromResourcePath(String filename) throws URISyntaxException, IOException { URL resource = getClass().getResource(filename); File file = new File(resource.toURI()); String body = FileUtils.readFileToString(file); return body;// www . j av a 2 s.co m }