List of usage examples for com.google.common.io ByteStreams nullOutputStream
public static OutputStream nullOutputStream()
From source file:org.eclipse.hawkbit.ui.management.targettable.BulkUploadHandler.java
@Override public OutputStream receiveUpload(final String filename, final String mimeType) { try {// w ww . j av a 2 s . c o m tempFile = File.createTempFile("temp", ".csv"); progressBar.setVisible(false); targetsCountLabel.setVisible(false); return new FileOutputStream(tempFile); } catch (final FileNotFoundException e) { LOG.error("File was not found with file name {}", filename, e); } catch (final IOException e) { LOG.error("Error while reading file {}", filename, e); } return ByteStreams.nullOutputStream(); }
From source file:com.facebook.buck.artifact_cache.HttpArtifactCacheBinaryProtocol.java
@VisibleForTesting static byte[] createMetadataHeader(ImmutableSet<RuleKey> ruleKeys, ImmutableMap<String, String> metadata, ByteSource data) throws IOException { ByteArrayOutputStream rawOut = new ByteArrayOutputStream(); Hasher hasher = HASH_FUNCTION.newHasher(); try (DataOutputStream out = new DataOutputStream(new HasherOutputStream(hasher, rawOut))) { // Write the rule keys to the raw metadata, including them in the end-to-end checksum. out.writeInt(ruleKeys.size());/*from ww w . j a va2s.c o m*/ for (RuleKey ruleKey : ruleKeys) { out.writeUTF(ruleKey.toString()); } // Write out the metadata map to the raw metadata, including it in the end-to-end checksum. out.writeInt(metadata.size()); for (Map.Entry<String, String> ent : metadata.entrySet()) { out.writeUTF(ent.getKey()); byte[] val = ent.getValue().getBytes(Charsets.UTF_8); out.writeInt(val.length); out.write(val); if (out.size() > MAX_METADATA_HEADER_SIZE) { throw new IOException("Metadata header too big."); } } } // Add the file data contents to the end-to-end checksum. data.copyTo(new HasherOutputStream(hasher, ByteStreams.nullOutputStream())); // Finish the checksum, adding it to the raw metadata rawOut.write(hasher.hash().asBytes()); // Finally, base64 encode the raw bytes to make usable in a HTTP header. byte[] bytes = rawOut.toByteArray(); if (bytes.length > MAX_METADATA_HEADER_SIZE) { throw new IOException("Metadata header too big."); } return bytes; }
From source file:org.apache.beam.sdk.coders.StandardCoder.java
/** * Returns the size in bytes of the encoded value using this coder. *///ww w. j a v a 2s . c o m protected long getEncodedElementByteSize(T value, Context context) throws Exception { try (CountingOutputStream os = new CountingOutputStream(ByteStreams.nullOutputStream())) { encode(value, os, context); return os.getCount(); } catch (Exception exn) { throw new IllegalArgumentException( "Unable to encode element '" + value + "' with coder '" + this + "'.", exn); } }
From source file:edu.byu.nlp.crowdsourcing.MultiAnnDatasetLabeler.java
/** * @param gold for computing confusion matrices for debugging *///from www. j ava2s .c om public MultiAnnDatasetLabeler(MultiAnnModelBuilder multiannModelBuilder, PrintWriter debugOut, boolean predictSingleLastSample, String trainingOperations, DiagonalizationMethod diagonalizationMethod, boolean diagonalizationWithFullConfusionMatrix, int goldInstancesForDiagonalization, Dataset trainingData, String unannotatedDocumentWeight, IntermediatePredictionLogger predictionLogger, RandomGenerator algRnd) { // TODO (pfelt): in the future we'll probably want to NOT pass in the builder, but create a new builder // for every label() request. The only problem with that right now is that it's not clear how // to build a Dataset from a collection of instances--it requires indexes generated from the original data??? this.builder = multiannModelBuilder; this.predictSingleLastSample = predictSingleLastSample; this.trainingOperations = trainingOperations; this.diagonalizationMethod = diagonalizationMethod; this.diagonalizationWithFullConfusionMatrix = diagonalizationWithFullConfusionMatrix; this.goldInstancesForDiagonalization = goldInstancesForDiagonalization; this.statsOut = (statsOut == null) ? new PrintWriter(ByteStreams.nullOutputStream()) : statsOut; this.debugOut = (debugOut == null) ? new PrintWriter(ByteStreams.nullOutputStream()) : debugOut; this.unannotatedDocumentWeight = unannotatedDocumentWeight; this.predictionLogger = predictionLogger; this.rnd = algRnd; this.data = trainingData; // should get rid of this after we figure out how to pass instances into the label() method }
From source file:org.eclipse.hawkbit.ui.artifacts.upload.AbstractFileTransferHandler.java
protected OutputStream createOutputStreamForTempFile() throws IOException { if (isUploadInterrupted()) { return ByteStreams.nullOutputStream(); }// w w w. j av a 2 s . com final File tempFile = File.createTempFile("spUiArtifactUpload", null); // we return the outputstream so we cannot close it here @SuppressWarnings("squid:S2095") final OutputStream out = new FileOutputStream(tempFile); tempFilePath = tempFile.getAbsolutePath(); return out; }
From source file:com.github.jsdossier.Main.java
@VisibleForTesting static void run(String[] args, FileSystem fileSystem) { Flags flags = Flags.parse(args, fileSystem); Config config = null;/*from www . j a v a 2s . c o m*/ try (InputStream stream = newInputStream(flags.config)) { config = Config.load(stream, fileSystem); } catch (IOException e) { e.printStackTrace(System.err); System.exit(-1); } if (flags.printConfig) { Gson gson = new GsonBuilder().setPrettyPrinting().create(); String header = " Configuration "; int len = header.length(); String pad = Strings.repeat("=", len / 2); System.err.println(pad + header + pad); System.err.println(gson.toJson(config.toJson())); System.err.println(Strings.repeat("=", 79)); System.exit(1); } Iterable<String> standardFlags = STANDARD_FLAGS; if (config.isStrict()) { standardFlags = transform(standardFlags, new Function<String, String>() { @Override public String apply(String input) { return input.replace("--jscomp_warning", "--jscomp_error"); } }); } ImmutableList<String> compilerFlags = ImmutableList.<String>builder() .addAll(transform(config.getSources(), toFlag("--js="))) .addAll(transform(config.getModules(), toFlag("--js="))) .addAll(transform(config.getExterns(), toFlag("--externs="))) .add("--language_in=" + config.getLanguage().getName()).addAll(standardFlags).build(); PrintStream nullStream = new PrintStream(ByteStreams.nullOutputStream()); args = compilerFlags.toArray(new String[compilerFlags.size()]); Logger log = Logger.getLogger(Main.class.getPackage().getName()); log.setLevel(Level.WARNING); log.addHandler(new Handler() { @Override public void publish(LogRecord record) { System.err.printf("[%s][%s] %s\n", record.getLevel(), record.getLoggerName(), record.getMessage()); } @Override public void flush() { } @Override public void close() { } }); Main main = new Main(args, nullStream, System.err, config); main.runCompiler(); }
From source file:com.android.tradefed.util.StreamUtil.java
/** * Create a {@link OutputStream} that discards all writes. */ public static OutputStream nullOutputStream() { return ByteStreams.nullOutputStream(); }
From source file:org.jclouds.s3.filters.Aws4SignerBase.java
/** * hash input with sha256//from w ww .j av a 2s. com * * @param input * @return hash result * @throws HTTPException */ public static byte[] hash(InputStream input) throws HTTPException { HashingInputStream his = new HashingInputStream(Hashing.sha256(), input); try { ByteStreams.copy(his, ByteStreams.nullOutputStream()); return his.hash().asBytes(); } catch (IOException e) { throw new HttpException("Unable to compute hash while signing request: " + e.getMessage(), e); } }
From source file:org.mapstruct.ap.testutil.runner.CompilingStatement.java
private void assertCheckstyleRules() throws Exception { if (sourceOutputDir != null) { Properties properties = new Properties(); properties.put("checkstyle.cache.file", classOutputDir + "/checkstyle.cache"); final Checker checker = new Checker(); checker.setModuleClassLoader(Checker.class.getClassLoader()); checker.configure(ConfigurationLoader.loadConfiguration( new InputSource(getClass().getClassLoader() .getResourceAsStream("checkstyle-for-generated-sources.xml")), new PropertiesExpander(properties), true)); ByteArrayOutputStream errorStream = new ByteArrayOutputStream(); checker.addListener(new DefaultLogger(ByteStreams.nullOutputStream(), true, errorStream, true)); int errors = checker.process(findGeneratedFiles(new File(sourceOutputDir))); if (errors > 0) { String errorLog = errorStream.toString("UTF-8"); assertThat(true).describedAs("Expected checkstyle compliant output, but got errors:\n" + errorLog) .isEqualTo(false);// w w w . j ava 2s.c o m } } }
From source file:net.minecraftforge.gradle.patcher.TaskGenBinPatches.java
private byte[] pack200(byte[] data) throws Exception { JarInputStream in = new JarInputStream(new ByteArrayInputStream(data)); ByteArrayOutputStream out = new ByteArrayOutputStream(); Packer packer = Pack200.newPacker(); SortedMap<String, String> props = packer.properties(); props.put(Packer.EFFORT, "9"); props.put(Packer.KEEP_FILE_ORDER, Packer.TRUE); props.put(Packer.UNKNOWN_ATTRIBUTE, Packer.PASS); final PrintStream err = new PrintStream(System.err); System.setErr(new PrintStream(ByteStreams.nullOutputStream())); packer.pack(in, out);/*from w w w.j a v a 2s .co m*/ System.setErr(err); in.close(); out.close(); return out.toByteArray(); }