private String responseBody(CloseableHttpResponse response) throws IOException { try (InputStream is = response.getEntity() == null ? new NullInputStream(0) : response.getEntity().getContent()) { return IOUtils.toString(is, StandardCharsets.UTF_8); } }
private String responseBody(CloseableHttpResponse response) throws IOException { try (InputStream is = response.getEntity() == null ? new NullInputStream(0) : response.getEntity().getContent()) { return IOUtils.toString(is, StandardCharsets.UTF_8); } } }
@Test public void testCopy_inputStreamToOutputStream_IO84() throws Exception { final long size = (long)Integer.MAX_VALUE + (long)1; final InputStream in = new NullInputStream(size); final OutputStream out = new NullOutputStream(); // Test copy() method assertEquals(-1, IOUtils.copy(in, out)); // reset the input in.close(); // Test copyLarge() method assertEquals("copyLarge()", size, IOUtils.copyLarge(in, out)); }
@Test public void testLargeFiles_IO84() throws Exception { final long size = (long)Integer.MAX_VALUE + (long)1; final NullInputStream mock = new NullInputStream(size); final OutputStream nos = new NullOutputStream(); final CountingOutputStream cos = new CountingOutputStream(nos); // Test integer methods IOUtils.copyLarge(mock, cos); try { cos.getCount(); fail("Expected getCount() to throw an ArithmeticException"); } catch (final ArithmeticException ae) { // expected result } try { cos.resetCount(); fail("Expected resetCount() to throw an ArithmeticException"); } catch (final ArithmeticException ae) { // expected result } mock.close(); // Test long methods IOUtils.copyLarge(mock, cos); assertEquals("getByteCount()", size, cos.getByteCount()); assertEquals("resetByteCount()", size, cos.resetByteCount()); }
@Test public void testLargeFiles_IO84() throws Exception { final long size = (long)Integer.MAX_VALUE + (long)1; final NullInputStream mock = new NullInputStream(size); final CountingInputStream cis = new CountingInputStream(mock); final OutputStream out = new NullOutputStream(); // Test integer methods IOUtils.copyLarge(cis, out); try { cis.getCount(); fail("Expected getCount() to throw an ArithmeticException"); } catch (final ArithmeticException ae) { // expected result } try { cis.resetCount(); fail("Expected resetCount() to throw an ArithmeticException"); } catch (final ArithmeticException ae) { // expected result } mock.close(); // Test long methods IOUtils.copyLarge(cis, out); assertEquals("getByteCount()", size, cis.getByteCount()); assertEquals("resetByteCount()", size, cis.resetByteCount()); }
@Override public ServletInputStream getInputStream() throws IOException { if (request.getBody() == null) { return new AwsServletInputStream(new NullInputStream(0, false, false)); } byte[] bodyBytes = null; if (request.isBase64Encoded()) { bodyBytes = Base64.getMimeDecoder().decode(request.getBody()); } else { String encoding = getCharacterEncoding(); if (encoding == null) { encoding = StandardCharsets.ISO_8859_1.name(); } try { bodyBytes = request.getBody().getBytes(encoding); } catch (Exception e) { log.error("Could not read request with character encoding: " + SecurityUtils.crlf(encoding), e); bodyBytes = request.getBody().getBytes(StandardCharsets.ISO_8859_1.name()); } } ByteArrayInputStream requestBodyStream = new ByteArrayInputStream(bodyBytes); return new AwsServletInputStream(requestBodyStream); }
private CoreEvent createStreamPayloadEventWithLength(OptionalLong length) throws MuleException { return builder(testEvent()) .message(Message.builder().payload(new TypedValue(new NullInputStream(length.orElse(-1l)), INPUT_STREAM, length)) .build()) .build(); }
private CoreEvent createStreamPayloadEventWithLength(OptionalLong length) throws MuleException { return builder(testEvent()) .message(Message.builder().payload(new TypedValue(new NullInputStream(length.orElse(-1l)), INPUT_STREAM, length)) .build()) .build(); }
@Override public InputStream getResponseBodyAsStream() throws IOException { if (httpResponse != null) { final HttpEntity httpEntity = httpResponse.getEntity(); if (httpEntity != null) { return httpEntity.getContent(); } } return new NullInputStream(0); }
/** * Create a HTTP method release input Stream * * @param response The HTTP response to read from * @throws IOException If there is a problem reading from the response * @throws NullPointerException If the response has no message entity */ public HttpMethodReleaseInputStream(final HttpResponse response) throws IOException { super(null == response.getEntity() ? new NullInputStream(0L) : response.getEntity().getContent()); this.response = response; }
public CommonsHttpResponse(final HttpResponse response) throws IOException { super(null == response.getEntity() ? new NullInputStream(0L) : new HttpMethodReleaseInputStream(response)); this.response = response; }
@Override public ServletInputStream getInputStream() throws IOException { final InputStream stream = new NullInputStream(getContentLength()); return new ServletInputStream() { @Override public int read() throws IOException { return stream.read(); } }; }
static void writeFile(Directory directory, String fileName, long size) throws Exception{ IndexOutput o = directory.createOutput(fileName, IOContext.DEFAULT); o.copyBytes(new InputStreamDataInput(new NullInputStream(size)), size); o.close(); }
@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 { if(Checksum.NONE == status.getChecksum()) { status.setChecksum(writer.checksum(folder).compute(new NullInputStream(0L), status)); } return super.mkdir(folder, region, status); } } }
private CoreEvent createStreamPayloadEventWithLength(OptionalLong length) throws MuleException { return builder(testEvent()) .message(Message.builder().payload(new TypedValue(new NullInputStream(length.orElse(-1l)), INPUT_STREAM, length)) .build()) .build(); }
@Test public void shouldHaveDataProperty() { InputStream stream = new NullInputStream(1); Segment segment = mockSegment(); when(segment.getLength()).thenReturn(1); Backend backend = mockBackend(); when(backend.getSegmentData("s")).thenReturn(Optional.of(stream)); PropertyState property = new DataSegmentNode(backend, "s", segment).getProperty("data"); assertEquals(Type.BINARY, property.getType()); assertSame(stream, property.getValue(Type.BINARY).getNewStream()); assertEquals(1, property.getValue(Type.BINARY).length()); }
@Override public Path touch(final Path file, final TransferStatus status) throws BackgroundException { if(Checksum.NONE == status.getChecksum()) { status.setChecksum(writer.checksum(file).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())); }
@Override public Path touch(final Path file, final TransferStatus status) throws BackgroundException { if(Checksum.NONE == status.getChecksum()) { status.setChecksum(writer.checksum(file).compute(new NullInputStream(0L), status)); } new DefaultStreamCloser().close(writer.write(file, status, new DisabledConnectionCallback())); return new Path(file.getParent(), file.getName(), file.getType(), new AzureAttributesFinderFeature(session, context).find(file)); }
@Override public Path touch(final Path file, final TransferStatus status) throws BackgroundException { if(Checksum.NONE == status.getChecksum()) { status.setChecksum(writer.checksum(file).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)); }
@Test public void inlineBinaryShouldNotBeDownloaded() throws Exception { SegmentNodeStore store = SegmentNodeStoreBuilders.builder(fileStore.fileStore()).build(); NodeBuilder root = store.getRoot().builder(); root.setProperty("b", root.createBlob(new NullInputStream(SegmentTestConstants.MEDIUM_LIMIT - 1))); store.merge(root, EmptyHook.INSTANCE, CommitInfo.EMPTY); RemoteBlobProcessor processor = new RemoteBlobProcessor(blobStore.blobStore(), blobId -> { Assert.fail("Inline binaries should not be downloaded"); return null; }); processor.processBinary(store.getRoot().getProperty("b").getValue(Type.BINARY)); }