List of usage examples for com.google.common.io Files toString
public static String toString(File file, Charset charset) throws IOException
From source file:com.android.tools.idea.rendering.LayoutFilePullParser.java
/** * Crates a new {@link LayoutFilePullParser *//*from ww w.j a va2 s . com*/ public static LayoutFilePullParser create(@NotNull LayoutlibCallback layoutlibCallback, @NotNull File xml) throws XmlPullParserException, IOException { LayoutFilePullParser parser = new LayoutFilePullParser(layoutlibCallback); parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); String xmlText = Files.toString(xml, Charsets.UTF_8); parser.setInput(new StringReader(xmlText)); return parser; }
From source file:com.insightml.utils.io.IoUtils.java
public static String readFile(final File file) { try {//from w ww . ja va2 s . c o m if (file.getName().endsWith(".gz")) { return readFile(new GZIPInputStream(new FileInputStream(file)), Charsets.UTF_8); } return Files.toString(file, Charsets.UTF_8); } catch (final IOException e) { throw new IllegalArgumentException(e); } }
From source file:org.sonar.plugins.protobuf.api.visitors.AbstractHighlighterVisitor.java
static List<Integer> startLines(File file, Charset charset) { List<Integer> startLines = Lists.newArrayList(); final String content; try {//from w ww. jav a 2 s . co m content = Files.toString(file, charset); } catch (IOException e) { throw Throwables.propagate(e); } startLines.add(0); for (int i = 0; i < content.length(); i++) { if (content.charAt(i) == '\n' || (content.charAt(i) == '\r' && i + 1 < content.length() && content.charAt(i + 1) != '\n')) { startLines.add(i + 1); } } return startLines; }
From source file:com.zack6849.alphabot.api.PermissionManager.java
public void load() { Gson gson = new GsonBuilder().setPrettyPrinting().create(); try {/* w w w .j av a 2 s. c om*/ groups.clear(); String json = Files.toString(new File("permissions.json"), Charset.isSupported("UTF-8") ? Charset.forName("UTF-8") : Charset.defaultCharset()); JsonElement jelement = new JsonParser().parse(json); JsonObject output = jelement.getAsJsonObject(); JsonObject group = output.get("groups").getAsJsonObject(); Set<Map.Entry<String, JsonElement>> set = group.entrySet(); Iterator it = set.iterator(); while (it.hasNext()) { Map.Entry en = (Map.Entry) it.next(); JsonObject obj = new JsonParser().parse(en.getValue().toString()).getAsJsonObject(); String name = obj.get("name").toString().replaceAll("\"", ""); List<Permission> permissions = new ArrayList<Permission>(); //List<String> inheiritance = new ArrayList<String>(); boolean exec = obj.get("exec").getAsBoolean(); for (JsonElement perm : obj.getAsJsonArray("permissions")) { permissions.add(new Permission(perm.getAsString(), false)); } /*for(JsonElement inheirit : obj.getAsJsonArray("inheritance")){ inheiritance.add(inheirit.getAsString()); } */ groups.add(new Group(name, permissions, exec)); for (Group g : groups) { JsonObject gr = output.get("groups").getAsJsonObject().get(g.getName()).getAsJsonObject(); if (gr.has("inheritance")) { JsonArray inherit = gr.get("inheritance").getAsJsonArray(); List<String> inheritance = new ArrayList<String>(); for (int i = 0; i < inherit.size(); i++) { inheritance.add(inherit.get(i).getAsString()); } for (String in : inheritance) { Group ing = getGroupByName(in); g.addInherit(ing); } } } } } catch (Exception ex) { Logger.getLogger(PermissionManager.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.sonar.plugins.csharp.SarifParser.java
public void parse(File file) { String contents;/*from w w w.j a va 2 s.co m*/ try { contents = Files.toString(file, Charsets.UTF_8); } catch (IOException e) { throw new IllegalStateException( "Unable to read the Roslyn SARIF report file: " + file.getAbsolutePath(), e); } JsonParser parser = new JsonParser(); JsonObject root = parser.parse(contents).getAsJsonObject(); if (root.has("runLogs")) { JsonElement runLogs = parser.parse(contents).getAsJsonObject().get("runLogs"); for (JsonElement runLogElement : runLogs.getAsJsonArray()) { JsonObject runLog = runLogElement.getAsJsonObject(); JsonArray results = runLog.getAsJsonArray("results"); if (results != null) { handleIssues(results, false); } } } else if (root.has("issues")) { JsonElement issues = parser.parse(contents).getAsJsonObject().get("issues"); handleIssues(issues.getAsJsonArray(), true); } }
From source file:com.facebook.buck.step.fs.LogContentsOfFileStep.java
@Override public StepExecutionResult execute(ExecutionContext context) throws IOException, InterruptedException { if (LOG.isLoggable(level)) { String contents;/*w w w . j av a 2 s . co m*/ try { contents = Files.toString(absolutePath.toFile(), StandardCharsets.UTF_8); LOG.logWithLevel(level, contents); } catch (IOException e) { LOG.error(e, "Error logging the contents of the file %s", absolutePath.toString()); } } return StepExecutionResult.SUCCESS; }
From source file:org.gradle.api.internal.resources.FileCollectionBackedTextResource.java
public String asString() { try {/* w w w . j a v a 2 s .c o m*/ return Files.toString(asFile(), charset); } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:com.github.enr.markdownj.extras.FileUtils.java
/** * Returns file content as string, reading from a url. Throws runtime * exception in case of FileNotFoundException or IOException. * //from w w w . j a v a 2s . c o m * @param fileurl the url of the file to read. * @return file content as string. */ public static String readFileFromUrl(URL fileurl, String encoding) { String fileContent = ""; try { Charset charset = charsetForNameOrDefault(encoding); fileContent = Files.toString(fileFromUrl(fileurl), charset); } catch (IOException e) { throw new RuntimeException("Error reading " + fileurl, e); } return fileContent; }
From source file:com.ngdata.hbaseindexer.mr.MRTestUtil.java
public static File substituteZkHost(File file, String zkConnectString) throws IOException { String str = Files.toString(file, Charsets.UTF_8); str = str.replace("_MYPATTERN_", zkConnectString); File tmp = File.createTempFile("tmpIndexer", ".xml"); tmp.deleteOnExit();//from w w w . ja v a2s .c om Files.write(str, tmp, Charsets.UTF_8); return tmp; }
From source file:com.tibco.businessworks6.sonar.plugin.source.DefaultSource.java
public boolean parseSource(Charset charset) { if (code == null || code.isEmpty()) { try {/*from w w w .j av a 2s .c o m*/ code = Files.toString(file, charset); } catch (IOException e) { return false; } return true; } return true; }