org.cactoos.Input Java Examples
The following examples show how to use
org.cactoos.Input.
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: HtHeaders.java From cactoos-http with MIT License | 6 votes |
/** * Ctor. * @param head Response head part */ @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") public HtHeaders(final Input head) { super(() -> { final Map<String, List<String>> map = new HashMap<>(); final ListOf<Text> texts = new ListOf<>( new Split(new TextOf(head), "\r\n") ); for (final Text line : texts.subList(1, texts.size())) { final String[] parts = line.asString().split(":", 2); map.merge( new Lowered( new Trimmed(new TextOf(parts[0])), Locale.ENGLISH ).asString(), new ListOf<>( new Trimmed(new TextOf(parts[1])).asString() ), (first, second) -> new Joined<String>(first, second) ); } return map; }); }
Example #2
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 #3
Source File: JavaInterface.java From eo with MIT License | 6 votes |
@Override public Input code() { return new InputOf( new FormattedText( "%s\n\npublic interface %s {\n %s\n}\n", "package eo;", this.name, new UncheckedText( new JoinedText( "\n ", new Mapped<>( mtd -> new UncheckedText( new FormattedText("%s;", mtd.java()) ).asString(), this.methods ) ) ).asString().replace("\n", "\n ") ) ); }
Example #4
Source File: Tree.java From eo with MIT License | 5 votes |
/** * Compile it to Java files. * * @return Java files (path, content) */ public Map<String, Input> java() { return new StickyMap<>( new Mapped<>( javaFile -> new MapEntry<>( javaFile.path(), javaFile.code() ), new Mapped<>(RootNode::java, this.nodes) ) ); }
Example #5
Source File: HtCookies.java From cactoos-http with MIT License | 5 votes |
/** * Ctor. * @param rsp Response */ public HtCookies(final Input rsp) { super(() -> new Grouped<>( new Mapped<>( (Text entry) -> { final Iterable<Text> parts = new Split(entry, "="); if (new LengthOf(parts).intValue() != 2) { throw new IllegalArgumentException( "Incorrect HTTP Response cookie" ); } final Iterator<Text> iter = parts.iterator(); return new MapEntry<>( iter.next().asString(), iter.next().asString() ); }, new Joined<>( new Mapped<>( e -> new Split(e, ";\\s+"), new HtHeaders(rsp).get("set-cookie") ) ) ), MapEntry::getKey, MapEntry::getValue )); }
Example #6
Source File: HtStatus.java From cactoos-http with MIT License | 5 votes |
/** * Ctor. * @param head Response head part */ public HtStatus(final Input head) { super(() -> Double.parseDouble( // @checkstyle MagicNumber (3 line) new BufferedReader( new InputStreamReader(head.stream(), StandardCharsets.UTF_8) ).readLine().split(" ", 3)[1] )); }
Example #7
Source File: HtRetryWire.java From cactoos-http with MIT License | 5 votes |
@Override public Input send(final Input input) throws Exception { return new Retry<>( this.origin::send, this.func ).apply(input); }
Example #8
Source File: HtTimedWire.java From cactoos-http with MIT License | 5 votes |
@Override public Input send(final Input input) throws Exception { return new Timed<>( this.origin::send, this.milliseconds ).apply(input); }
Example #9
Source File: DigestEnvelope.java From cactoos with MIT License | 5 votes |
/** * Ctor. * @param input The input * @param max Buffer size * @param algrthm The algorithm */ public DigestEnvelope( final Input input, final int max, final String algrthm ) { this.source = input; this.size = max; this.algorithm = algrthm; }
Example #10
Source File: Sticky.java From cactoos with MIT License | 5 votes |
/** * Ctor. * @param input The input */ public Sticky(final Input input) { this.cache = new org.cactoos.scalar.Sticky<>( () -> { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); new LengthOf( new TeeInput(input, new OutputTo(baos)) ).value(); return baos.toByteArray(); } ); }
Example #11
Source File: Joined.java From cactoos with MIT License | 5 votes |
/** * Ctor. * @param first First input * @param rest The other inputs */ public Joined(final Input first, final Input... rest) { this( new org.cactoos.iterable.Joined<>( first, new IterableOf<>(rest) ) ); }
Example #12
Source File: HtKeepAliveResponse.java From cactoos-http with MIT License | 5 votes |
/** * Ctor. * @param wre The wire * @param mtimeout The timeout for the connection usage in milliseconds * @param rmax The maximum quantity of the requests within the connection * timeout * @param req The request * @checkstyle ParameterNumberCheck (2 lines) */ public HtKeepAliveResponse( final Wire wre, final long mtimeout, final int rmax, final Input req ) { super(() -> wre.send( new InputOf( new FormattedText( HtKeepAliveResponse.TEMPLATE, req, mtimeout, rmax ) ) ).stream()); }
Example #13
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 #14
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 #15
Source File: JavaClass.java From eo with MIT License | 5 votes |
@Override public Input code() { return new InputOf( new FormattedText( "%s\n\npublic final class %s implements %s {\n %s\n}\n", "package eo;", this.name, new UncheckedText( new JoinedText(", ", this.ifaces) ).asString(), this.body.java(this.name).replace("\n", "\n ") ) ); }
Example #16
Source File: Program.java From eo with MIT License | 5 votes |
/** * Ctor. * * @param ipt Input text * @param dir Directory to write to */ public Program(final Input ipt, final Path dir) { this( ipt, path -> new OutputTo( new File(dir.toFile(), path) ) ); }
Example #17
Source File: InputWithFallback.java From cactoos with MIT License | 4 votes |
/** * Ctor. * @param input Main input * @param alt Alternative */ public InputWithFallback(final Input input, final IoCheckedFunc<IOException, Input> alt) { this.main = input; this.alternative = alt; }
Example #18
Source File: LengthOf.java From cactoos with MIT License | 4 votes |
/** * Ctor. * @param input The input */ public LengthOf(final Input input) { // @checkstyle MagicNumber (1 line) this(input, 16 << 10); }
Example #19
Source File: HtSecureWire.java From cactoos-http with MIT License | 4 votes |
@Override public Input send(final Input input) throws Exception { return new HtWire(this.address, new Constant<>(this.port), this.socket) .send(input); }
Example #20
Source File: GzipInput.java From cactoos with MIT License | 4 votes |
/** * Ctor. * @param input The input. */ public GzipInput(final Input input) { // @checkstyle MagicNumberCheck (1 line) this(input, 16 << 10); }
Example #21
Source File: InputAsBytes.java From cactoos with MIT License | 4 votes |
/** * Ctor. * @param input The input */ InputAsBytes(final Input input) { // @checkstyle MagicNumber (1 line) this(input, 16 << 10); }
Example #22
Source File: HtUpgradeWire.java From cactoos-http with MIT License | 4 votes |
@Override public Input send(final Input input) throws Exception { return this.origin.send(input); }
Example #23
Source File: LSInputOf.java From cactoos with MIT License | 3 votes |
/** * Ctor. * @param inpt Input * @param pubid PublicID * @param sysid SystemID * @param bse Base * @checkstyle ParameterNumberCheck (3 lines) */ public LSInputOf(final Input inpt, final String pubid, final String sysid, final String bse) { this.input = inpt; this.pid = pubid; this.sid = sysid; this.base = bse; }
Example #24
Source File: ResourceOf.java From cactoos with MIT License | 2 votes |
/** * New resource input with current context {@link ClassLoader}. * @param res Resource name * @param fbk Fallback */ public ResourceOf(final CharSequence res, final Func<CharSequence, Input> fbk) { this(res, fbk, Thread.currentThread().getContextClassLoader()); }
Example #25
Source File: ResourceOf.java From cactoos with MIT License | 2 votes |
/** * New resource input with specified {@link ClassLoader}. * @param res Resource name * @param fbk Fallback * @param ldr Resource class loader */ public ResourceOf(final CharSequence res, final Func<CharSequence, Input> fbk, final ClassLoader ldr) { this(new TextOf(res), input -> fbk.apply(input.asString()), ldr); }
Example #26
Source File: InputOf.java From cactoos with MIT License | 2 votes |
/** * Ctor. * * @param input The input */ private InputOf(final Input input) { this.origin = input; }
Example #27
Source File: Md5DigestOf.java From cactoos with MIT License | 2 votes |
/** * Ctor. * @param input The input */ public Md5DigestOf(final Input input) { super(input, "MD5"); }
Example #28
Source File: Joined.java From cactoos with MIT License | 2 votes |
/** * Ctor. * @param ipts Iterable of inputs */ public Joined(final Iterable<Input> ipts) { this.inputs = ipts; }
Example #29
Source File: DigestEnvelope.java From cactoos with MIT License | 2 votes |
/** * Ctor. * @param input The input * @param algrthm The algorithm */ public DigestEnvelope(final Input input, final String algrthm) { // @checkstyle MagicNumber (1 line) this(input, 16 << 10, algrthm); }
Example #30
Source File: GzipInput.java From cactoos with MIT License | 2 votes |
/** * Ctor. * @param input The input * @param max Max length of the buffer */ public GzipInput(final Input input, final int max) { this.origin = input; this.size = max; }