List of usage examples for com.google.common.io InputSupplier InputSupplier
InputSupplier
From source file:ca.ualberta.physics.cssdp.vfs.service.FileSystemService.java
public ServiceResponse<Void> write(final Long owner, final String path, final String filename, final InputStream fileData) { final ServiceResponse<Void> sr = new ServiceResponse<Void>(); Long defaultQuota = VfsServer.properties().getLong("default_user_quota"); File userDir = getUserRoot(owner); long diskUsage = sizeOf(userDir); if (diskUsage > defaultQuota) { sr.error("Can not save file to VFS, user quota exceeded (" + StorageUnit.GIGABYTE.format(defaultQuota)); return sr; }// w w w . jav a 2s. com File file = new File(new File(userDir, path), filename); int duplicateCount = 0; while (file.exists()) { file = new File(new File(userDir, path), filename + "(" + ++duplicateCount + ")"); } try { Files.createParentDirs(file); Files.copy(new InputSupplier<InputStream>() { @Override public InputStream getInput() throws IOException { return fileData; } }, file); } catch (IOException e) { sr.error("Could not write file data because " + e.getMessage()); } return sr; }
From source file:org.jclouds.examples.blobstore.hdfs.io.HdfsPayloadSlicer.java
protected Payload doSlice(final FSDataInputStream inputStream, final long offset, final long length) { return new InputStreamSupplierPayload(new InputSupplier<InputStream>() { public InputStream getInput() throws IOException { if (offset > 0) { try { inputStream.seek(offset); } catch (IOException e) { Closeables.closeQuietly(inputStream); throw e; }/*from w ww . j a va 2s.co m*/ } return new LimitInputStream(inputStream, length); } }); }
From source file:co.freeside.betamax.message.AbstractMessage.java
@Override public final InputSupplier<InputStream> getBodyAsBinary() { return new InputSupplier<InputStream>() { @Override/* ww w. j av a 2s.com*/ public InputStream getInput() throws IOException { return getBodyAsStream(); } }; }
From source file:com.notifier.desktop.view.LicenseDialog.java
public void open() { try {//from w ww .ja v a2 s. c o m Shell parent = getParent(); dialogShell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); dialogShell.setLayout(new FormLayout()); dialogShell.layout(); dialogShell.pack(); dialogShell.setSize(403, 353); dialogShell.setText("License"); licenseTextArea = new Text(dialogShell, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL); FormData licenseTextAreaLData = new FormData(); licenseTextAreaLData.left = new FormAttachment(0, 1000, 12); licenseTextAreaLData.top = new FormAttachment(0, 1000, 12); licenseTextAreaLData.bottom = new FormAttachment(1000, 1000, -12); licenseTextAreaLData.right = new FormAttachment(1000, 1000, -12); licenseTextArea.setLayoutData(licenseTextAreaLData); String license = "Copyright (c) 2010, Leandro Aparecido\nAll rights reserved.\n\n"; try { license += CharStreams.toString(new InputSupplier<InputStreamReader>() { @Override public InputStreamReader getInput() throws IOException { return new InputStreamReader(Application.class.getResourceAsStream(Application.LICENSE)); } }); } catch (IOException e) { logger.error("Could not load license"); } licenseTextArea.setText(license); licenseTextArea.setBounds(12, 12, 256, 168); licenseTextArea.setEditable(false); Dialogs.centerDialog(dialogShell); dialogShell.open(); Dialogs.bringToForeground(dialogShell); } catch (Exception e) { logger.error("Error showing license dialog", e); } }
From source file:eu.esdihumboldt.util.resource.internal.BundleResolver.java
/** * @see ResourceResolver#resolve(URI)// ww w . jav a 2 s . com */ @Override public InputSupplier<? extends InputStream> resolve(URI uri) throws ResourceNotFoundException { final URL entry = bundle.getEntry(uri.getPath()); if (entry == null) { throw new ResourceNotFoundException( "Resource with path " + uri.getPath() + " not contained in bundle " + bundle.getSymbolicName()); } return new InputSupplier<InputStream>() { @Override public InputStream getInput() throws IOException { return entry.openStream(); } }; }
From source file:eu.numberfour.n4js.JSLibSingleTestConfigProvider.java
/** * @param resourceName//w w w . j ava 2 s .c om * the classpath-relative location of the to-be-read resource */ private static List<String> getFileLines(final String resourceName) throws IOException { InputSupplier<InputStreamReader> readerSupplier = CharStreams .newReaderSupplier(new InputSupplier<InputStream>() { @Override public InputStream getInput() throws IOException { return Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName); } }, Charsets.UTF_8); return CharStreams.readLines(readerSupplier); }
From source file:co.freeside.betamax.message.AbstractMessage.java
@Override public final InputSupplier<Reader> getBodyAsText() { return new InputSupplier<Reader>() { @Override/*from ww w . jav a 2s . c o m*/ public Reader getInput() throws IOException { return getBodyAsReader(); } }; }
From source file:org.killbill.billing.plugin.meter.MeterTestSuiteWithEmbeddedDB.java
@BeforeSuite(groups = { "slow", "mysql" }) public void startMysqlBeforeTestSuite() throws IOException, ClassNotFoundException, SQLException, URISyntaxException { helper.initialize();//from ww w. j a v a 2 s . c o m helper.start(); final InputSupplier<InputStream> inputSupplier = new InputSupplier<InputStream>() { @Override public InputStream getInput() throws IOException { return Resources.getResource("org/killbill/billing/plugin/meter/ddl.sql").openStream(); } }; final String ddl = CharStreams.toString(CharStreams.newReaderSupplier(inputSupplier, Charsets.UTF_8)); helper.executeScript(ddl); helper.refreshTableNames(); }
From source file:com.github.praxissoftware.maven.plugins.GenerateFeaturesMojo.java
@SuppressWarnings("unchecked") @Override/*from w ww . j a va 2s.c o m*/ public void execute() throws MojoExecutionException { Writer out = null; try { // Get the template text from the jar's resources. final InputSupplier<InputStreamReader> supplier = CharStreams .newReaderSupplier(new InputSupplier<InputStream>() { @Override public InputStream getInput() throws IOException { return getClass().getClassLoader().getResourceAsStream("features.mustache.xml"); } }, Charsets.UTF_8); final String template = CharStreams.toString(supplier); // Create the mustache factory from the loaded template. final Mustache mustache = new MustacheBuilder().parse(template, "features.mustache.xml"); // Establish output stream. final File featureFile = setUpFile(outputFile); out = new FileWriter(featureFile); // Build context. final Map<String, Object> context = convert(project.getArtifact()); final List<Map<String, Object>> dependencies = Lists.newArrayList(); for (final Artifact dependency : Ordering.natural().onResultOf(new SortByCoordinates()) .sortedCopy(Iterables.filter((Collection<Artifact>) project.getDependencyArtifacts(), new ArtifactsWeWant()))) { dependencies.add(convert(dependency)); } context.put("dependencies", dependencies); getLog().info("Writing feature to " + outputFile.getAbsolutePath()); // Render template. mustache.execute(out, context); } catch (final Exception e) { Throwables.propagateIfInstanceOf(e, MojoExecutionException.class); Throwables.propagateIfPossible(e); throw new MojoExecutionException("Unable to generate features.xml.", e); } finally { Closeables.closeQuietly(out); } }
From source file:edu.umd.cloud9.collection.clue.ClueWarcDocnoMappingBuilder.java
/** * Runs this tool./* w w w . j av a 2 s . c o m*/ */ public int run(String[] args) throws IOException { DocnoMapping.DefaultBuilderOptions options = DocnoMapping.BuilderUtils.parseDefaultOptions(args); if (options == null) { return -1; } LOG.info("Tool name: " + ClueWarcDocnoMappingBuilder.class.getSimpleName()); LOG.info(" - input path: " + options.collection); LOG.info(" - output file: " + options.docnoMapping); FileSystem fs = FileSystem.get(getConf()); FSDataOutputStream out = fs.create(new Path(options.docnoMapping), true); final InputStream in = ClueWarcDocnoMapping.class.getResourceAsStream("docno.mapping"); List<String> lines = CharStreams.readLines(CharStreams.newReaderSupplier(new InputSupplier<InputStream>() { @Override public InputStream getInput() throws IOException { return in; } }, Charsets.UTF_8)); out.write((Joiner.on("\n").join(lines) + "\n").getBytes()); out.close(); return 0; }