List of usage examples for org.apache.commons.io.output NullOutputStream nullOutputStream
public static OutputStream nullOutputStream()
From source file:org.archive.io.arc.ARCWriterTest.java
public void testWriteGiantRecord() throws IOException { PrintStream dummyStream = new PrintStream(new NullOutputStream()); ARCWriter arcWriter = new ARCWriter(SERIAL_NO, dummyStream, new File("dummy"), new WriterPoolSettingsData("", "", -1, false, null, null)); assertNotNull(arcWriter);/*w w w.j a v a 2 s. com*/ // Start the record with an arbitrary 14-digit date per RFC2540 long now = System.currentTimeMillis(); long recordLength = org.apache.commons.io.FileUtils.ONE_GB * 3; arcWriter.write("dummy:uri", "application/octet-stream", "0.1.2.3", now, recordLength, new NullInputStream(recordLength)); arcWriter.close(); }
From source file:org.artifactory.engine.UploadServiceImpl.java
private void consumeRequestBody(ArtifactoryRequest request) throws IOException { IOUtils.copy(request.getInputStream(), new NullOutputStream()); }
From source file:org.artifactory.request.InternalArtifactoryResponse.java
@Override public OutputStream getOutputStream() throws IOException { return new NullOutputStream(); }
From source file:org.artifactory.traffic.read.TrafficReaderTest.java
/** * Test the stream writer with valid in-range dates *//*w w w . jav a 2 s . c o m*/ public void testEntriesStream() { Date[] dateRange = findDateRange(); trafficReader = new TrafficReader(new File(trafficLogDir.getFile())); Date startDate = dateRange[0]; Date endDate = dateRange[1]; long charsWritten = trafficReader.writeFileToStream(new NullOutputStream(), startDate, endDate); assertTrue(charsWritten > 0); }
From source file:org.carrot2.core.ProcessingResultTest.java
private void checkSerializationDeserialization(boolean documentsDeserialized, boolean clustersDeserialized, boolean attributesDeserialized) throws Exception { final ProcessingResult sourceProcessingResult = prepareProcessingResult(); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); sourceProcessingResult.serialize(new NullOutputStream()); sourceProcessingResult.serialize(outputStream, documentsDeserialized, clustersDeserialized, attributesDeserialized);/* w w w .j av a2 s . co m*/ CloseableUtils.close(outputStream); final ProcessingResult deserialized = ProcessingResult .deserialize(new ByteArrayInputStream(outputStream.toByteArray())); assertNotNull(deserialized); assertNotNull(deserialized.getAttributes()); if (documentsDeserialized) { assertThatDocuments(deserialized.getDocuments()).isEquivalentTo(sourceProcessingResult.getDocuments()); } else { Assertions.assertThat(deserialized.getDocuments()).isNull(); } if (clustersDeserialized) { assertThatClusters(deserialized.getClusters()).isEquivalentTo(sourceProcessingResult.getClusters(), documentsDeserialized); } else { Assertions.assertThat(deserialized.getClusters()).isNull(); } if (attributesDeserialized) { Assertions.assertThat(deserialized.getAttribute(AttributeNames.RESULTS)) .isEqualTo(sourceProcessingResult.getAttribute(AttributeNames.RESULTS)); } else { Assertions.assertThat(deserialized.getAttribute(AttributeNames.RESULTS)).isNull(); } Assertions.assertThat(deserialized.getAttributes().get(AttributeNames.QUERY)) .isEqualTo(sourceProcessingResult.getAttributes().get(AttributeNames.QUERY)); }
From source file:org.cc86.MMC.modules.audio.SWTTYProvider.java
private static void setup() { Tools.runCmdWithPassthru(IoBuilder.forLogger("External.sudoedChmod").buildPrintStream(), "sudo", "chmod", "777", "/sys/class/softuart/softuart/data"); Tools.runCmdWithPassthru(new PrintStream(new NullOutputStream()), "cat", "/sys/class/softuart/softuart/data"); }
From source file:org.cesecore.util.PKIXCertRevocationStatusChecker.java
/** * Reads the content of 'httpErrorStream' and ignores it. *//* w w w. j a v a 2 s . c o m*/ private void handleContentOfErrorStream(final InputStream httpErrorStream) { if (httpErrorStream != null) { try { OutputStream os = new NullOutputStream(); IOUtils.copy(httpErrorStream, os); httpErrorStream.close(); os.close(); } catch (IOException ex) { } } }
From source file:org.cruk.genologics.api.GenologicsAPIBatchOperationTest.java
@Test public void testArtifactBatchFetch() throws Exception { List<LimsLink<Artifact>> links = new ArrayList<LimsLink<Artifact>>(); links.add(new ArtifactLink(new URI("http://limsdev.cri.camres.org:8080/api/v2/artifacts/2-1000624"))); links.add(new ArtifactLink(new URI("http://limsdev.cri.camres.org:8080/api/v2/artifacts/2-1000622"))); links.add(new ArtifactLink(new URI("http://limsdev.cri.camres.org:8080/api/v2/artifacts/2-1000605"))); links.add(new ArtifactLink(new URI("http://limsdev.cri.camres.org:8080/api/v2/artifacts/2-1000623"))); links.add(new ArtifactLink(new URI("http://limsdev.cri.camres.org:8080/api/v2/artifacts/2-1000625"))); File expectedResultFile = new File("src/test/xml/batchtestreordering-artifacts.xml"); String expectedReply = FileUtils.readFileToString(expectedResultFile); URI uri = new URI("http://limsdev.cri.camres.org:8080/api/v2/artifacts/batch/retrieve"); // Note: need PushbackInputStream to prevent the call to getBody() being made more than once. // See MessageBodyClientHttpResponseWrapper. InputStream responseStream = new PushbackInputStream(new ByteArrayInputStream(expectedReply.getBytes())); HttpHeaders headers = new HttpHeaders(); ClientHttpResponse httpResponse = EasyMock.createMock(ClientHttpResponse.class); EasyMock.expect(httpResponse.getStatusCode()).andReturn(HttpStatus.OK).anyTimes(); EasyMock.expect(httpResponse.getRawStatusCode()).andReturn(HttpStatus.OK.value()).anyTimes(); EasyMock.expect(httpResponse.getHeaders()).andReturn(headers).anyTimes(); EasyMock.expect(httpResponse.getBody()).andReturn(responseStream).once(); httpResponse.close();/*from w ww . j a v a 2 s .c o m*/ EasyMock.expectLastCall().once(); ClientHttpRequest httpRequest = EasyMock.createMock(ClientHttpRequest.class); EasyMock.expect(httpRequest.getHeaders()).andReturn(headers).anyTimes(); EasyMock.expect(httpRequest.getBody()).andReturn(new NullOutputStream()).times(0, 2); EasyMock.expect(httpRequest.execute()).andReturn(httpResponse).once(); ClientHttpRequestFactory mockFactory = EasyMock.createStrictMock(ClientHttpRequestFactory.class); EasyMock.expect(mockFactory.createRequest(uri, HttpMethod.POST)).andReturn(httpRequest).once(); restTemplate.setRequestFactory(mockFactory); EasyMock.replay(httpResponse, httpRequest, mockFactory); List<Artifact> artifacts = api.loadAll(links); assertEquals("Wrong number of artifacts", links.size(), artifacts.size()); for (int i = 0; i < links.size(); i++) { assertTrue("Artifact " + i + " wrong: " + artifacts.get(i).getUri(), artifacts.get(i).getUri().toString().startsWith(links.get(i).getUri().toString())); } EasyMock.verify(httpResponse, httpRequest, mockFactory); }
From source file:org.cruk.genologics.api.GenologicsAPIBatchOperationTest.java
@Test public void testArtifactBatchUpdate() throws Exception { File expectedResultFile = new File("src/test/xml/batchtestreordering-artifacts.xml"); String expectedReply = FileUtils.readFileToString(expectedResultFile); ArtifactBatchFetchResult updateArtifactsFetch = (ArtifactBatchFetchResult) marshaller .unmarshal(new StreamSource(expectedResultFile)); List<Artifact> artifacts = updateArtifactsFetch.getArtifacts(); // Rearrange these to a different order to that in the file. // This means the original XML file loaded above will return in an order // not matching either the Links object (below) or the original order // of the artifacts. Collections.shuffle(artifacts, new Random(997)); // Copy the URI order as it is now to make sure it doesn't differ // after updating the artifacts. List<URI> uriOrder = new ArrayList<URI>(); Links confirmLinks = new Links(); for (Artifact a : artifacts) { uriOrder.add(a.getUri());/*from w ww. j av a2 s.c om*/ confirmLinks.getLinks().add(new Link(a)); } // The Links object that (would) come back should be in a different order. Collections.shuffle(confirmLinks.getLinks(), new Random(1024)); StringWriter linksXML = new StringWriter(); marshaller.marshal(confirmLinks, new StreamResult(linksXML)); // Two calls to make here. URI updateUri = new URI("http://limsdev.cri.camres.org:8080/api/v2/artifacts/batch/update"); URI retrieveUri = new URI("http://limsdev.cri.camres.org:8080/api/v2/artifacts/batch/retrieve"); // Note: need PushbackInputStream to prevent the call to getBody() being made more than once. // See MessageBodyClientHttpResponseWrapper. InputStream response1Stream = new PushbackInputStream( new ByteArrayInputStream(linksXML.toString().getBytes())); InputStream response2Stream = new PushbackInputStream(new ByteArrayInputStream(expectedReply.getBytes())); HttpHeaders headers = new HttpHeaders(); ClientHttpResponse httpResponse1 = EasyMock.createMock(ClientHttpResponse.class); EasyMock.expect(httpResponse1.getStatusCode()).andReturn(HttpStatus.OK).anyTimes(); EasyMock.expect(httpResponse1.getRawStatusCode()).andReturn(HttpStatus.OK.value()).anyTimes(); EasyMock.expect(httpResponse1.getHeaders()).andReturn(headers).anyTimes(); EasyMock.expect(httpResponse1.getBody()).andReturn(response1Stream).once(); httpResponse1.close(); EasyMock.expectLastCall().once(); ClientHttpRequest httpRequest1 = EasyMock.createMock(ClientHttpRequest.class); EasyMock.expect(httpRequest1.getHeaders()).andReturn(headers).anyTimes(); EasyMock.expect(httpRequest1.getBody()).andReturn(new NullOutputStream()).times(0, 2); EasyMock.expect(httpRequest1.execute()).andReturn(httpResponse1).once(); ClientHttpResponse httpResponse2 = EasyMock.createMock(ClientHttpResponse.class); EasyMock.expect(httpResponse2.getStatusCode()).andReturn(HttpStatus.OK).anyTimes(); EasyMock.expect(httpResponse2.getRawStatusCode()).andReturn(HttpStatus.OK.value()).anyTimes(); EasyMock.expect(httpResponse2.getHeaders()).andReturn(headers).anyTimes(); EasyMock.expect(httpResponse2.getBody()).andReturn(response2Stream).once(); httpResponse2.close(); EasyMock.expectLastCall().once(); ClientHttpRequest httpRequest2 = EasyMock.createMock(ClientHttpRequest.class); EasyMock.expect(httpRequest2.getHeaders()).andReturn(headers).anyTimes(); EasyMock.expect(httpRequest2.getBody()).andReturn(new NullOutputStream()).times(0, 2); EasyMock.expect(httpRequest2.execute()).andReturn(httpResponse2).once(); ClientHttpRequestFactory mockFactory = EasyMock.createStrictMock(ClientHttpRequestFactory.class); EasyMock.expect(mockFactory.createRequest(updateUri, HttpMethod.POST)).andReturn(httpRequest1).once(); EasyMock.expect(mockFactory.createRequest(retrieveUri, HttpMethod.POST)).andReturn(httpRequest2).once(); restTemplate.setRequestFactory(mockFactory); EasyMock.replay(httpResponse1, httpRequest1, httpResponse2, httpRequest2, mockFactory); api.updateAll(artifacts); assertEquals("Wrong number of artifacts", uriOrder.size(), artifacts.size()); for (int i = 0; i < uriOrder.size(); i++) { assertEquals("Artifact " + i + " wrong:", uriOrder.get(i), artifacts.get(i).getUri()); } EasyMock.verify(httpResponse2, httpRequest2, mockFactory); }
From source file:org.cryptomator.crypto.aes256.Aes256Cryptor.java
@Override public boolean authenticateContent(SeekableByteChannel encryptedFile) throws IOException { // init mac:/*from w ww. jav a 2 s. c o m*/ final Mac calculatedMac = this.hmacSha256(hMacMasterKey); // read stored mac: encryptedFile.position(16); final ByteBuffer storedMac = ByteBuffer.allocate(calculatedMac.getMacLength()); final int numMacBytesRead = encryptedFile.read(storedMac); // check validity of header: if (numMacBytesRead != calculatedMac.getMacLength()) { throw new IOException("Failed to read file header."); } // read all encrypted data and calculate mac: encryptedFile.position(64); final InputStream in = new SeekableByteChannelInputStream(encryptedFile); final InputStream macIn = new MacInputStream(in, calculatedMac); IOUtils.copyLarge(macIn, new NullOutputStream()); // compare (in constant time): return MessageDigest.isEqual(storedMac.array(), calculatedMac.doFinal()); }