Java Code Examples for org.cactoos.Input#stream()
The following examples show how to use
org.cactoos.Input#stream() .
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: HtWire.java From cactoos-http with MIT License | 6 votes |
@Override public Input send(final Input input) throws Exception { final Socket socket = this.supplier.value(); final InputStream source = input.stream(); final InputStream ins = socket.getInputStream(); final OutputStream ous = socket.getOutputStream(); final byte[] buf = new byte[HtWire.LENGTH]; while (true) { final int len = source.read(buf); if (len < 0) { break; } ous.write(buf, 0, len); } return new InputOf(ins); }
Example 2
Source File: PropertiesOf.java From cactoos with MIT License | 5 votes |
/** * Ctor. * @param input Input */ public PropertiesOf(final Input input) { this( () -> { final Properties props = new Properties(); try (InputStream stream = input.stream()) { props.load(stream); } return props; } ); }
Example 3
Source File: LengthOf.java From cactoos with MIT License | 5 votes |
/** * Ctor. * @param input The input * @param max Buffer size */ @SuppressWarnings( { "PMD.CallSuperInConstructor", "PMD.ConstructorOnlyInitializesOrCallOtherConstructors" } ) public LengthOf(final Input input, final int max) { this(() -> { if (max == 0) { throw new IllegalArgumentException( "Cannot use a buffer limited to zero size" ); } try (InputStream stream = input.stream()) { final byte[] buf = new byte[max]; long length = 0L; while (true) { final int len = stream.read(buf); if (len > 0) { length += (long) len; } if (len < 0) { break; } } return (double) length; } }); }
Example 4
Source File: ReaderOf.java From cactoos with MIT License | 2 votes |
/** * Ctor. * @param input The input * @param charset The charset */ public ReaderOf(final Input input, final Charset charset) { this(() -> new InputStreamReader(input.stream(), charset)); }
Example 5
Source File: ReaderOf.java From cactoos with MIT License | 2 votes |
/** * Ctor. * @param input The input * @param charset The charset */ public ReaderOf(final Input input, final CharSequence charset) { this(() -> new InputStreamReader(input.stream(), charset.toString())); }
Example 6
Source File: ReaderOf.java From cactoos with MIT License | 2 votes |
/** * Ctor. * @param input The input * @param decoder The decoder * @since 0.13.1 */ public ReaderOf(final Input input, final CharsetDecoder decoder) { this(() -> new InputStreamReader(input.stream(), decoder)); }