List of usage examples for com.google.common.io CharStreams toString
public static String toString(Readable r) throws IOException
From source file:org.robotframework.ide.eclipse.main.plugin.refactoring.RedXmlEditsCollector.java
List<TextEdit> collectEditsInExcludedPaths(final String projectName, final IFile redXmlFile) { try (BufferedReader fileReader = new BufferedReader(new InputStreamReader(redXmlFile.getContents()))) { final IDocument document = new Document(CharStreams.toString(fileReader)); return collectEditsInExcludedPaths(projectName, new MatchesInDocumentEngine(document)); } catch (IOException | CoreException e) { return new ArrayList<>(); }/* w ww . j a va2s. c o m*/ }
From source file:pl.psi.licensing.boundary.GeneralAdministrationEndpoint.java
/** * Endpoint for uploading a new license/* w ww .ja va 2s . co m*/ */ @POST @Path("/uploadNewLicense") @Consumes(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.APPLICATION_JSON) public Response uploadNewLicense(InputStream license) { String licenseText = ""; try { licenseText = CharStreams.toString(new InputStreamReader(license, Charsets.UTF_8)); } catch (IOException e) { e.printStackTrace(); } LicensingSystemResponse resp = licenseService.introduceNewLicense(licenseText); return Response.ok(resp).build(); }
From source file:com.brainardphotography.gravatar.GravatarProfileURL.java
public String getText(GravatarProfileFormat format) throws IOException { if (format.getContentType() == ContentType.BINARY) throw new IllegalArgumentException("'getAsText' doesn't support BINARY content types."); URL url = toURL(format);/* w ww .ja va 2 s .c o m*/ try (InputStream input = url.openStream()) { return CharStreams.toString(new InputStreamReader(input)); } }
From source file:com.ondeck.datapipes.http.HttpConnectorResponseHandler.java
@Override public HttpConnectorResponse handleResponse(HttpResponse response) throws IOException { StatusLine statusLine = response.getStatusLine(); HttpEntity httpEntity = response.getEntity(); String content = httpEntity == null ? null : CharStreams.toString(new InputStreamReader(httpEntity.getContent())); return new HttpConnectorResponse(statusLine.getStatusCode(), content); }
From source file:ch.fancytools.ballbotsche.restresource.RegisterResource.java
@GET @Produces(MediaType.TEXT_HTML)/*from ww w . j av a2s . c om*/ public String deliverRegisterPage() { try { InputSupplier<? extends InputStream> supplier = new InputSupplier<InputStream>() { @Override public InputStream getInput() throws IOException { return getClass().getClassLoader().getResourceAsStream("register.html"); } }; return CharStreams.toString(CharStreams.newReaderSupplier(supplier, Charset.forName("UTF-8"))); } catch (IOException ex) { java.util.logging.Logger.getLogger(RegisterResource.class.getName()).log(Level.SEVERE, null, ex); return "failed, hard."; } }
From source file:io.macgyver.plugin.git.GitResourceImpl.java
@Override public String getContentAsString() throws IOException { try (InputStreamReader reader = new InputStreamReader(openInputStream(), Charsets.UTF_8)) { String text = CharStreams.toString(reader); return text; }//from w w w .jav a 2s . co m }
From source file:com.ericsson.gerrit.plugins.highavailability.forwarder.rest.EventRestApiServlet.java
private static Event getEventFromRequest(HttpServletRequest req) throws IOException { String jsonEvent = CharStreams.toString(req.getReader()); Gson gson = new GsonBuilder().registerTypeAdapter(Event.class, new EventDeserializer()) .registerTypeAdapter(Supplier.class, new SupplierDeserializer()).create(); return gson.fromJson(jsonEvent, Event.class); }
From source file:com.android.build.gradle.integration.common.truth.AarSubject.java
@NonNull public StringSubject textSymbolFile() throws IOException { InputStream stream = getInputStream("R.txt"); return new StringSubject(failureStrategy, CharStreams.toString(new InputStreamReader(stream, Charsets.UTF_8))); }
From source file:com.netflix.exhibitor.core.state.FourLetterWord.java
public FourLetterWord(Word word, String hostname, InstanceConfig config, int connectionTimeOutMs) { Preconditions.checkNotNull(word);//from w ww. j av a 2 s . co m String localResponse = ""; Socket s = null; try { s = new Socket(hostname, config.getInt(IntConfigs.CLIENT_PORT)); s.setTcpNoDelay(true); s.setSoTimeout(connectionTimeOutMs); s.getOutputStream().write(word.name().toLowerCase().getBytes()); s.getOutputStream().flush(); localResponse = CharStreams.toString(new InputStreamReader(s.getInputStream())); } catch (Exception e) { // ignore - treat as server not running } finally { try { if (s != null) { s.close(); } } catch (IOException e) { // ignore } } response = localResponse; }
From source file:org.cicomponents.badges.impl.ShieldStyleFlatBadgeMaker.java
@SneakyThrows @Override// w w w .j av a2 s. c o m public byte[] make(BadgeProperty... properties) { java.util.List<BadgeProperty> props = Arrays.asList(properties); BadgeSubject subject = (BadgeSubject) props.stream().filter(prop -> prop instanceof BadgeSubject) .findFirst().orElse(BadgeMaker.subject("Unknown")); BadgeStatus status = (BadgeStatus) props.stream().filter(prop -> prop instanceof BadgeStatus).findFirst() .orElse(BadgeMaker.status("unknown")); BadgeColor color = (BadgeColor) props.stream().filter(prop -> prop instanceof BadgeColor).findFirst() .orElse(BadgeMaker.color("#555")); BadgeStatusColor statusColor = (BadgeStatusColor) props.stream() .filter(prop -> prop instanceof BadgeStatusColor).findFirst() .orElse(BadgeMaker.statusColor("#4c1")); int subjectWidth = measureText(subject.getText()); int statusWidth = measureText(status.getText()); if (subjectWidth % 2 == 0) { subjectWidth++; } if (statusWidth % 2 == 0) { statusWidth++; } subjectWidth += 10; statusWidth += 10; int width = subjectWidth + statusWidth; String template = CharStreams .toString(new InputStreamReader(getClass().getResourceAsStream("shield-flat.svg.template"))); String svg = template.replaceAll("\\{\\{width\\}\\}", String.valueOf(width)) .replaceAll("\\{\\{subjectWidth\\}\\}", String.valueOf(subjectWidth)) .replaceAll("\\{\\{statusWidth\\}\\}", String.valueOf(statusWidth)) .replaceAll("\\{\\{halfWidth\\}\\}", String.valueOf(subjectWidth / 2)) .replaceAll("\\{\\{quarterWidth\\}\\}", String.valueOf(subjectWidth + (statusWidth / 2 - 1))) .replaceAll("\\{\\{subject\\}\\}", subject.getText()) .replaceAll("\\{\\{status\\}\\}", status.getText()) .replaceAll("\\{\\{color\\}\\}", colorscheme.getOrDefault(color.getText(), color.getText())) .replaceAll("\\{\\{alternateColor\\}\\}", colorscheme.getOrDefault(statusColor.getText(), statusColor.getText())); return svg.getBytes(); }