Example usage for com.google.common.io ByteStreams nullOutputStream

List of usage examples for com.google.common.io ByteStreams nullOutputStream

Introduction

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

Prototype

public static OutputStream nullOutputStream() 

Source Link

Document

Returns an OutputStream that simply discards written bytes.

Usage

From source file:com.cisco.cta.taxii.adapter.AdapterRunner.java

/**
 * @param args The command line arguments.
 *//*from  w ww .  j  av  a 2s .c om*/
@SuppressFBWarnings(value = "DM_DEFAULT_ENCODING", justification = "DEV-NULL encoding is irrelevant")
public static void main(String[] args) {
    try (PrintStream devNull = new PrintStream(ByteStreams.nullOutputStream())) {
        System.setErr(devNull);
        ctx = new SpringApplicationBuilder(ScheduleConfiguration.class, RunNowConfiguration.class,
                SmokeTestConfiguration.class, RunConfigConfiguration.class).bannerMode(Mode.OFF)
                        .listeners(new ApplicationPidFileWriter()).web(false).run(args);
        ctx.start();

    } catch (Throwable t) {
        errHandler.handle(t);
    }
}

From source file:ch.ethz.system.mt.tpch.GeneratorAssertions.java

public static void assertEntityLinesMD5(Iterable<? extends TpchEntity> entities, String expectedMD5) {
    try {//from   w  w  w .  j a  va 2  s.c o  m
        DigestOutputStream out = md5OutputStream(ByteStreams.nullOutputStream());
        // out = md5OutputStream(System.out);
        for (TpchEntity entity : entities) {
            out.write(entity.toLine().getBytes(Charsets.UTF_8));
            out.write('\n');
        }

        byte[] md5Digest = out.getMessageDigest().digest();
        assertEquals(base16().lowerCase().encode(md5Digest), expectedMD5);
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}

From source file:com.google.testing.junit.runner.testbed.Fifo.java

/**
 * Helper method to help with the synchronization between testbed java test and shell tests. It
 * will block until data is available on the FIFO
 *//*w w  w.j  a v a2  s .com*/
static void waitUntilDataAvailable() throws IOException {
    if (FIFO == null) {
        throw new IllegalStateException("No fifo specified");
    }
    Files.asByteSource(new File(FIFO)).copyTo(ByteStreams.nullOutputStream());
}

From source file:org.jclouds.io.ByteStreams2.java

public static HashCode hashAndClose(InputStream input, HashFunction hashFunction) throws IOException {
    checkNotNull(input, "input");
    checkNotNull(hashFunction, "hashFunction");
    try {/* w w  w.j  a v a 2  s  .c o  m*/
        HashingInputStream his = new HashingInputStream(hashFunction, input);
        ByteStreams.copy(his, ByteStreams.nullOutputStream());
        return his.hash();
    } finally {
        closeQuietly(input);
    }
}

From source file:com.teradata.tpcds.GeneratorAssertions.java

private static void assertEntityLinesMD5(Results results, Session session, String expectedMD5) {
    try {//from w ww.ja  v a2s  .c  o  m
        DigestOutputStream out = md5OutputStream(ByteStreams.nullOutputStream());
        for (List<List<String>> parentAndChildRows : results) {
            out.write(formatRow(parentAndChildRows.get(0), session).getBytes(ISO_8859_1));
        }
        byte[] md5Digest = out.getMessageDigest().digest();
        assertEquals(base16().lowerCase().encode(md5Digest), expectedMD5);
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}

From source file:com.crunchynoodles.util.FileUtils.java

/***
 *  Returns an output stream where written bytes are simply discarded.
 *
 * @return writable stream, hahahahaha...
 *//*w w w  .j  a  v a 2 s  .c om*/
public static OutputStream getNullOutputStream() {
    return ByteStreams.nullOutputStream();
}

From source file:com.google.cloud.dataflow.sdk.runners.worker.DataflowApiUtils.java

/**
 * Determines the serialized size (in bytes) of the {@link GenericJson} object that will be
 * serialized and sent to the Google Cloud Dataflow service API.
 *
 * <p>Uses only constant memory./*ww  w .  ja  v a  2s . c  o  m*/
 */
public static long computeSerializedSizeBytes(GenericJson object) throws IOException {
    JsonFactory factory = object.getFactory();
    if (factory == null) {
        factory = Transport.getJsonFactory();
    }

    CountingOutputStream stream = new CountingOutputStream(ByteStreams.nullOutputStream());
    JsonGenerator generator = null;
    try {
        generator = factory.createJsonGenerator(stream, StandardCharsets.UTF_8);
        generator.serialize(object);
        generator.close(); // also closes the stream.
    } finally {
        if (generator != null) {
            generator.close();
        }
    }
    return stream.getCount();
}

From source file:org.sonatype.nexus.common.hash.Hashes.java

/**
 * Computes the hash of the given stream using the given algorithm.
 *//*ww  w . j  a  v  a  2s.  com*/
public static HashCode hash(final HashAlgorithm algorithm, final InputStream inputStream) throws IOException {
    checkNotNull(algorithm);
    checkNotNull(inputStream);

    try (HashingInputStream hashingStream = new HashingInputStream(algorithm.function(), inputStream)) {
        ByteStreams.copy(hashingStream, ByteStreams.nullOutputStream());
        return hashingStream.hash();
    }
}

From source file:io.dockstore.common.Utilities.java

public static ImmutablePair<String, String> executeCommand(String command) {
    return executeCommand(command, true, Optional.of(ByteStreams.nullOutputStream()),
            Optional.of(ByteStreams.nullOutputStream()));
}

From source file:org.sonatype.nexus.common.hash.Hashes.java

/**
 * Computes the hash of the given stream using multiple algorithms in one pass.
 *//*from  w  w w .ja v a2  s .com*/
public static Map<HashAlgorithm, HashCode> hash(final Iterable<HashAlgorithm> algorithms,
        final InputStream inputStream) throws IOException {
    checkNotNull(algorithms);
    checkNotNull(inputStream);

    try (MultiHashingInputStream hashingStream = new MultiHashingInputStream(algorithms, inputStream)) {
        ByteStreams.copy(hashingStream, ByteStreams.nullOutputStream());
        return hashingStream.hashes();
    }
}