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.facebook.buck.parser.SerialPerBuildState.java

public SerialPerBuildState(DaemonicParserState permState, ConstructorArgMarshaller marshaller,
        BuckEventBus eventBus, Cell rootCell, boolean enableProfiling) {
    this.permState = permState;
    this.marshaller = marshaller;
    this.eventBus = eventBus;
    this.enableProfiling = enableProfiling;
    this.cells = new ConcurrentHashMap<>();
    this.cellSymlinkAllowability = new ConcurrentHashMap<>();
    this.parsers = new ConcurrentHashMap<>();
    this.buildInputPathsUnderSymlink = Sets.newHashSet();
    this.symlinkExistenceCache = new ConcurrentHashMap<>();

    this.stdout = new PrintStream(ByteStreams.nullOutputStream());
    this.stderr = new PrintStream(ByteStreams.nullOutputStream());
    this.console = new Console(Verbosity.STANDARD_INFORMATION, stdout, stderr, Ansi.withoutTty());

    this.symlinkCheckers = new TargetNodeListener() {
        @Override//from   w  ww. j a  v a  2 s  . c o m
        public void onCreate(Path buildFile, TargetNode<?> node) throws IOException {
            registerInputsUnderSymlinks(buildFile, node);
        }
    };

    register(rootCell);
}

From source file:com.google.testing.junit.runner.junit4.JUnit4RunnerModule.java

@Provides
@Singleton//from  w w  w. jav a2  s. c  o  m
@Xml
OutputStream provideXmlStream() {
    Optional<Path> path = config.getXmlOutputPath();

    if (path.isPresent()) {
        try {
            // TODO(bazel-team): Change the provider method to return ByteSink or CharSink
            return new FileOutputStream(path.get().toFile());
        } catch (FileNotFoundException e) {
            /*
             * We try to avoid throwing exceptions in the runner code. There is no
             * way to induce a test failure here, so the only thing we can do is
             * print a message and move on.
             */
            e.printStackTrace();
        }
    }

    return ByteStreams.nullOutputStream();
}

From source file:net.ripe.rpki.commons.crypto.util.KeyStoreUtil.java

private static KeyStore clearKeyStore(KeyStore keyStore) {
    try {/*ww  w  .  ja va2  s  . co m*/
        if (keyStore.containsAlias(KEYSTORE_KEY_ALIAS)) {
            keyStore.deleteEntry(KEYSTORE_KEY_ALIAS);
            keyStore.store(ByteStreams.nullOutputStream(), KEYSTORE_PASSPHRASE);
        }
        return keyStore;
    } catch (GeneralSecurityException e) {
        throw new net.ripe.rpki.commons.crypto.util.KeyStoreException(e);
    } catch (IOException e) {
        throw new net.ripe.rpki.commons.crypto.util.KeyStoreException(e);
    }
}

From source file:org.gaul.s3proxy.NullBlobStore.java

@Override
public String putBlob(String containerName, Blob blob, PutOptions options) {
    long length;/* w  ww.  j  a v a  2  s. co  m*/
    try (InputStream is = blob.getPayload().openStream()) {
        length = ByteStreams.copy(is, ByteStreams.nullOutputStream());
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }

    byte[] array = Longs.toByteArray(length);
    ByteSourcePayload payload = new ByteSourcePayload(ByteSource.wrap(array));
    payload.setContentMetadata(blob.getPayload().getContentMetadata());
    payload.getContentMetadata().setContentLength((long) array.length);
    payload.getContentMetadata().setContentMD5((HashCode) null);
    blob.setPayload(payload);

    return super.putBlob(containerName, blob, options);
}

From source file:alluxio.client.file.FileSystemTestUtils.java

/**
 * Loads a file into Alluxio by reading it.
 *
 * @param fs a {@link FileSystem}//from   w  ww. ja v  a 2 s . co  m
 * @param fileName the name of the file to load
 */
public static void loadFile(FileSystem fs, String fileName) {
    try (FileInStream is = fs.openFile(new AlluxioURI(fileName),
            OpenFileOptions.defaults().setReadType(ReadType.CACHE))) {
        IOUtils.copy(is, ByteStreams.nullOutputStream());
    } catch (IOException | AlluxioException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.google.devtools.build.lib.sandbox.DockerSandboxedSpawnRunner.java

public static boolean isSupported(CommandEnvironment cmdEnv, Path dockerClient) {
    boolean verbose = cmdEnv.getOptions().getOptions(SandboxOptions.class).dockerVerbose;

    if (!ProcessWrapperUtil.isSupported(cmdEnv)) {
        if (verbose) {
            cmdEnv.getReporter()/*from  w w w .j a v  a 2s  .co  m*/
                    .handle(Event.error("Docker sandboxing is disabled, because ProcessWrapperUtil.isSupported "
                            + "returned false. This should never happen - is your Bazel binary "
                            + "corrupted?"));
        }
        return false;
    }

    // On Linux we need to know the UID and GID that we're running as, because otherwise Docker will
    // create files as 'root' and we can't move them to the execRoot.
    if (OS.getCurrent() == OS.LINUX) {
        try {
            ProcessUtils.getuid();
            ProcessUtils.getgid();
        } catch (UnsatisfiedLinkError e) {
            if (verbose) {
                cmdEnv.getReporter().handle(Event
                        .error("Docker sandboxing is disabled, because ProcessUtils.getuid/getgid threw an "
                                + "UnsatisfiedLinkError. This means that you're running a Bazel version "
                                + "that doesn't have JNI libraries - did you build it correctly?\n"
                                + Throwables.getStackTraceAsString(e)));
            }
            return false;
        }
    }

    Command cmd = new Command(new String[] { dockerClient.getPathString(), "info" }, ImmutableMap.of(),
            cmdEnv.getExecRoot().getPathFile());
    try {
        cmd.execute(ByteStreams.nullOutputStream(), ByteStreams.nullOutputStream());
    } catch (CommandException e) {
        if (verbose) {
            cmdEnv.getReporter()
                    .handle(Event.error("Docker sandboxing is disabled, because running 'docker info' failed: "
                            + Throwables.getStackTraceAsString(e)));
        }
        return false;
    }

    if (verbose) {
        cmdEnv.getReporter().handle(Event.info("Docker sandboxing is supported"));
    }

    return true;
}

From source file:org.gaul.areweconsistentyet.AreWeConsistentYet.java

public int readAfterDelete() throws IOException {
    int count = 0;
    for (int i = 0; i < iterations; ++i) {
        String blobName = makeBlobName();
        blobStoreRead.putBlob(containerName, makeBlob(blobName, payload1));
        blobStore.removeBlob(containerName, blobName);
        Blob getBlob = blobStoreRead.getBlob(containerName, blobName);
        if (getBlob != null) {
            ++count;/*ww w.  j  a v  a2  s. com*/
            try (Payload payload = getBlob.getPayload(); InputStream is = payload.openStream()) {
                ByteStreams.copy(is, ByteStreams.nullOutputStream());
            }
        }
    }
    return count;
}

From source file:org.openqa.selenium.firefox.xpi.XpiDriverService.java

private XpiDriverService(File executable, int port, ImmutableList<String> args,
        ImmutableMap<String, String> environment, FirefoxBinary binary, FirefoxProfile profile, File logFile)
        throws IOException {
    super(executable, port, args, environment);

    Preconditions.checkState(port > 0, "Port must be set");

    this.port = port;
    this.binary = binary;
    this.profile = profile;

    String firefoxLogFile = System.getProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE);
    if (firefoxLogFile != null) { // System property has higher precedence
        if ("/dev/stdout".equals(firefoxLogFile)) {
            sendOutputTo(System.out);
        } else if ("/dev/stderr".equals(firefoxLogFile)) {
            sendOutputTo(System.err);
        } else if ("/dev/null".equals(firefoxLogFile)) {
            sendOutputTo(ByteStreams.nullOutputStream());
        } else {//  w  ww.  ja v a 2 s  .c  o m
            // TODO: This stream is leaked.
            sendOutputTo(new FileOutputStream(firefoxLogFile));
        }
    } else {
        if (logFile != null) {
            // TODO: This stream is leaked.
            sendOutputTo(new FileOutputStream(logFile));
        } else {
            sendOutputTo(ByteStreams.nullOutputStream());
        }
    }
}

From source file:io.github.msdk.io.mztab.MzTabFileImportMethod.java

/** {@inheritDoc} */
@Override//www.  j  av a 2 s.c  om
public FeatureTable execute() throws MSDKException {

    logger.info("Started parsing file " + sourceFile);

    // Check if the file is readable
    if (!sourceFile.canRead()) {
        throw new MSDKException("Cannot read file " + sourceFile);
    }

    String fileName = sourceFile.getName();
    newFeatureTable = MSDKObjectBuilder.getFeatureTable(fileName, dataStore);

    try {
        // Prevent MZTabFileParser from writing to console
        OutputStream logStream = ByteStreams.nullOutputStream();

        // Load mzTab file
        MZTabFileParser mzTabFileParser = new MZTabFileParser(sourceFile, logStream);

        MZTabFile mzTabFile = mzTabFileParser.getMZTabFile();

        // Let's say the initial parsing took 10% of the time
        totalRows = mzTabFile.getSmallMolecules().size();
        samples = mzTabFile.getMetadata().getMsRunMap().size();

        // Check if cancel is requested
        if (canceled) {
            return null;
        }

        // Add the columns to the table
        addColumns(newFeatureTable, mzTabFile);

        // Check if cancel is requested
        if (canceled) {
            return null;
        }

        // Add the rows to the table (= import small molecules)
        addRows(newFeatureTable, mzTabFile);

        // Check if cancel is requested
        if (canceled) {
            return null;
        }

    } catch (Exception e) {
        throw new MSDKException(e);
    }

    logger.info("Finished parsing " + sourceFile + ", parsed " + samples + " samples and " + totalRows
            + " features.");

    return newFeatureTable;

}

From source file:org.sonatype.nexus.blobstore.file.internal.SimpleFileOperations.java

@Override
public StreamMetrics computeMetrics(final Path file) throws IOException {
    try (InputStream is = Files.newInputStream(file); MetricsInputStream mis = new MetricsInputStream(is)) {
        ByteStreams.copy(mis, ByteStreams.nullOutputStream());
        return mis.getMetrics();
    }// w  w w  .j a v  a2 s.c om
}