org.apache.commons.io.input.NullInputStream Java Examples
The following examples show how to use
org.apache.commons.io.input.NullInputStream.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FortifySscClientTest.java From dependency-track with Apache License 2.0 | 6 votes |
@Test public void testUploadFindingsNegativeCase() throws Exception { String token = "db975c97-98b1-4988-8d6a-9c3e044dfff3"; String applicationVersion = ""; new MockServerClient("localhost", 1080) .when( request() .withMethod("POST") .withHeader(HttpHeaders.ACCEPT, "application/xml") .withPath("/ssc/upload/resultFileUpload.html?mat=" + token + "&engineType=DEPENDENCY_TRACK&entityId=" + applicationVersion) .withQueryStringParameter("engineType", "DEPENDENCY_TRACK") .withQueryStringParameter("mat", token) .withQueryStringParameter("entityId", applicationVersion) ) .respond( response() .withStatusCode(400) .withHeader(HttpHeaders.CONTENT_TYPE, "application/xml") ); FortifySscUploader uploader = new FortifySscUploader(); FortifySscClient client = new FortifySscClient(uploader, new URL("https://localhost/ssc")); client.uploadDependencyTrackFindings(token, applicationVersion, new NullInputStream(16)); }
Example #2
Source File: FortifySscClientTest.java From dependency-track with Apache License 2.0 | 6 votes |
@Test public void testUploadFindingsPositiveCase() throws Exception { String token = "db975c97-98b1-4988-8d6a-9c3e044dfff3"; String applicationVersion = "12345"; new MockServerClient("localhost", 1080) .when( request() .withMethod("POST") .withHeader(HttpHeaders.ACCEPT, "application/xml") .withPath("/ssc/upload/resultFileUpload.html?mat=" + token + "&engineType=DEPENDENCY_TRACK&entityId=" + applicationVersion) .withQueryStringParameter("engineType", "DEPENDENCY_TRACK") .withQueryStringParameter("mat", token) .withQueryStringParameter("entityId", applicationVersion) ) .respond( response() .withStatusCode(200) .withHeader(HttpHeaders.CONTENT_TYPE, "application/xml") ); FortifySscUploader uploader = new FortifySscUploader(); FortifySscClient client = new FortifySscClient(uploader, new URL("https://localhost/ssc")); client.uploadDependencyTrackFindings(token, applicationVersion, new NullInputStream(0)); }
Example #3
Source File: ARCWriterTest.java From webarchive-commons with Apache License 2.0 | 6 votes |
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); // 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(); }
Example #4
Source File: ReleasableInputStreamTest.java From data-prep with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { releasableInputStream = new ReleasableInputStream(new NullInputStream(2048), () -> wasCalled.set(true)); failedReleasableInputStream = new ReleasableInputStream(new InputStream() { @Override public int read() throws IOException { throw new IOException("Oops"); } @Override public int available() throws IOException { throw new IOException("Oops"); } @Override public synchronized void mark(int readlimit) { throw new RuntimeException("Oops"); } }, () -> wasCalled.set(true)); }
Example #5
Source File: StoregateMultipartWriteFeatureTest.java From cyberduck with GNU General Public License v3.0 | 6 votes |
@Test public void testWriteZeroLength() throws Exception { final StoregateIdProvider nodeid = new StoregateIdProvider(session).withCache(cache); final Path room = new StoregateDirectoryFeature(session, nodeid).mkdir( new Path(String.format("/My files/%s", new AlphanumericRandomStringService().random()), EnumSet.of(Path.Type.directory, Path.Type.volume)), null, new TransferStatus()); final TransferStatus status = new TransferStatus(); final Path test = new Path(room, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); final StoregateMultipartWriteFeature writer = new StoregateMultipartWriteFeature(session, nodeid); final HttpResponseOutputStream<VersionId> out = writer.write(test, status, new DisabledConnectionCallback()); assertNotNull(out); new StreamCopier(status, status).transfer(new NullInputStream(0L), out); final VersionId version = out.getStatus(); assertNotNull(version); assertTrue(new DefaultFindFeature(session).find(test)); new StoregateDeleteFeature(session, nodeid).delete(Collections.singletonList(room), new DisabledLoginCallback(), new Delete.DisabledCallback()); }
Example #6
Source File: SDSMultipartWriteFeatureTest.java From cyberduck with GNU General Public License v3.0 | 6 votes |
@Test public void testWriteZeroLength() throws Exception { final SDSNodeIdProvider nodeid = new SDSNodeIdProvider(session).withCache(cache); final Path room = new SDSDirectoryFeature(session, nodeid).mkdir( new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory, Path.Type.volume, Path.Type.triplecrypt)), null, new TransferStatus()); final TransferStatus status = new TransferStatus(); final Path test = new Path(room, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); final SDSMultipartWriteFeature writer = new SDSMultipartWriteFeature(session, nodeid); final HttpResponseOutputStream<VersionId> out = writer.write(test, status, new DisabledConnectionCallback()); assertNotNull(out); new StreamCopier(status, status).transfer(new NullInputStream(0L), out); final VersionId version = out.getStatus(); assertNotNull(version); assertTrue(new DefaultFindFeature(session).find(test)); new SDSDeleteFeature(session, nodeid).delete(Collections.singletonList(room), new DisabledLoginCallback(), new Delete.DisabledCallback()); }
Example #7
Source File: AwsHttpServletRequest.java From aws-serverless-java-container with Apache License 2.0 | 6 votes |
protected ServletInputStream bodyStringToInputStream(String body, boolean isBase64Encoded) throws IOException { if (body == null) { return new AwsServletInputStream(new NullInputStream(0, false, false)); } byte[] bodyBytes; if (isBase64Encoded) { bodyBytes = Base64.getMimeDecoder().decode(body); } else { String encoding = getCharacterEncoding(); if (encoding == null) { encoding = StandardCharsets.ISO_8859_1.name(); } try { bodyBytes = body.getBytes(encoding); } catch (Exception e) { log.error("Could not read request with character encoding: " + SecurityUtils.crlf(encoding), e); bodyBytes = body.getBytes(StandardCharsets.ISO_8859_1.name()); } } ByteArrayInputStream requestBodyStream = new ByteArrayInputStream(bodyBytes); return new AwsServletInputStream(requestBodyStream); }
Example #8
Source File: S3DirectoryFeature.java From cyberduck with GNU General Public License v3.0 | 6 votes |
@Override public Path mkdir(final Path folder, final String region, final TransferStatus status) throws BackgroundException { if(containerService.isContainer(folder)) { final S3BucketCreateService service = new S3BucketCreateService(session); service.create(folder, StringUtils.isBlank(region) ? PreferencesFactory.get().getProperty("s3.location") : region); return folder; } else { status.setChecksum(writer.checksum(folder, status).compute(new NullInputStream(0L), status)); // Add placeholder object status.setMime(MIMETYPE); final EnumSet<Path.Type> type = EnumSet.copyOf(folder.getType()); type.add(Path.Type.placeholder); final StatusOutputStream<StorageObject> out = writer.write(new Path(folder.getParent(), folder.getName(), type, new PathAttributes(folder.attributes())), status, new DisabledConnectionCallback()); new DefaultStreamCloser().close(out); final StorageObject metadata = out.getStatus(); return new Path(folder.getParent(), folder.getName(), type, new S3AttributesFinderFeature(session).toAttributes(metadata)); } }
Example #9
Source File: FileBuffer.java From cyberduck with GNU General Public License v3.0 | 6 votes |
@Override public synchronized int read(final byte[] chunk, final Long offset) throws IOException { final RandomAccessFile file = random(); if(offset < file.length()) { file.seek(offset); if(chunk.length + offset > file.length()) { return file.read(chunk, 0, (int) (file.length() - offset)); } else { return file.read(chunk, 0, chunk.length); } } else { final NullInputStream nullStream = new NullInputStream(length); if(nullStream.available() > 0) { nullStream.skip(offset); return nullStream.read(chunk, 0, chunk.length); } else { return IOUtils.EOF; } } }
Example #10
Source File: StreamCopierTest.java From cyberduck with GNU General Public License v3.0 | 5 votes |
@Test public void testTransferFixedLength() throws Exception { final TransferStatus status = new TransferStatus().length(432768L); new StreamCopier(status, status).withLimit(432768L).transfer(new NullInputStream(432768L), new NullOutputStream()); assertTrue(status.isComplete()); assertEquals(432768L, status.getOffset(), 0L); }
Example #11
Source File: B2TouchFeature.java From cyberduck with GNU General Public License v3.0 | 5 votes |
@Override public Path touch(final Path file, final TransferStatus status) throws BackgroundException { status.setChecksum(writer.checksum(file, status).compute(new NullInputStream(0L), status)); status.setTimestamp(System.currentTimeMillis()); final StatusOutputStream<BaseB2Response> out = writer.write(file, status, new DisabledConnectionCallback()); new DefaultStreamCloser().close(out); return new Path(file.getParent(), file.getName(), file.getType(), new B2AttributesFinderFeature(session, fileid).toAttributes((B2FileResponse) out.getStatus())); }
Example #12
Source File: StreamCopierTest.java From cyberduck with GNU General Public License v3.0 | 5 votes |
@Test public void testTransferFixedLengthIncomplete() throws Exception { final TransferStatus status = new TransferStatus().length(432768L); new StreamCopier(status, status).withLimit(432767L).transfer(new NullInputStream(432768L), new NullOutputStream()); assertEquals(432767L, status.getOffset(), 0L); assertTrue(status.isComplete()); }
Example #13
Source File: StreamCopierTest.java From cyberduck with GNU General Public License v3.0 | 5 votes |
@Test public void testReadNoEndofStream() throws Exception { final TransferStatus status = new TransferStatus().length(432768L); new StreamCopier(status, status).withLimit(432768L).transfer(new NullInputStream(432770L), new NullOutputStream()); assertEquals(432768L, status.getOffset(), 0L); assertTrue(status.isComplete()); }
Example #14
Source File: CRC32ChecksumComputeTest.java From cyberduck with GNU General Public License v3.0 | 5 votes |
@Test public void testCompute() throws Exception { assertEquals("0", new CRC32ChecksumCompute().compute(new NullInputStream(0), new TransferStatus()).hash); assertEquals("d202ef8d", new CRC32ChecksumCompute().compute(new NullInputStream(1L), new TransferStatus()).hash); }
Example #15
Source File: MD5FastChecksumComputeTest.java From cyberduck with GNU General Public License v3.0 | 5 votes |
@Test public void testComputeEmptyString() throws Exception { assertEquals("d41d8cd98f00b204e9800998ecf8427e", new MD5FastChecksumCompute().compute(IOUtils.toInputStream("", Charset.defaultCharset()), new TransferStatus()).hash); assertEquals("d41d8cd98f00b204e9800998ecf8427e", new MD5FastChecksumCompute().compute(new NullInputStream(0L), new TransferStatus().length(0)).hash); }
Example #16
Source File: AwsServletInputStream.java From aws-serverless-java-container with Apache License 2.0 | 5 votes |
@Override public int read() throws IOException { if (bodyStream == null || bodyStream instanceof NullInputStream) { return -1; } int readByte = bodyStream.read(); if (readByte == -1) { finished = true; } return readByte; }
Example #17
Source File: FileResourceUtils.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public InputStream openStream() throws IOException { try { return file.getInputStream(); } catch ( IOException ioe ) { return new NullInputStream( 0 ); } }
Example #18
Source File: FileResourceController.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public InputStream openStream() throws IOException { try { return file.getInputStream(); } catch ( IOException ioe ) { return new NullInputStream( 0 ); } }
Example #19
Source File: CompressedContentExtractor.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
/** * Checks if a file exists in the zip * * @param payload zip file as a payload * @param path path of stream to be extracted * @param fileName file to check exists * @return true if it exists */ public boolean fileExists(final Payload payload, final String path, final String fileName) { try (InputStream projectAsStream = payload.openInputStream()) { return extract(projectAsStream, fileName, (ZipInputStream z) -> new NullInputStream(-1)) != null; } catch (IOException e) { log.warn("Unable to open content {}", path, e); } return false; }
Example #20
Source File: S3ReadFeature.java From cyberduck with GNU General Public License v3.0 | 5 votes |
@Override public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { if(file.getType().contains(Path.Type.upload)) { return new NullInputStream(0L); } final HttpRange range = HttpRange.withStatus(status); final RequestEntityRestStorageService client = session.getClient(); final S3Object object = client.getVersionedObject( file.attributes().getVersionId(), containerService.getContainer(file).getName(), containerService.getKey(file), null, // ifModifiedSince null, // ifUnmodifiedSince null, // ifMatch null, // ifNoneMatch status.isAppend() ? range.getStart() : null, status.isAppend() ? (range.getEnd() == -1 ? null : range.getEnd()) : null); if(log.isDebugEnabled()) { log.debug(String.format("Reading stream with content length %d", object.getContentLength())); } return object.getDataInputStream(); } catch(ServiceException e) { throw new S3ExceptionMappingService().map("Download {0} failed", e, file); } }
Example #21
Source File: SpectraDirectoryFeature.java From cyberduck with GNU General Public License v3.0 | 5 votes |
@Override public Path mkdir(final Path folder, final String region, final TransferStatus status) throws BackgroundException { if(containerService.isContainer(folder)) { return super.mkdir(folder, region, status); } else { status.setChecksum(writer.checksum(folder, status).compute(new NullInputStream(0L), status)); return super.mkdir(folder, region, status); } }
Example #22
Source File: CryptoChecksumCompute.java From cyberduck with GNU General Public License v3.0 | 5 votes |
@Override public Checksum compute(final InputStream in, final TransferStatus status) throws ChecksumException { if(Checksum.NONE == delegate.compute(new NullInputStream(0L), new TransferStatus())) { return Checksum.NONE; } if(null == status.getHeader()) { // Write header to be reused in writer final FileHeader header = cryptomator.getFileHeaderCryptor().create(); status.setHeader(cryptomator.getFileHeaderCryptor().encryptHeader(header)); } // Make nonces reusable in case we need to compute a checksum status.setNonces(new RotatingNonceGenerator(cryptomator.numberOfChunks(status.getLength()))); return this.compute(this.normalize(in, status), status.getOffset(), status.getHeader(), status.getNonces()); }
Example #23
Source File: MD5ChecksumComputeTest.java From cyberduck with GNU General Public License v3.0 | 5 votes |
@Test public void testComputeEmptyString() throws Exception { assertEquals("d41d8cd98f00b204e9800998ecf8427e", new MD5ChecksumCompute().compute(IOUtils.toInputStream("", Charset.defaultCharset()), new TransferStatus()).hash); assertEquals("d41d8cd98f00b204e9800998ecf8427e", new MD5ChecksumCompute().compute(new NullInputStream(0L), new TransferStatus().length(0)).hash); }
Example #24
Source File: S3TouchFeature.java From cyberduck with GNU General Public License v3.0 | 5 votes |
@Override public Path touch(final Path file, final TransferStatus status) throws BackgroundException { status.setChecksum(writer.checksum(file, status).compute(new NullInputStream(0L), status)); status.setLength(0L); final StatusOutputStream<StorageObject> out = writer.write(file, status, new DisabledConnectionCallback()); new DefaultStreamCloser().close(out); final S3Object metadata = (S3Object) out.getStatus(); return new Path(file.getParent(), file.getName(), file.getType(), new S3AttributesFinderFeature(session).toAttributes(metadata)); }
Example #25
Source File: S3SingleUploadServiceTest.java From cyberduck with GNU General Public License v3.0 | 5 votes |
@Test public void testDecorate() throws Exception { final NullInputStream n = new NullInputStream(1L); final S3Session session = new S3Session(new Host(new S3Protocol())); assertSame(NullInputStream.class, new S3SingleUploadService(session, new S3WriteFeature(session, new S3DisabledMultipartService())).decorate(n, null).getClass()); }
Example #26
Source File: DisabledChecksumComputeTest.java From cyberduck with GNU General Public License v3.0 | 5 votes |
@Test(expected = IOException.class) public void compute() throws Exception { final NullInputStream in = new NullInputStream(0L); new DisabledChecksumCompute().compute(in, new TransferStatus()); assertEquals(-1, in.read()); in.read(); }
Example #27
Source File: SHA1ChecksumComputeTest.java From cyberduck with GNU General Public License v3.0 | 4 votes |
@Test public void testCompute() throws Exception { assertEquals("da39a3ee5e6b4b0d3255bfef95601890afd80709", new SHA1ChecksumCompute().compute(new NullInputStream(0), new TransferStatus()).hash); }
Example #28
Source File: SHA512ChecksumComputeTest.java From cyberduck with GNU General Public License v3.0 | 4 votes |
@Test public void testCompute() throws Exception { assertEquals("cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e", new SHA512ChecksumCompute().compute(new NullInputStream(0), new TransferStatus()).hash); }
Example #29
Source File: GoogleStorageReadFeature.java From cyberduck with GNU General Public License v3.0 | 4 votes |
@Override public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { if(0L == status.getLength()) { return new NullInputStream(0L); } final StringBuilder uri = new StringBuilder(String.format("%sstorage/v1/b/%s/o/%s?alt=media", session.getClient().getRootUrl(), containerService.getContainer(file).getName(), GoogleStorageUriEncoder.encode(containerService.getKey(file)))); if(StringUtils.isNotBlank(file.attributes().getVersionId())) { uri.append(String.format("?generation=%s", file.attributes().getVersionId())); } final HttpUriRequest request = new HttpGet(uri.toString()); request.addHeader(HTTP.CONTENT_TYPE, MEDIA_TYPE); if(status.isAppend()) { final HttpRange range = HttpRange.withStatus(status); final String header; if(-1 == range.getEnd()) { header = String.format("bytes=%d-", range.getStart()); } else { header = String.format("bytes=%d-%d", range.getStart(), range.getEnd()); } if(log.isDebugEnabled()) { log.debug(String.format("Add range header %s for file %s", header, file)); } request.addHeader(new BasicHeader(HttpHeaders.RANGE, header)); // Disable compression request.addHeader(new BasicHeader(HttpHeaders.ACCEPT_ENCODING, "identity")); } final HttpClient client = session.getHttpClient(); final HttpResponse response = client.execute(request); switch(response.getStatusLine().getStatusCode()) { case HttpStatus.SC_OK: case HttpStatus.SC_PARTIAL_CONTENT: return new HttpMethodReleaseInputStream(response); default: throw new DefaultHttpResponseExceptionMappingService().map( new HttpResponseException(response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase())); } } catch(IOException e) { throw new GoogleStorageExceptionMappingService().map("Download {0} failed", e, file); } }
Example #30
Source File: NullLocal.java From cyberduck with GNU General Public License v3.0 | 4 votes |
@Override public InputStream getInputStream() { return new NullInputStream(0L); }