DataSource

General purpose readable byte data source.

API

DataSource.java
interface DataSource {
  Try<T> tryReadAll(Function<InputStream, Try<T>> consumingMapper)
  Try<T> tryReadAndApply(ThrowingFunction<InputStream, T> inputStreamMapper)     (1)
  Try<Void> tryReadAndAccept(ThrowingConsumer<InputStream> inputStreamConsumer)     (2)
  Try<byte[]> tryReadAsBytes()     (3)
  byte[] bytes()     (4)
  Try<String> tryReadAsString(Charset charset)     (5)
  Try<String> tryReadAsStringUtf8()     (6)
  Try<Can<String>> tryReadAsLines(Charset charset)     (7)
  Try<Can<String>> tryReadAsLinesUtf8()     (8)
  Try<BufferedImage> tryReadAsImage()
  Try<HashUtils.Hash> tryHash(HashAlgorithm hashAlgorithm)
  Try<HashUtils.Hash> tryMd5()
  String md5Hex()
  DataSource map(ThrowingFunction<InputStream, InputStream> inputStreamMapper)     (9)
  Try<Void> tryReadAndWrite(DataSink dataSink, int bufferSize)     (10)
  void pipe(DataSink dataSink, int bufferSize)     (11)
  void pipe(DataSink dataSink)     (12)
  DataSource empty()     (13)
  DataSource ofInputStreamSupplier(ThrowingSupplier<InputStream> inputStreamSupplier)     (14)
  DataSource ofInputStreamEagerly(InputStream inputStream)     (15)
  DataSource ofResource(Class<?> cls, String resourcePath)     (16)
  DataSource ofSpringResource(Resource springResource)     (17)
  DataSource ofFile(File file)     (18)
  DataSource ofString(String string, Charset charset)     (19)
  DataSource ofStringUtf8(String string)     (20)
  DataSource ofBytes(byte[] bytes)     (21)
}
1 tryReadAndApply(ThrowingFunction)

Passes an InputStream to given Function for application.

2 tryReadAndAccept(ThrowingConsumer)

Passes an InputStream to given Consumer for consumption.

3 tryReadAsBytes()

Reads from this DataSource into a String using given charset encoding.

4 bytes()

Shortcut for tryReadAsBytes().valueAsNonNullElseFail() .

5 tryReadAsString(Charset)

Reads from this DataSource into a String using given charset encoding.

6 tryReadAsStringUtf8()

Reads from this DataSource into a String using UTF-8 encoding.

7 tryReadAsLines(Charset)

Reads from this DataSource all lines using given charset encoding.

8 tryReadAsLinesUtf8()

Reads from this DataSource all lines using UTF-8 encoding.

9 map(ThrowingFunction)

Returns a new DataSource that maps the InputStream of this DataSource to another through means of applying given unary operator inputStreamMapper . (eg the decode or encode the originating input stream)

10 tryReadAndWrite(DataSink, int)

Acts as a pipe, reading from this DataSource and writing to given DataSink , using given bufferSize for the underlying byte data junks.

11 pipe(DataSink, int)

Acts as a pipe, reading from this DataSource and writing to given DataSink , using given bufferSize for the underlying byte data junks.

12 pipe(DataSink)

Acts as a pipe, reading from this DataSource and writing to given DataSink , using default bufferSize of 16k for the underlying byte data junks.

13 empty()

Acts as a no-op.

14 ofInputStreamSupplier(ThrowingSupplier)

Creates a DataSource for given InputStream Supplier.

15 ofInputStreamEagerly(InputStream)

Creates a DataSource for given InputStream eagerly. That is, it reads the InputStream into a byte array, which can be later read from repeatedly.

16 ofResource(Class, String)

Creates a DataSource for given resource path relative to Class .

17 ofSpringResource(Resource)

Creates a DataSource for given Spring Resource .

18 ofFile(File)

Creates a DataSource for given File . If null , an 'empty' DataSource is returned.

19 ofString(String, Charset)

Creates a DataSource for given String . If null or empty, an 'empty' DataSource is returned.

20 ofStringUtf8(String)

Creates a DataSource for given String . If null or empty, an 'empty' DataSource is returned.

21 ofBytes(byte)

Creates a DataSource for given byte array. If null or empty, an 'empty' DataSource is returned.

Members

tryReadAndApply(ThrowingFunction)

Passes an InputStream to given Function for application.

tryReadAndAccept(ThrowingConsumer)

Passes an InputStream to given Consumer for consumption.

tryReadAsBytes()

Reads from this DataSource into a String using given charset encoding.

If the underlying InputStream is null a success Try is returned, containing a null value.

bytes()

Shortcut for tryReadAsBytes().valueAsNonNullElseFail() .

tryReadAsString(Charset)

Reads from this DataSource into a String using given charset encoding.

If the underlying InputStream is null a success Try is returned, containing a null value.

tryReadAsStringUtf8()

Reads from this DataSource into a String using UTF-8 encoding.

If the underlying InputStream is null a success Try is returned, containing a null value.

tryReadAsLines(Charset)

Reads from this DataSource all lines using given charset encoding.

If the underlying InputStream is null a success Try is returned, containing a null value.

tryReadAsLinesUtf8()

Reads from this DataSource all lines using UTF-8 encoding.

If the underlying InputStream is null a success Try is returned, containing a null value.

map(ThrowingFunction)

Returns a new DataSource that maps the InputStream of this DataSource to another through means of applying given unary operator inputStreamMapper . (eg the decode or encode the originating input stream)

tryReadAndWrite(DataSink, int)

Acts as a pipe, reading from this DataSource and writing to given DataSink , using given bufferSize for the underlying byte data junks.

pipe(DataSink, int)

Acts as a pipe, reading from this DataSource and writing to given DataSink , using given bufferSize for the underlying byte data junks.

Throws if the write failed.

pipe(DataSink)

Acts as a pipe, reading from this DataSource and writing to given DataSink , using default bufferSize of 16k for the underlying byte data junks.

Throws if the write failed.

empty()

Acts as a no-op.

ofInputStreamSupplier(ThrowingSupplier)

Creates a DataSource for given InputStream Supplier.

ofInputStreamEagerly(InputStream)

Creates a DataSource for given InputStream eagerly. That is, it reads the InputStream into a byte array, which can be later read from repeatedly.

If reading from given InputStream throws any exception, it is propagated without catching.

ofResource(Class, String)

Creates a DataSource for given resource path relative to Class .

If any of the args is null (or empty), returns an 'empty' DataSource .

ofSpringResource(Resource)

Creates a DataSource for given Spring Resource .

If the single argument is null, returns an 'empty' DataSource .

ofFile(File)

Creates a DataSource for given File . If null , an 'empty' DataSource is returned.

ofString(String, Charset)

Creates a DataSource for given String . If null or empty, an 'empty' DataSource is returned.

ofStringUtf8(String)

Creates a DataSource for given String . If null or empty, an 'empty' DataSource is returned.

ofBytes(byte)

Creates a DataSource for given byte array. If null or empty, an 'empty' DataSource is returned.