Example usage for com.google.common.io InputSupplier getInput

List of usage examples for com.google.common.io InputSupplier getInput

Introduction

In this page you can find the example usage for com.google.common.io InputSupplier getInput.

Prototype

T getInput() throws IOException;

Source Link

Document

Returns an object that encapsulates a readable resource.

Usage

From source file:org.jclouds.collect.InputSupplierMap.java

@Override
public V get(Object key) {
    InputSupplier<V> value = toMap.get(key);
    try {/*from www.j a v a2 s  .  c  om*/
        return value != null ? value.getInput() : null;
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}

From source file:org.richfaces.cdk.resource.writer.impl.JavaScriptPackagingProcessor.java

@Override
public void process(String resourceName, InputSupplier<? extends InputStream> in,
        OutputSupplier<? extends OutputStream> out, boolean closeAtFinish) throws IOException {
    process(resourceName, in.getInput(), out.getOutput(), closeAtFinish);
}

From source file:com.mapr.synth.samplers.FileSampler.java

private void readJsonData(InputSupplier<? extends InputStream> input) throws IOException {
    ObjectMapper om = new ObjectMapper();
    try (InputStream in = input.getInput()) {
        data = om.readTree(in);/*w  ww  . ja va  2  s.  co  m*/
    }
}

From source file:com.minecave.pickaxes.util.nbt.EPNbtFactory.java

/**
 * Load the content of a file from a stream.
 * <p/>/*from   w  w  w  . jav  a 2  s .  c o m*/
 * Use {@link Files#newInputStreamSupplier(java.io.File)} to provide a stream from a file.
 *
 * @param stream - the stream supplier.
 * @param option - whether or not to decompress the input stream.
 * @return The decoded NBT compound.
 * @throws IOException If anything went wrong.
 */
public static NbtCompound fromStream(InputSupplier<? extends InputStream> stream, StreamOptions option)
        throws IOException {
    InputStream input = null;
    DataInputStream data = null;
    boolean suppress = true;

    try {
        input = stream.getInput();
        data = new DataInputStream(new BufferedInputStream(
                option == StreamOptions.GZIP_COMPRESSION ? new GZIPInputStream(input) : input));

        NbtCompound result = fromCompound(get().LOAD_COMPOUND.loadNbt(data));
        suppress = false;
        return result;

    } finally {
        if (data != null)
            Closeables.close(data, suppress);
        else if (input != null)
            Closeables.close(input, suppress);
    }
}

From source file:org.activityinfo.server.endpoint.gwtrpc.PersistentPolicyProvider.java

private SerializationPolicy tryFetchFromBlobService(String key) {
    try {/*from w w  w . j  a v  a  2s.  com*/
        LOGGER.fine("Trying to read serialization policy from blobservice at " + key);
        InputSupplier<? extends InputStream> inputSupplier = blobService.get(key);
        InputStream in = inputSupplier.getInput();
        try {
            SerializationPolicy policy = SerializationPolicyLoader.loadFromStream(in, null);

            LOGGER.info("Read serialization policy from blob service at " + key);

            return policy;
        } finally {
            Closeables.closeQuietly(in);
        }

    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, "Could not load serialization policy from cache", e);
    }
    return null;
}

From source file:co.cask.tigon.internal.app.FlowSpecificationAdapter.java

public FlowSpecification fromJson(InputSupplier<? extends Reader> inputSupplier) throws IOException {
    Reader reader = inputSupplier.getInput();
    try {//  w  w  w  .  ja  v a 2s .c o m
        return fromJson(reader);
    } finally {
        Closeables.closeQuietly(reader);
    }
}

From source file:org.sonar.batch.repository.DefaultPreviousIssuesLoader.java

@Override
public void load(ProjectReactor reactor, Function<PreviousIssue, Void> consumer) {
    InputSupplier<InputStream> request = serverClient.doRequest(
            "/batch/issues?key=" + ServerClient.encodeForUrl(reactor.getRoot().getKeyWithBranch()), "GET",
            null);/*from ww  w  .j  a  v a  2  s  . c o m*/
    try (InputStream is = request.getInput(); Reader reader = new InputStreamReader(is, Charsets.UTF_8)) {
        for (PreviousIssue issue : PreviousIssueHelper.getIssues(reader)) {
            consumer.apply(issue);
        }
    } catch (HttpDownloader.HttpException e) {
        throw serverClient.handleHttpException(e);
    } catch (IOException e) {
        throw new IllegalStateException("Unable to get previous issues", e);
    }
}

From source file:com.facebook.buck.httpserver.TraceDataHandler.java

private void doGet(Request baseRequest, HttpServletResponse response) throws ServletException, IOException {
    String path = baseRequest.getPathInfo();
    Matcher matcher = ID_PATTERN.matcher(path);

    if (!matcher.matches()) {
        Responses.writeFailedResponse(baseRequest, response);
        return;/*ww  w  .  j a  va2s .c om*/
    }

    String id = matcher.group(1);

    response.setContentType(MediaType.JAVASCRIPT_UTF_8.toString());
    response.setStatus(HttpServletResponse.SC_OK);

    boolean hasValidCallbackParam = false;
    Writer responseWriter = response.getWriter();
    String callback = baseRequest.getParameter("callback");
    if (callback != null) {
        Matcher callbackMatcher = CALLBACK_PATTERN.matcher(callback);
        if (callbackMatcher.matches()) {
            hasValidCallbackParam = true;
            responseWriter.write(callback);
            responseWriter.write("(");
        }
    }

    InputSupplier<? extends InputStream> inputSupplier = tracesHelper.getInputForTrace(id);
    try (InputStreamReader inputStreamReader = new InputStreamReader(inputSupplier.getInput())) {
        CharStreams.copy(inputStreamReader, responseWriter);
    }

    if (hasValidCallbackParam) {
        responseWriter.write(");\n");
    }

    response.flushBuffer();
    baseRequest.setHandled(true);
}

From source file:com.theoryinpractise.coffeescript.CoffeeScriptCompiler.java

private void compileFile(Context context, String sourcePath, String fileName) throws IOException {
    InputSupplier<InputStreamReader> supplier = Resources.newReaderSupplier(getClass().getResource(sourcePath),
            Charsets.UTF_8);/*  w w w  .  j av  a 2  s .c o  m*/
    context.evaluateReader(globalScope, supplier.getInput(), fileName, 0, null);
}

From source file:org.eclipse.osee.jaxrs.server.internal.ext.RestResourceConcatenator.java

public void addResource(InputSupplier<? extends InputStream> supplier) throws IOException {
    Conditions.checkNotNull(supplier, "InputStreamSupplier");
    InputStream is = null;/*from   ww  w .j  av  a 2 s .c  o m*/
    try {
        is = supplier.getInput();
        processResource(Lib.inputStreamToString(is));
    } finally {
        Lib.close(is);
    }
}