List of usage examples for org.apache.commons.io.output NullOutputStream nullOutputStream
public static OutputStream nullOutputStream()
From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditN3UtilsTest.java
private boolean isSerializableAsXML(Model m) { try {// w w w. ja v a 2 s .c om NullOutputStream nullStream = new NullOutputStream(); m.write(nullStream, "RDF/XML"); return true; } catch (Exception e) { return false; } }
From source file:net.oneandone.stool.util.StoolLogFileAppender.java
@Override public void openFile(String filename) throws IOException { synchronized (lock) { File file = new File(filename); if (FileUtil.isParentDirectoryCreationRequired(file)) { addError("Parent does not exist. Ignoring. [" + file.getAbsolutePath() + "]"); setOutputStream(new NullOutputStream()); } else {// w ww .ja v a 2 s . co m ResilientFileOutputStream resilientFos = new ResilientFileOutputStream(file, append); resilientFos.setContext(context); setOutputStream(resilientFos); } } }
From source file:io.lightlink.output.JsonStreamTestPerf.java
public void test() throws IOException, InterruptedException { JSONResponseStream bufferResponseStream; HashMap<String, Object> map = getData(); LightLinkFilter.setThreadLocalStreamingData(new StreamingResponseData(null, null)); bufferResponseStream = new JSONResponseStream(new NullOutputStream(), null); bufferResponseStream.writePropertyArrayStart("resultSet"); for (int i = 0; i < 100000; i++) { bufferResponseStream.writeFullObjectToArray(map); }// www . j a va2s . c om bufferResponseStream = new JSONResponseStream(new NullOutputStream(), null); bufferResponseStream.writePropertyArrayStart("resultSet"); long l = System.currentTimeMillis(); for (int i = 0; i < 100000; i++) { bufferResponseStream.writeFullObjectToArray(map); } System.out.println("time prd:" + (System.currentTimeMillis() - l) / 1000F); System.setProperty("lightlink.debug", "true"); bufferResponseStream = new JSONResponseStream(new NullOutputStream(), null); bufferResponseStream.writePropertyArrayStart("resultSet"); l = System.currentTimeMillis(); for (int i = 0; i < 100000; i++) { bufferResponseStream.writeFullObjectToArray(map); } System.out.println("time debug:" + (System.currentTimeMillis() - l) / 1000F); }
From source file:com.thoughtworks.go.agent.launcher.DownloadableFile.java
protected static boolean matchChecksum(File localFile, String expectedSignature) { try (FileInputStream input = new FileInputStream(localFile)) { MessageDigest digester = MessageDigest.getInstance("MD5"); try (DigestInputStream digest = new DigestInputStream(input, digester)) { IOUtils.copy(digest, new NullOutputStream()); }/*from ww w. j av a 2 s. c om*/ return expectedSignature.equalsIgnoreCase(encodeHexString(digester.digest())); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.vitesify.languidmpd.streams.TestMPDStreamProcessor.java
@Test public void test_send_single_command() throws IOException { InputStream is = new ReaderInputStream(new StringReader("OK\nOK\nNOT OK\nOK"), Charset.forName("UTF-8")); OutputStream os = new NullOutputStream(); MPDStreamProcesser mpdsp = new MPDStreamProcesser(is, os); Set<String> s = Collections.emptySet(); assertTrue(mpdsp.send_command(Message.STATUS, s)); assertTrue(mpdsp.last_command_succeeded()); assertTrue(mpdsp.get_return_code().endsWith("NOT OK\n")); }
From source file:net.krotscheck.dfr.stream.AbstractStreamEncoderTest.java
/** * Assert that we can change the destination. * * @throws Exception Should not be thrown. *//*from w w w .j ava 2s . c o m*/ @Test public void testGetSetDestination() throws Exception { IStreamEncoder encoder = new TestStreamEncoder(); Assert.assertNull(encoder.getOutputStream()); // Test input stream OutputStream stream = new NullOutputStream(); encoder.setOutputStream(stream); Assert.assertEquals(stream, encoder.getOutputStream()); }
From source file:fi.jumi.core.stdout.SynchronizedPrintStreamTest.java
/** * For example {@link Throwable#printStackTrace} does this, we must be careful to always acquire a lock on the * monitor of the PrintStream first, before all other locks. *///from w w w . j a v a 2 s . c o m @Test public void does_not_deadlock_if_somebody_locks_in_the_PrintStream_externally() throws Exception { final int ITERATIONS = 10; PrintStream printStream = SynchronizedPrintStream.create(new NullOutputStream(), Charset.defaultCharset(), lock); // will fail with a test timeout if a deadlock happens runConcurrently(() -> { // what Thread.printStackTrace() would do synchronized (printStream) { for (int i = 0; i < ITERATIONS; i++) { Thread.yield(); printStream.print("X"); } } }, () -> { // what a normal printer would do for (int i = 0; i < ITERATIONS; i++) { Thread.yield(); printStream.print("X"); } }); }
From source file:com.redhat.akashche.wixgen.jaxb.SampleInstallerTest.java
@Test public void test() throws Exception { JAXBContext jaxb = JAXBContext.newInstance(SampleInstallerTest.class.getPackage().getName()); InputStream is = null;//from w w w . j a v a 2 s . c om Writer writer = null; try { is = SampleInstallerTest.class.getResourceAsStream("SampleInstaller.wxs"); Reader reader = new InputStreamReader(is, Charset.forName("UTF-8")); Wix wix = (Wix) jaxb.createUnmarshaller().unmarshal(reader); wix.getProduct().setName(wix.getProduct().getName() + " (JAXB)"); // OutputStream os = new FileOutputStream("SampleInstaller_JAXB.wxs"); OutputStream os = new NullOutputStream(); writer = new OutputStreamWriter(os, Charset.forName("UTF-8")); Marshaller marshaller = jaxb.createMarshaller(); marshaller.setProperty(JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(wix, writer); } finally { closeQuietly(is); closeQuietly(writer); } }
From source file:eu.peppol.document.PayloadDigestCalculator.java
public static MessageDigestResult calcDigest(String algorithm, StandardBusinessDocumentHeader sbdh, InputStream inputStream) { MessageDigest messageDigest;//from ww w .j a v a2 s.c o m try { messageDigest = MessageDigest.getInstance(algorithm); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException( "Unknown digest algorithm " + OxalisConstant.DEFAULT_DIGEST_ALGORITHM + " " + e.getMessage(), e); } InputStream inputStreamToCalculateDigestFrom = null; ManifestItem manifestItem = SbdhFastParser.searchForAsicManifestItem(sbdh); if (manifestItem != null) { // creates an FilterInputStream, which will extract the ASiC in binary format. inputStreamToCalculateDigestFrom = new Base64InputStream(new AsicFilterInputStream(inputStream)); } else inputStreamToCalculateDigestFrom = inputStream; DigestInputStream digestInputStream = new DigestInputStream( new BufferedInputStream(inputStreamToCalculateDigestFrom), messageDigest); try { IOUtils.copy(digestInputStream, new NullOutputStream()); } catch (IOException e) { throw new IllegalStateException("Unable to calculate digest for payload"); } return new MessageDigestResult(messageDigest.digest(), messageDigest.getAlgorithm()); }
From source file:com.netflix.imfutility.util.conversion.executor.FakeProcess.java
@Override public OutputStream getOutputStream() { return new NullOutputStream() { @Override// w w w. jav a 2 s . co m public void close() throws IOException { super.close(); if (!closed) { executorLogger.finishProcess(processInfo); closed = true; } } }; }