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.apache.ranger.policyengine.perftest.v2.RangerPolicyFactory.java
public static String readResourceFile(String fileName) { try {/*from w w w .j a v a2 s. c o m*/ File f = new File(RangerPolicyFactory.class.getResource(fileName).toURI()); checkState(f.exists() && f.isFile() && f.canRead()); return Files.toString(f, Charsets.UTF_8); } catch (Exception e) { throw Throwables.propagate(e); } }
From source file:io.reactivesocket.cli.Main.java
private PayloadImpl singleInputPayload() { String inputString;/* w ww. j ava 2s .c o m*/ if (input == null) { Scanner in = new Scanner(System.in); inputString = in.nextLine(); } else if (input.startsWith("@")) { try { inputString = Files.toString(inputFile(), StandardCharsets.UTF_8); } catch (IOException e) { throw new UsageException(e.toString()); } } else { inputString = input; } return new PayloadImpl(inputString, ""); }
From source file:lombok.ast.app.Main.java
private void process(File in, File outDir, String relativeName) throws IOException { File out = outDir == null ? null : new File(outDir, relativeName); if (verbose && !saveIntermediate) { System.out.printf("Processing: %s to %s\n", in.getCanonicalPath(), out == null ? "sysout" : out.getCanonicalPath()); }//from www . j av a 2 s . c o m Source source = new Source(Files.toString(in, charset), in.getCanonicalPath()); Object transfer = null; String chain = "/"; try { for (Operation<Object, Object> programElem : program) { transfer = programElem.process(source, transfer); if (saveIntermediate) { if (!"/".equals(chain)) { chain += "-"; } chain += getDestinationType(programElem); File intermediate = new File(outDir.getCanonicalPath() + chain + "/" + relativeName); intermediate.getParentFile().mkdirs(); if (verbose) { System.out.printf("Processing: %s to %s\n", in.getCanonicalPath(), intermediate.getCanonicalPath()); } if (TO_JAVAC.contains(programElem)) { Files.write(javacToText.process(source, (JCCompilationUnit) transfer).toString(), intermediate, charset); } else if (TO_ECJ.contains(programElem)) { Files.write(ecjToText.process(source, (CompilationUnitDeclaration) transfer).toString(), intermediate, charset); } else if (TO_LOMBOK.contains(programElem)) { Files.write(lombokToText.process(source, (Node) transfer).toString(), intermediate, charset); } } } if (out == null) { System.out.println(transfer); } else if (!saveIntermediate) { out.getParentFile().mkdirs(); Files.write(transfer.toString(), out, charset); } } catch (ConversionProblem cp) { System.err.printf("Can't convert: %s due to %s\n", in.getCanonicalPath(), cp.getMessage()); errors++; } catch (RuntimeException e) { System.err.printf("Error during convert: %s\n%s\n", in.getCanonicalPath(), printEx(e)); errors++; } }
From source file:fr.obeo.releng.targetplatform.pde.Converter.java
private boolean hasContentDifferencesOtherThanSequenceNumber(URI targetDefinitionLocation, String xml) { try {/*from ww w .j a v a2 s.c om*/ File targetDefinition = new File(targetDefinitionLocation.toFileString()); if (targetDefinition.exists()) { String oldXml = Files.toString(targetDefinition, Charsets.UTF_8); oldXml = SEQUENCE_NUMBER__PATTERN.matcher(oldXml).replaceFirst(""); String newXml = SEQUENCE_NUMBER__PATTERN.matcher(xml).replaceFirst(""); return !oldXml.equals(newXml); } } catch (IOException e) { TargetPlatformBundleActivator.getInstance().getLog() .log(new Status(IStatus.ERROR, TargetPlatformBundleActivator.PLUGIN_ID, e.getMessage())); } return true; }
From source file:ch.raffael.doclets.pegdown.PegdownDoclet.java
/** * Process the overview file, if specified. *//* w w w .j a va 2s.c om*/ protected void processOverview() { if (options.getOverviewFile() != null) { try { rootDoc.setRawCommentText(Files.toString(options.getOverviewFile(), options.getEncoding())); defaultProcess(rootDoc, false); } catch (IOException e) { printError("Error loading overview from " + options.getOverviewFile() + ": " + e.getLocalizedMessage()); rootDoc.setRawCommentText(""); } } }
From source file:com.hazelcast.jclouds.ComputeServiceBuilder.java
public String getCredentialFromFile(String provider, String credentialPath) throws IllegalArgumentException { try {/* ww w . j av a 2s . c o m*/ String fileContents = Files.toString(new File(credentialPath), Charsets.UTF_8); if (provider.equals(GOOGLE_COMPUTE_ENGINE)) { Supplier<Credentials> credentialSupplier = new GoogleCredentialsFromJson(fileContents); return credentialSupplier.get().credential; } return fileContents; } catch (IOException e) { throw new InvalidConfigurationException( "Failed to retrieve the private key from the file: " + credentialPath, e); } }
From source file:io.hops.hopsworks.ca.api.certs.CertSigningService.java
@POST @Path("/hopsworks") @AllowCORS//from w ww .j a v a 2 s. c om @RolesAllowed({ "AGENT", "CLUSTER_AGENT" }) @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response hopsworks(@Context HttpServletRequest req, @Context SecurityContext sc, String jsonString) throws GenericException { JSONObject json = new JSONObject(jsonString); String pubAgentCert = "no certificate"; String caPubCert = "no certificate"; String intermediateCaPubCert = "no certificate"; if (json.has("csr")) { String csr = json.getString("csr"); try { pubAgentCert = delaTrackerCertController.signCsr(sc.getUserPrincipal().getName(), csr); caPubCert = Files.toString(new File(settings.getCertsDir() + "/certs/ca.cert.pem"), Charsets.UTF_8); intermediateCaPubCert = Files.toString( new File(settings.getIntermediateCaDir() + "/certs/intermediate.cert.pem"), Charsets.UTF_8); } catch (IOException | DelaCSRCheckException ex) { throw new GenericException(RESTCodes.GenericErrorCode.UNKNOWN_ERROR, Level.SEVERE, null, ex.getMessage(), ex); } } CsrDTO dto = new CsrDTO(caPubCert, intermediateCaPubCert, pubAgentCert, settings.getHadoopVersionedDir()); return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(dto).build(); }
From source file:org.apache.bookkeeper.mledger.offload.jcloud.impl.BlobStoreManagedLedgerOffloader.java
public static Credentials getCredentials(String driver, TieredStorageConfigurationData conf) throws IOException { // credentials: // for s3, get by DefaultAWSCredentialsProviderChain. // for gcs, use downloaded file 'google_creds.json', which contains service account key by // following instructions in page https://support.google.com/googleapi/answer/6158849 if (isGcsDriver(driver)) { String gcsKeyPath = conf.getGcsManagedLedgerOffloadServiceAccountKeyFile(); if (Strings.isNullOrEmpty(gcsKeyPath)) { throw new IOException("The service account key path is empty for GCS driver"); }/*w w w . j a v a 2 s .co m*/ try { String gcsKeyContent = Files.toString(new File(gcsKeyPath), Charset.defaultCharset()); return new GoogleCredentialsFromJson(gcsKeyContent).get(); } catch (IOException ioe) { log.error("Cannot read GCS service account credentials file: {}", gcsKeyPath); throw new IOException(ioe); } } else if (isS3Driver(driver)) { AWSCredentials credentials = null; try { DefaultAWSCredentialsProviderChain creds = DefaultAWSCredentialsProviderChain.getInstance(); credentials = creds.getCredentials(); } catch (Exception e) { // allowed, some mock s3 service not need credential log.warn("Exception when get credentials for s3 ", e); } String id = "accesskey"; String key = "secretkey"; if (credentials != null) { id = credentials.getAWSAccessKeyId(); key = credentials.getAWSSecretKey(); } return new Credentials(id, key); } else { throw new IOException("Not support this kind of driver: " + driver); } }
From source file:com.android.repository.io.impl.FileOpImpl.java
@NonNull @Override public String toString(@NonNull File f, @NonNull Charset c) throws IOException { return Files.toString(f, c); }
From source file:org.sonar.java.SonarComponents.java
public String fileContent(File file) { try {/*www . j ava 2s. co m*/ if (isSQGreaterThan62()) { return inputFromIOFile(file).contents(); } return Files.toString(file, getCharset(file)); } catch (IOException e) { throw new AnalysisException("Unable to read file " + file, e); } }