List of usage examples for com.google.common.io InputSupplier InputSupplier
InputSupplier
From source file:net.ripe.rpki.commons.provisioning.cms.ProvisioningCmsObjectParser.java
/** * http://tools.ietf.org/html/draft-ietf-sidr-rescerts-provisioning-09#section-3.1.1.3.2 *///from w ww . j a v a 2 s . c o m private void parseContent() { try { final InputSupplier<InputStream> supplier = new InputSupplier<InputStream>() { @Override public InputStream getInput() throws IOException { return sp.getSignedContent().getContentStream(); } }; final String payloadXml = CharStreams.toString(CharStreams.newReaderSupplier(supplier, Charsets.UTF_8)); payload = PayloadParser.parse(payloadXml, validationResult); validationResult.rejectIfFalse(true, CMS_CONTENT_PARSING); } catch (IOException e) { validationResult.rejectIfFalse(false, CMS_CONTENT_PARSING); } }
From source file:com.facebook.buck.parser.Parser.java
public Parser(final ProjectFilesystem projectFilesystem, KnownBuildRuleTypes buildRuleTypes, Console console, String pythonInterpreter, ImmutableSet<Pattern> tempFilePatterns, RuleKeyBuilderFactory ruleKeyBuilderFactory) { this(projectFilesystem, buildRuleTypes, console, /* Calls to get() will reconstruct the build file tree by calling constructBuildFileTree. */ new InputSupplier<BuildFileTree>() { @Override/*from w w w .j ava2 s . c om*/ public BuildFileTree getInput() throws IOException { return BuildFileTree.constructBuildFileTree(projectFilesystem); } }, new BuildTargetParser(projectFilesystem), /* knownBuildTargets */ Maps.<BuildTarget, BuildRuleBuilder<?>>newHashMap(), new DefaultProjectBuildFileParserFactory(projectFilesystem, pythonInterpreter, buildRuleTypes.getAllDescriptions()), tempFilePatterns, ruleKeyBuilderFactory); }
From source file:org.fusesource.process.manager.service.ProcessManagerService.java
protected void downloadContent(final URL url, File installDir) throws IOException, CommandFailedException { // copy the URL to the install dir File archive = new File(installDir, INSTALLED_BINARY); Files.copy(new InputSupplier<InputStream>() { @Override//from www . ja va 2 s .co m public InputStream getInput() throws IOException { return url.openStream(); } }, archive); }
From source file:co.cask.cdap.cli.CLIConfig.java
private String tryGetVersion() { try {/*w w w. ja va 2 s . c om*/ InputSupplier<? extends InputStream> versionFileSupplier = new InputSupplier<InputStream>() { @Override public InputStream getInput() throws IOException { return VersionCommand.class.getClassLoader().getResourceAsStream("VERSION"); } }; return CharStreams.toString(CharStreams.newReaderSupplier(versionFileSupplier, Charsets.UTF_8)); } catch (IOException e) { throw Throwables.propagate(e); } }
From source file:com.google.appinventor.buildserver.ProjectBuilder.java
private ArrayList<String> extractProjectFiles(ZipFile inputZip, File projectRoot) throws IOException { ArrayList<String> projectFileNames = Lists.newArrayList(); Enumeration<? extends ZipEntry> inputZipEnumeration = inputZip.entries(); while (inputZipEnumeration.hasMoreElements()) { ZipEntry zipEntry = inputZipEnumeration.nextElement(); final InputStream extractedInputStream = inputZip.getInputStream(zipEntry); File extractedFile = new File(projectRoot, zipEntry.getName()); LOG.info("extracting " + extractedFile.getAbsolutePath() + " from input zip"); Files.createParentDirs(extractedFile); // Do I need this? Files.copy(new InputSupplier<InputStream>() { public InputStream getInput() throws IOException { return extractedInputStream; }//from w w w . jav a 2 s. c o m }, extractedFile); projectFileNames.add(extractedFile.getPath()); } return projectFileNames; }
From source file:io.fabric8.process.manager.service.ProcessManagerService.java
@Override public Installation installJar(final InstallOptions parameters, final InstallTask postInstall) throws Exception { @SuppressWarnings("serial") InstallTask installTask = new InstallTask() { @Override/*from ww w . ja v a 2 s.c o m*/ public void install(InstallContext installContext, ProcessConfig config, String 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"); if (etc.mkdirs()) { LOGGER.debug("Creating etc directory {} of process {}.", etc, id); } else { LOGGER.debug("Directory etc {} of process {} exists. Skipping.", etc, id); } Files.write("", new File(etc, "config.properties"), Charsets.UTF_8); writeJvmConfig(etc, parameters.getJvmOptions()); JarInstaller installer = new JarInstaller(parameters, executor); installer.install(installContext, config, id, installDir); if (postInstall != null) { postInstall.install(installContext, config, id, installDir); } } }; return installViaScript(parameters, installTask); }
From source file:de.chaosfisch.google.youtube.upload.UploadJob.java
private void uploadChunk() throws IOException, UploadResponseException, UploadFinishedException { // GET END SIZE final long end = generateEndBytes(start, bytesToUpload); // Log operation LOGGER.debug("start={} end={} filesize={}", start, end, fileSize); // Log operation LOGGER.debug("Uploaded {} bytes so far, using PUT method.", totalBytesUploaded); if (null == uploadProgress) { uploadProgress = new UploadJobProgressEvent(upload, upload.getFile().length()); uploadProgress.setTime(Calendar.getInstance().getTimeInMillis()); }/* w w w . j a v a 2 s. c o m*/ // Calculating the chunk size final int chunk = (int) (end - start + 1); // Building PUT RequestImpl for chunk data final URL url = URI.create(upload.getUploadurl()).toURL(); final HttpURLConnection request = (HttpURLConnection) url.openConnection(); request.setRequestMethod("POST"); request.setDoOutput(true); request.setFixedLengthStreamingMode(chunk); //Properties request.setRequestProperty("Content-Type", upload.getMimetype()); request.setRequestProperty("Content-Range", String.format("bytes %d-%d/%d", start, end, fileToUpload.length())); request.setRequestProperty("Authorization", getAuthHeader()); request.setRequestProperty("GData-Version", GDATAConfig.GDATA_V2); request.setRequestProperty("X-GData-Key", String.format("key=%s", GDATAConfig.DEVELOPER_KEY)); request.connect(); try (final TokenInputStream tokenInputStream = new TokenInputStream(new FileInputStream(upload.getFile())); final BufferedOutputStream throttledOutputStream = new BufferedOutputStream( request.getOutputStream())) { tokenInputStream.skip(start); flowChunk(tokenInputStream, throttledOutputStream, start, end); switch (request.getResponseCode()) { case SC_OK: case SC_CREATED: //FILE UPLOADED final InputSupplier<InputStream> supplier = new InputSupplier<InputStream>() { @Override public InputStream getInput() throws IOException { return request.getInputStream(); } }; handleSuccessfulUpload( CharStreams.toString(CharStreams.newReaderSupplier(supplier, Charsets.UTF_8))); break; case SC_RESUME_INCOMPLETE: // OK, the chunk completed succesfully LOGGER.debug("responseMessage={}", request.getResponseMessage()); break; default: throw new UploadResponseException(request.getResponseCode()); } bytesToUpload -= chunkSize; start = end + 1; } }
From source file:com.metamx.druid.merger.coordinator.ForkingTaskRunner.java
@Override public Optional<InputSupplier<InputStream>> streamTaskLog(final String taskid, final long offset) { final ProcessHolder processHolder; synchronized (tasks) { final TaskInfo taskInfo = tasks.get(taskid); if (taskInfo != null && taskInfo.processHolder != null) { processHolder = taskInfo.processHolder; } else {// w w w . j a v a2 s . c o m return Optional.absent(); } } return Optional.<InputSupplier<InputStream>>of(new InputSupplier<InputStream>() { @Override public InputStream getInput() throws IOException { final RandomAccessFile raf = new RandomAccessFile(processHolder.logFile, "r"); final long rafLength = raf.length(); if (offset > 0) { raf.seek(offset); } else if (offset < 0 && offset < rafLength) { raf.seek(rafLength + offset); } return Channels.newInputStream(raf.getChannel()); } }); }
From source file:com.metamx.druid.indexing.coordinator.RemoteTaskRunner.java
@Override public Optional<InputSupplier<InputStream>> streamTaskLog(final String taskId, final long offset) { final ZkWorker zkWorker = findWorkerRunningTask(taskId); if (zkWorker == null) { // Worker is not running this task, it might be available in deep storage return Optional.absent(); } else {/* w ww.java 2s. co m*/ // Worker is still running this task final URL url = makeWorkerURL(zkWorker.getWorker(), String.format("/task/%s/log?offset=%d", taskId, offset)); return Optional.<InputSupplier<InputStream>>of(new InputSupplier<InputStream>() { @Override public InputStream getInput() throws IOException { try { return httpClient.get(url).go(new InputStreamResponseHandler()).get(); } catch (InterruptedException e) { throw Throwables.propagate(e); } catch (ExecutionException e) { // Unwrap if possible Throwables.propagateIfPossible(e.getCause(), IOException.class); throw Throwables.propagate(e); } } }); } }
From source file:org.eclipse.andmore.integration.tests.SdkTestCase.java
protected File makeTestFile(File dir, String name, String relative, final InputStream contents) throws IOException { if (relative != null) { dir = new File(dir, relative); if (!dir.exists()) { boolean mkdir = dir.mkdirs(); assertTrue(dir.getPath(), mkdir); }/* w w w . j a v a2 s .c o m*/ } else if (!dir.exists()) { boolean mkdir = dir.mkdirs(); assertTrue(dir.getPath(), mkdir); } File tempFile = new File(dir, name); if (tempFile.exists()) { tempFile.delete(); } Files.copy(new InputSupplier<InputStream>() { @Override public InputStream getInput() throws IOException { return contents; } }, tempFile); return tempFile; }