List of usage examples for com.google.common.io InputSupplier getInput
T getInput() throws IOException;
From source file:co.cask.cdap.internal.app.ApplicationSpecificationAdapter.java
public ApplicationSpecification fromJson(InputSupplier<? extends Reader> inputSupplier) throws IOException { try (Reader reader = inputSupplier.getInput()) { return fromJson(reader); }//from ww w. ja v a 2 s . c o m }
From source file:edu.cmu.cs.lti.ark.fn.parsing.LocalFeatureReading.java
private List<FrameFeatures> readLocalEventsFile(InputSupplier<? extends InputStream> eventsInputSupplier, List<FrameFeatures> frameFeaturesList) throws IOException { final InputStream input = eventsInputSupplier.getInput(); try {/* ww w . j a va2 s . c o m*/ return readLocalEventsFile(input, frameFeaturesList); } finally { closeQuietly(input); } }
From source file:iterator.util.Config.java
public void load(InputSupplier<? extends Reader> supplier) { try {//ww w. j a v a2s . c om Properties properties = new Properties(); properties.load(supplier.getInput()); load(properties); } catch (IOException ioe) { throw Throwables.propagate(ioe); } }
From source file:eu.esdihumboldt.hale.io.xml.validator.internal.SchemaResolver.java
/** * @see LSResourceResolver#resolveResource(String, String, String, String, * String)// www .j av a2 s . c o m */ @Override public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) { String schemaLocation; if (baseURI != null) { schemaLocation = baseURI.substring(0, baseURI.lastIndexOf("/") + 1); //$NON-NLS-1$ } else { String loc = mainSchemaURI.toString(); schemaLocation = loc.substring(0, loc.lastIndexOf("/") + 1); //$NON-NLS-1$ } if (systemId.indexOf("http://") < 0) { //$NON-NLS-1$ systemId = schemaLocation + systemId; } URI uri; try { uri = new URI(systemId); uri = uri.normalize(); } catch (URISyntaxException e1) { return null; } InputStream inputStream = null; // try resolving using (local) Resources try { InputSupplier<? extends InputStream> input = Resources.tryResolve(uri, Resources.RESOURCE_TYPE_XML_SCHEMA); if (input != null) { inputStream = input.getInput(); } } catch (Throwable e) { // ignore } // try resolving using cache if (inputStream == null) { try { inputStream = Request.getInstance().get(uri); } catch (Throwable e) { // ignore } } // fall-back if (inputStream == null) { try { inputStream = uri.toURL().openStream(); } catch (Throwable e) { return null; } } LSInput lsin = new LSInputImpl(); lsin.setSystemId(uri.toString()); lsin.setByteStream(inputStream); return lsin; }
From source file:org.eclipse.osee.jaxrs.server.internal.security.oauth2.provider.endpoints.ClientEndpoint.java
@GET @Path("{application-guid}/logo") @Produces({ "image/png", "image/jpeg", "image/gif" }) public Response getApplicationLogo(@Context final UriInfo uriInfo, @PathParam("application-guid") final String applicationGuid) { return Response.ok(new StreamingOutput() { @Override//w w w. j a v a 2 s .c o m public void write(OutputStream outputStream) throws IOException, WebApplicationException { InputSupplier<InputStream> supplier = getDataProvider().getClientLogoSupplier(uriInfo, applicationGuid); if (supplier != null) { InputStream inputStream = null; try { inputStream = supplier.getInput(); Lib.inputStreamToOutputStream(inputStream, outputStream); } finally { Lib.close(inputStream); } } } }).build(); }
From source file:com.facebook.buck.httpserver.TracesHelper.java
private Optional<String> parseCommandFrom(Path pathToTrace) { InputSupplier<? extends InputStream> inputSupplier = projectFilesystem .getInputSupplierForRelativePath(pathToTrace); try (JsonReader jsonReader = new JsonReader(new InputStreamReader(inputSupplier.getInput()))) { jsonReader.beginArray();/*from w w w. j a va 2 s . c om*/ Gson gson = new Gson(); JsonObject json = gson.fromJson(jsonReader, JsonObject.class); JsonElement nameEl = json.get("name"); if (nameEl == null || !nameEl.isJsonPrimitive()) { return Optional.absent(); } JsonElement argsEl = json.get("args"); if (argsEl == null || !argsEl.isJsonObject() || argsEl.getAsJsonObject().get("command_args") == null || !argsEl.getAsJsonObject().get("command_args").isJsonPrimitive()) { return Optional.absent(); } String name = nameEl.getAsString(); String commandArgs = argsEl.getAsJsonObject().get("command_args").getAsString(); String command = "buck " + name + " " + commandArgs; return Optional.of(command); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:de.cosmocode.palava.core.inject.csv.CsvReaderIterator.java
CsvReaderIterator(InputSupplier<? extends Reader> supplier, CsvStrategy strategy) throws IOException { Preconditions.checkNotNull(supplier, "Supplier"); Preconditions.checkNotNull(strategy, "Strategy"); final Reader input = Preconditions.checkNotNull(supplier.getInput(), "%s.getInput()", supplier); this.reader = new CSVReader(input, strategy.separator(), strategy.quote(), strategy.escape()); this.header = readNext(); Preconditions.checkArgument(header != null, "%s is empty", supplier); this.next = header; }
From source file:org.eclipse.osee.orcs.db.internal.search.tagger.TextStreamTagger.java
@Override public List<MatchLocation> find(InputSupplier<? extends InputStream> provider, String toSearch, boolean matchAllLocations, QueryOption... options) throws Exception { List<MatchLocation> toReturn; if (Strings.isValid(toSearch)) { InputStream inputStream = null; try {//from w ww.jav a2s. c o m inputStream = provider.getInput(); toReturn = getMatcher().findInStream(inputStream, toSearch, matchAllLocations, options); } finally { Lib.close(inputStream); } } else { toReturn = Collections.emptyList(); } return toReturn; }
From source file:eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier.java
/** * Resolve the given location and open an input stream. * //from w w w.ja va 2 s.c om * @param location the location * @return the input stream * @throws IOException if an error occurs opening the stream */ protected InputStream resolve(URI location) throws IOException { // try resolving using resources boolean triedLocal = false; if (location.getScheme().equals(SCHEME_LOCAL)) { // prefer local InputSupplier<? extends InputStream> localSupplier = Resources.tryResolve(location, null); if (localSupplier != null) { try { triedLocal = true; return localSupplier.getInput(); } catch (Throwable e) { // ignore } } } try { return Request.getInstance().get(location); } catch (Exception e) { // ignore } try { return location.toURL().openStream(); } catch (IOException ioe) { // try to resolve locally if (!triedLocal) { InputSupplier<? extends InputStream> localSupplier = Resources.tryResolve(location, null); if (localSupplier != null) { return localSupplier.getInput(); } } throw ioe; } }
From source file:co.cask.cdap.internal.app.deploy.pipeline.adapter.ConfigureAdapterStage.java
/** * Creates a {@link InMemoryConfigurator} to run through * the process of generation of {@link AdapterDefinition} * * @param deploymentInfo Location of the input and output location *///from w ww . j a v a2s. c o m @Override public void process(AdapterDeploymentInfo deploymentInfo) throws Exception { InMemoryAdapterConfigurator inMemoryAdapterConfigurator = new InMemoryAdapterConfigurator(cConf, namespace, templateJarLocation, adapterName, deploymentInfo.getAdapterConfig(), deploymentInfo.getTemplateSpec(), pluginRepository); ConfigResponse configResponse; try { configResponse = inMemoryAdapterConfigurator.config().get(120, TimeUnit.SECONDS); } catch (ExecutionException e) { if (e.getCause() instanceof Exception) { throw (Exception) e.getCause(); } throw e; } InputSupplier<? extends Reader> configSupplier = configResponse.get(); if (configResponse.getExitCode() != 0 || configSupplier == null) { throw new IllegalArgumentException("Failed to configure adapter: " + deploymentInfo); } try (Reader reader = configSupplier.getInput()) { emit(GSON.fromJson(reader, AdapterDefinition.class)); } }