StreamResource extends AbstractDataResource { public StreamResource(InputStream stream, String name, long size) { this(stream, name, size, null); } StreamResource(InputStream stream, String name, long size);  StreamResource(InputStream stream, String name, long size, String parentPath);  StreamResource(InputStream stream, String name, long size, String parentPath, Date modificationDate); @Override InputStream openStream(); @Override long getSize(); @Override boolean isData(); @Override String getName(); @Override String getPath(); @Override String getSchemePrefix(); @Override URL getUrl(); @Override DataResource navigate(String resourcePath); @Override Date getLastModificationDate(); static final String SCHEME_PREFIX; }
@Test public void testStreamResource() throws Exception { byte[] buffer = "Hello World!".getBytes(); ByteArrayInputStream stream = new ByteArrayInputStream(buffer); String name = "message.txt"; StreamResource streamResource = new StreamResource(stream, name, buffer.length); assertThat(streamResource.openStream()).isSameAs(stream); assertThat(streamResource.getName()).isEqualTo(name); assertThat(streamResource.getPath()).isEqualTo(name); assertThat(streamResource.getSize()).isEqualTo(buffer.length); assertThat(streamResource.getSchemePrefix()).isEqualTo("stream:"); assertThat(streamResource.isData()).isTrue(); assertThat(streamResource.isAvailable()).isTrue(); assertThat(streamResource.getUri()).isEqualTo("stream:" + name); URL url = streamResource.getUrl(); assertThat(url.toString()).isEqualTo("stream:" + name); assertThat(url.openStream()).isSameAs(stream); }