List of usage examples for com.google.common.io ByteStreams nullOutputStream
public static OutputStream nullOutputStream()
From source file:org.haiku.haikudepotserver.pkg.job.PkgScreenshotImportArchiveJobRunner.java
/** * <p>Goes through the archive and captures information about each screenshot.</p> */// www. j a v a 2s . com private void collectScreenshotMetadataFromArchive(Map<String, ScreenshotImportMetadatas> data, ArchiveInputStream archiveInputStream, ArchiveEntry archiveEntry, String pkgName, int order) { ScreenshotImportMetadatas metadatas = data.get(pkgName); if (null == metadatas) { metadatas = new ScreenshotImportMetadatas(); ObjectContext context = serverRuntime.newContext(); Optional<Pkg> pkgOptional = Pkg.tryGetByName(context, pkgName); if (!pkgOptional.isPresent()) { metadatas.setNotFound(); } data.put(pkgName, metadatas); } if (!metadatas.isNotFound()) { HashingInputStream hashingInputStream = new HashingInputStream(HASH_FUNCTION, archiveInputStream); try { ByteStreams.copy(hashingInputStream, ByteStreams.nullOutputStream()); } catch (IOException ioe) { throw new UncheckedIOException(ioe); } metadatas.add(new FromArchiveScreenshotMetadata(order, archiveEntry.getSize(), hashingInputStream.hash(), archiveEntry.getName())); } }
From source file:io.macgyver.plugin.cmdb.AppInstanceManager.java
public String computeSignature(ObjectNode n, Set<String> exclusions) { List<String> list = Lists.newArrayList(n.fieldNames()); Collections.sort(list);// www . j a v a 2 s . co m HashingOutputStream hos = new HashingOutputStream(Hashing.sha1(), ByteStreams.nullOutputStream()); list.forEach(it -> { if (exclusions != null && !exclusions.contains(it)) { JsonNode val = n.get(it); if (val.isObject() || val.isArray()) { // skipping } else { try { hos.write(it.getBytes()); hos.write(val.toString().getBytes()); } catch (IOException e) { } } } }); return hos.hash().toString(); }
From source file:org.apache.beam.sdk.coders.Coder.java
/** * Returns the size in bytes of the encoded value using this coder. *///from w w w. j a v a 2 s . co m protected long getEncodedElementByteSize(T value) throws Exception { try (CountingOutputStream os = new CountingOutputStream(ByteStreams.nullOutputStream())) { encode(value, os); return os.getCount(); } catch (Exception exn) { throw new IllegalArgumentException( "Unable to encode element '" + value + "' with coder '" + this + "'.", exn); } }
From source file:ru.runa.wf.logic.bot.WebServiceTaskHandler.java
/** * Called to process response from web service with code from [200; 299] * (This codes indicates successful request processing). * //from w ww. ja va 2 s . c o m * @param task * Current task instance to be processed. * @param connection * HTTP connection to communicate with web service. * @param interaction * Current processing interaction. */ private void onResponse(WfTask task, HttpURLConnection connection, Interaction interaction) throws Exception { if (interaction.responseXSLT == null && interaction.responseVariable == null) { return; } String response = logResponseAndSetVariable(task, connection, interaction); InputStream inputStream = response == null ? connection.getInputStream() : new ByteArrayInputStream(response.getBytes(settings.encoding)); if (interaction.responseXSLT != null) { Transformer transformer = TransformerFactory.newInstance().newTransformer(new StreamSource( new ByteArrayInputStream(interaction.responseXSLT.getBytes(settings.encoding)))); transformer.transform(new StreamSource(inputStream), new StreamResult(ByteStreams.nullOutputStream())); } }
From source file:org.apache.beam.sdk.testing.CoderProperties.java
/** * A utility method that passes the given (unencoded) elements through * coder's registerByteSizeObserver() and encode() methods, and confirms * they are mutually consistent. This is useful for testing coder * implementations.//w w w . j av a 2 s. c o m */ public static <T> void testByteCount(Coder<T> coder, Coder.Context context, T[] elements) throws Exception { TestElementByteSizeObserver observer = new TestElementByteSizeObserver(); try (CountingOutputStream os = new CountingOutputStream(ByteStreams.nullOutputStream())) { for (T elem : elements) { coder.registerByteSizeObserver(elem, observer); coder.encode(elem, os, context); observer.advance(); } long expectedLength = os.getCount(); if (!context.isWholeStream) { assertEquals(expectedLength, observer.getSum()); } assertEquals(elements.length, observer.getCount()); } }
From source file:edu.byu.nlp.al.app.CrowdsourcingActiveMeasurement.java
private static PrintWriter nullWriter() { return new PrintWriter(ByteStreams.nullOutputStream()); }
From source file:edu.byu.nlp.crowdsourcing.models.gibbs.BlockCollapsedMultiAnnModel.java
/** {@inheritDoc} */ @Override//from ww w .jav a 2 s . c o m public DatasetLabeler getIntermediateLabeler() { final MultiAnnModel thisModel = this; return new DatasetLabeler() { @Override public Predictions label(Dataset trainingInstances, Dataset heldoutInstances) { return new MultiAnnDatasetLabeler(thisModel, new PrintWriter(ByteStreams.nullOutputStream()), true, DiagonalizationMethod.NONE, false, 0, trainingInstances, rnd).label(trainingInstances, heldoutInstances); } }; }