Example usage for com.google.common.io ByteSource ByteSource

List of usage examples for com.google.common.io ByteSource ByteSource

Introduction

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

Prototype

protected ByteSource() 

Source Link

Document

Constructor for use by subclasses.

Usage

From source file:com.google.devtools.build.lib.ideinfo.AndroidStudioInfoAspect.java

private static BinaryFileWriteAction makeProtoTextWriteAction(ActionOwner actionOwner,
        final MessageLite message, Artifact artifact) {
    return new BinaryFileWriteAction(actionOwner, artifact, new ByteSource() {
        @Override// w ww .  ja va  2s.  co  m
        public InputStream openStream() throws IOException {
            return new ByteArrayInputStream(message.toString().getBytes(StandardCharsets.UTF_8));
        }
    }, /*makeExecutable =*/ false);
}

From source file:org.apache.druid.indexing.overlord.ForkingTaskRunner.java

@Override
public Optional<ByteSource> streamTaskLog(final String taskid, final long offset) {
    final ProcessHolder processHolder;

    synchronized (tasks) {
        final ForkingTaskRunnerWorkItem taskWorkItem = tasks.get(taskid);
        if (taskWorkItem != null && taskWorkItem.processHolder != null) {
            processHolder = taskWorkItem.processHolder;
        } else {/*from  ww  w . j a v a  2  s.  c om*/
            return Optional.absent();
        }
    }

    return Optional.of(new ByteSource() {
        @Override
        public InputStream openStream() throws IOException {
            return LogUtils.streamFile(processHolder.logFile, offset);
        }
    });
}

From source file:org.pantsbuild.tools.jar.JarBuilder.java

private JarBuilder useCustomManifest(final InputSupplier<Manifest> manifestSource) {
    manifest = new ByteSource() {
        @Override/*from  w  w w .jav  a  2 s .  c o  m*/
        public InputStream openStream() throws IOException {
            return manifestSupplier(manifestSource.getInput()).openStream();
        }
    };
    return this;
}

From source file:io.druid.indexing.overlord.hrtr.HttpRemoteTaskRunner.java

@Override
public Optional<ByteSource> streamTaskLog(String taskId, long offset) {
    HttpRemoteTaskRunnerWorkItem taskRunnerWorkItem = tasks.get(taskId);
    Worker worker = null;//from   w w  w . j a  v a2s.co m
    if (taskRunnerWorkItem != null
            && taskRunnerWorkItem.getState() != HttpRemoteTaskRunnerWorkItem.State.COMPLETE) {
        worker = taskRunnerWorkItem.getWorker();
    }

    if (worker == null || !workers.containsKey(worker.getHost())) {
        // Worker is not running this task, it might be available in deep storage
        return Optional.absent();
    } else {
        // Worker is still running this task
        final URL url = WorkerHolder.makeWorkerURL(worker,
                StringUtils.format("/druid/worker/v1/task/%s/log?offset=%d", taskId, offset));
        return Optional.<ByteSource>of(new ByteSource() {
            @Override
            public InputStream openStream() throws IOException {
                try {
                    return httpClient.go(new Request(HttpMethod.GET, url), 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.apache.druid.indexing.overlord.hrtr.HttpRemoteTaskRunner.java

@Override
public Optional<ByteSource> streamTaskLog(String taskId, long offset) {
    HttpRemoteTaskRunnerWorkItem taskRunnerWorkItem = tasks.get(taskId);
    Worker worker = null;// w w w.j a v  a 2s  . c  om
    if (taskRunnerWorkItem != null
            && taskRunnerWorkItem.getState() != HttpRemoteTaskRunnerWorkItem.State.COMPLETE) {
        worker = taskRunnerWorkItem.getWorker();
    }

    if (worker == null || !workers.containsKey(worker.getHost())) {
        // Worker is not running this task, it might be available in deep storage
        return Optional.absent();
    } else {
        // Worker is still running this task
        final URL url = TaskRunnerUtils.makeWorkerURL(worker, "/druid/worker/v1/task/%s/log?offset=%d", taskId,
                offset);
        return Optional.of(new ByteSource() {
            @Override
            public InputStream openStream() throws IOException {
                try {
                    return httpClient.go(new Request(HttpMethod.GET, url), 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.pantsbuild.tools.jar.JarBuilder.java

private static ByteSource entrySupplier(final InputSupplier<JarFile> jar, final JarEntry entry) {
    return new ByteSource() {
        @Override//from  www.  j a va  2s. c  o m
        public InputStream openStream() throws IOException {
            return jar.getInput().getInputStream(entry);
        }
    };
}