List of usage examples for com.google.common.io InputSupplier InputSupplier
InputSupplier
From source file:org.eclipse.osee.jaxrs.server.internal.security.oauth2.provider.adapters.ClientProviderImpl.java
@Override public Client createClient(UriInfo uriInfo, OseePrincipal principal, final ClientFormData data) { String guid = data.getGuid(); long clientUuid = Lib.generateUuid(); long subjectId = subjectProvider.getSubjectId(data.getUserSubject()); ApplicationClient client = new ApplicationClient(clientUuid, subjectId, guid); client.setSubject(data.getUserSubject()); client.setApplicationName(data.getName()); client.setApplicationDescription(data.getDescription()); client.setApplicationWebUri(data.getWebUri()); client.setProperties(data.getProperties()); client.setConfidential(data.isConfidential()); /**//from w w w . j a v a 2 s . c o m * generate credentials */ String clientId = OAuthUtils.generateRandomTokenKey(); client.setClientId(clientId); if (client.isConfidential()) { String clientSecret = OAuthUtils.generateRandomTokenKey(); client.setClientSecret(clientSecret); } /** * <pre> * Additional Security options: * - restrict resource server * - restrict allowed grant types * - register allowed scopes/permissions * - restrict redirect/callback URIs * - authenticate using certificate * </pre> */ client.setRegisteredAudiences(data.getAllowedAudiences()); client.setAllowedGrantTypes(data.getAllowedGrantTypes()); client.setRegisteredScopes(data.getAllowedScopes()); client.setRedirectUris(data.getRedirectUris()); client.setApplicationCertificates(data.getCertificates()); client.setApplicationLogoUri(data.getLogoUri()); if (data.isLogoAvailable()) { InputSupplier<InputStream> logoSupplier = new InputSupplier<InputStream>() { @Override public InputStream getInput() { return data.getLogoContent(); } }; client.setApplicationLogoSupplier(logoSupplier); } storage.storeClient(principal, client); return client; }
From source file:co.cask.tigon.flow.DeployClient.java
private static InputSupplier<InputStream> getInputSupplier(final FlowSpecification flowSpec) { return new InputSupplier<InputStream>() { @Override/* w w w. j av a 2 s . co m*/ public InputStream getInput() throws IOException { String json = FlowSpecificationAdapter.create(new ReflectionSchemaGenerator()).toJson(flowSpec); return new ByteArrayInputStream(json.getBytes(Charsets.UTF_8)); } }; }
From source file:de.cosmocode.palava.store.FileSystemStore.java
private InputSupplier<InputStream> asSupplier(final InputStream stream) { return new InputSupplier<InputStream>() { @Override/* w ww . j a va 2 s . c o m*/ public InputStream getInput() throws IOException { return stream; } }; }
From source file:co.cask.tigon.internal.app.runtime.distributed.AbstractDistributedProgramRunner.java
/** * Copies the program jar to a local temp file and return a {@link Program} instance * with {@link Program#getJarLocation()} points to the local temp file. *//*from w w w. ja v a2 s . c om*/ private Program copyProgramJar(final Program program, File programDir) throws IOException { File tempJar = File.createTempFile(program.getName(), ".jar"); Files.copy(new InputSupplier<InputStream>() { @Override public InputStream getInput() throws IOException { return program.getJarLocation().getInputStream(); } }, tempJar); final Location jarLocation = new LocalLocationFactory().create(tempJar.toURI()); return Programs.createWithUnpack(jarLocation, programDir); }
From source file:org.stjs.generator.Generator.java
/** * This method copies the Javascript support file (stjs.js currently) to the desired folder. This method should be * called after the processing of all the files. * /*from w ww.j a v a 2 s .c o m*/ * @param folder */ public void copyJavascriptSupport(File folder) { final InputStream stjs = Thread.currentThread().getContextClassLoader().getResourceAsStream(STJS_FILE); if (stjs == null) { throw new RuntimeException(STJS_FILE + " is missing from the Generator's classpath"); } File outputFile = new File(folder, STJS_FILE); try { Files.copy(new InputSupplier<InputStream>() { @Override public InputStream getInput() throws IOException { return stjs; } }, outputFile); } catch (IOException e) { throw new RuntimeException("Could not copy the " + STJS_FILE + " file to the folder " + folder, e); } finally { try { stjs.close(); } catch (IOException e) { // silent } } }
From source file:co.cask.cdap.data2.transaction.queue.coprocessor.hbase96.HBaseQueueRegionObserver.java
private ConsumerConfigCache createConfigCache(final CoprocessorEnvironment env) { return ConsumerConfigCache.getInstance(configTableName, cConfReader, txSnapshotSupplier, new InputSupplier<HTableInterface>() { @Override/*from www . j a v a 2 s .c o m*/ public HTableInterface getInput() throws IOException { return env.getTable(configTableName); } }); }
From source file:org.fusesource.process.manager.support.ProcessManagerImpl.java
protected void untarTarball(final String url, File installDir) throws IOException, CommandFailedException { // copy the URL to the install dir // TODO should we use a temp file? File tarball = new File(installDir, "install.tar.gz"); Files.copy(new InputSupplier<InputStream>() { @Override// w ww. ja va 2 s . c om public InputStream getInput() throws IOException { return new URL(url).openStream(); } }, tarball); FileUtils.extractTar(tarball, installDir, untarTimeout, executor); }
From source file:org.eclipse.osee.jaxrs.server.internal.security.oauth2.provider.adapters.ClientProviderImpl.java
private InputSupplier<InputStream> newSupplier(final String uri) { return new InputSupplier<InputStream>() { @Override// w ww .j a v a2 s . c o m public InputStream getInput() throws IOException { CachedOutputStream cos; try { cos = logosCache.get(uri); } catch (ExecutionException ex) { throw new IOException(ex); } return cos.getInputStream(); } }; }
From source file:org.fusesource.process.manager.service.ProcessManagerService.java
@Override public Installation installJar(final InstallOptions parameters) throws Exception { @SuppressWarnings("serial") InstallTask installTask = new InstallTask() { @Override//from w ww . ja v a 2s . com public void install(ProcessConfig config, int id, File installDir) throws Exception { config.setName(parameters.getName()); // lets untar the process launcher String resourceName = "process-launcher.tar.gz"; final InputStream in = getClass().getClassLoader().getResourceAsStream(resourceName); Preconditions.checkNotNull(in, "Could not find " + resourceName + " on the file system"); File tmpFile = File.createTempFile("process-launcher", ".tar.gz"); Files.copy(new InputSupplier<InputStream>() { @Override public InputStream getInput() throws IOException { return in; } }, tmpFile); FileUtils.extractArchive(tmpFile, installDir, "tar zxf", untarTimeout, executor); // lets generate the etc configs File etc = new File(installDir, "etc"); etc.mkdirs(); Files.write("", new File(etc, "config.properties"), Charsets.UTF_8); Files.write("", new File(etc, "jvm.config"), Charsets.UTF_8); JarInstaller installer = new JarInstaller(executor); installer.unpackJarProcess(config, id, installDir, parameters); } }; return installViaScript(parameters.getControllerUrl(), installTask); }
From source file:com.continuuity.weave.internal.appmaster.ApplicationMasterService.java
private String loadJvmOptions() throws IOException { final File jvmOptsFile = new File(Constants.Files.JVM_OPTIONS); if (!jvmOptsFile.exists()) { return ""; }/*w ww . ja v a 2 s .c o m*/ return CharStreams.toString(new InputSupplier<Reader>() { @Override public Reader getInput() throws IOException { return new FileReader(jvmOptsFile); } }); }