List of usage examples for com.google.common.io Files toString
public static String toString(File file, Charset charset) throws IOException
From source file:org.spdx.rdfparser.model.UnitTestHelper.java
/** * @param filePath Path for file//w w w . j av a 2s . c o m * @return Text from the file * @throws IOException */ public static String fileToText(String filePath) throws IOException { return Files.toString(new File(filePath), Charset.forName("UTF-8")); }
From source file:org.jclouds.examples.minecraft.Utils.java
public static LoginCredentials currentUser() { String privateKeyKeyFile = System.getProperty("user.home") + "/.ssh/id_rsa"; String privateKey;//from w w w . ja v a 2s. c om try { privateKey = Files.toString(new File(privateKeyKeyFile), UTF_8); } catch (IOException e) { throw propagate(e); } assert privateKey.startsWith("-----BEGIN RSA PRIVATE KEY-----") : "invalid key:\n" + privateKey; return LoginCredentials.builder().user(System.getProperty("user.name")).privateKey(privateKey).build(); }
From source file:datamine.mojo.storage.TableInterfaceGenerationMojo.java
public void execute() throws MojoExecutionException, MojoFailureException { validateArguments();//from w w w . j ava 2s . co m InterfaceGenerator generator = new InterfaceGenerator(outputDirectory.getAbsolutePath(), packageName); try { // generate the java source codes Schema schema = new JsonSchemaConvertor().apply(Files.toString(schemaPath, Charsets.UTF_8)); schema.accept(generator); generator.generate(); } catch (IOException e) { throw new MojoExecutionException("Error generating Java interfaces for table access!", e); } }
From source file:org.mapstruct.ap.testutil.assertions.JavaFileAssert.java
/** * @return assertion on the file content *//*from w w w . ja v a 2 s.c om*/ public AbstractCharSequenceAssert<?, String> content() { exists(); isFile(); try { return Assertions.assertThat(Files.toString(actual, Charsets.UTF_8)); } catch (IOException e) { failWithMessage("Unable to read" + actual.toString() + ". Exception: " + e.getMessage()); } return null; }
From source file:net.sf.lucis.core.impl.ReindexingFSStore.java
private static Status readStatus(File file) { if (!file.exists()) { return Status.NULL; }/*from w ww. j a v a 2s.co m*/ try { String str = Files.toString(file, Charsets.UTF_8); if (str == null || str.length() == 0) { return Status.NULL; } str = str.trim(); if (str.length() == 0) { return Status.NULL; } try { return Enum.valueOf(Status.class, str); } catch (IllegalArgumentException e) { return Status.NULL; } } catch (FileNotFoundException fnfe) { // Nothing. } catch (IOException e) { throw new IllegalStateException(e); } return Status.NULL; }
From source file:org.artifactory.converters.MimeTypeConverter.java
@Override public void convert(CompoundVersionDetails source, CompoundVersionDetails target) { if (!path.exists()) { throw new RuntimeException( "Couldn't start Artifactory. Mime types file is missing: " + path.getAbsolutePath()); }// w ww . ja v a 2 s. c om try { String mimeTypesXml = Files.toString(path, Charsets.UTF_8); MimeTypesVersion mimeTypesVersion = MimeTypesVersion.findVersion(mimeTypesXml); if (!mimeTypesVersion.isCurrent()) { String result = mimeTypesVersion.convert(mimeTypesXml); Files.write(result, path, Charsets.UTF_8); } } catch (Exception e) { throw new RuntimeException("Failed to execute mimetypes conversion", e); } }
From source file:com.google.javascript.refactoring.ApplySuggestedFixes.java
/** * Applies the provided set of suggested fixes to the files listed in the suggested fixes. * The fixes can be provided in any order, but they may not have any overlapping modifications * for the same file./* w ww . j a va 2s. co m*/ */ public static void applySuggestedFixesToFiles(Iterable<SuggestedFix> fixes) throws IOException { Set<String> filenames = new HashSet<>(); for (SuggestedFix fix : fixes) { filenames.addAll(fix.getReplacements().keySet()); } Map<String, String> filenameToCodeMap = new HashMap<>(); for (String filename : filenames) { filenameToCodeMap.put(filename, Files.toString(new File(filename), UTF_8)); } Map<String, String> newCode = applySuggestedFixesToCode(fixes, filenameToCodeMap); for (Map.Entry<String, String> entry : newCode.entrySet()) { Files.write(entry.getValue(), new File(entry.getKey()), UTF_8); } }
From source file:org.springframework.xd.test.generator.SimpleHttpGenerator.java
@Override public void postFromFile(File file) { Assert.notNull(file, "file must not be null"); try {//from www. j a v a 2 s .c o m restTemplate.postForObject(url, Files.toString(file, Charset.defaultCharset()), String.class); } catch (IOException e) { throw new GeneratorException("Could not read from file [" + file + "]", e); } }
From source file:symbolicexecutor.FileLoader.java
/** * Reads all characters from a file into a String, using the base path unless * the file's path name is absolute.//from w ww.j ava 2s .c o m * @see Files#toString() */ public String toString(String filename) throws IOException { return Files.toString(new File(getPath(filename)), Charset.defaultCharset()); }
From source file:org.apache.lens.server.ui.StaticFileResource.java
/** * Load file./*from w ww . j a va 2 s . c o m*/ * * @param baseDir the base dir * @param filePath the file path * @return the string * @throws IOException Signals that an I/O exception has occurred. */ private static String loadFile(String baseDir, String filePath) throws IOException { return Files.toString(new File(baseDir, filePath), Charset.forName("UTF-8")); }