org.cactoos.Bytes Java Examples
The following examples show how to use
org.cactoos.Bytes.
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: BodyUrlTest.java From takes with MIT License | 6 votes |
/** * Body.URL can provide the expected length. * @throws Exception If there is some problem inside. */ @Test public void returnsCorrectLengthWithUrl() throws Exception { try (TempFile file = new TempFile()) { final Bytes body = new BytesOf("URL returnsCorrectLength!"); try (OutputStream outStream = new OutputTo(file.value()).stream()) { new LengthOf( new TeeInput(body, new OutputTo(outStream)) ).intValue(); } MatcherAssert.assertThat( "Body content of Body.Url doesn't have the correct length", new LengthOf( new Body.Url(file.value().toUri().toURL()) ).intValue(), new IsEqual<>(body.asBytes().length) ); } }
Example #2
Source File: BodyUrlTest.java From takes with MIT License | 6 votes |
/** * Body.URL can provide the expected input. * @throws Exception If there is some problem inside. */ @Test public void returnsCorrectInputWithUrl() throws Exception { try (TempFile file = new TempFile()) { final Bytes body = new BytesOf("URL returnsCorrectInput!"); try (OutputStream outStream = new OutputTo(file.value()).stream()) { new LengthOf( new TeeInput(body, new OutputTo(outStream)) ).intValue(); } final Body.Url input = new Body.Url(file.value().toUri().toURL()); MatcherAssert.assertThat( "Body content of Body.Url doesn't provide the correct bytes", new BytesOf(input).asBytes(), new IsEqual<>(body.asBytes()) ); } }
Example #3
Source File: InputOf.java From cactoos with MIT License | 5 votes |
/** * Ctor. * @param src The bytes */ public InputOf(final Bytes src) { this( () -> new IoChecked<InputStream>( () -> new ByteArrayInputStream(src.asBytes()) ).value() ); }
Example #4
Source File: UncheckedBytes.java From cactoos with MIT License | 5 votes |
/** * Ctor. * @param bts Encapsulated bytes */ @SuppressWarnings("PMD.AvoidThrowingRawExceptionTypes") public UncheckedBytes(final Bytes bts) { this( bts, error -> { throw new RuntimeException(error); } ); }
Example #5
Source File: TeeInput.java From cactoos with MIT License | 2 votes |
/** * Ctor. * @param bytes The source * @param path The output path * @since 0.13.3 */ public TeeInput(final Bytes bytes, final Path path) { this(new InputOf(bytes), new OutputTo(path)); }
Example #6
Source File: ReaderOf.java From cactoos with MIT License | 2 votes |
/** * Ctor. * @param bytes The text */ public ReaderOf(final Bytes bytes) { this(new InputOf(bytes)); }
Example #7
Source File: CheckedBytes.java From cactoos with MIT License | 2 votes |
/** * Ctor. * @param orig Origin bytes. * @param fnc Function that wraps exceptions. */ public CheckedBytes(final Bytes orig, final Func<Exception, E> fnc) { this.origin = orig; this.func = fnc; }
Example #8
Source File: InputStreamOf.java From cactoos with MIT License | 2 votes |
/** * Ctor. * @param bytes The text */ public InputStreamOf(final Bytes bytes) { this(new InputOf(bytes)); }
Example #9
Source File: UncheckedBytes.java From cactoos with MIT License | 2 votes |
/** * Ctor. * @param bts Encapsulated bytes * @param fbk Fallback * @since 0.5 */ public UncheckedBytes(final Bytes bts, final Func<Exception, byte[]> fbk) { this.bytes = bts; this.fallback = fbk; }
Example #10
Source File: BytesOf.java From cactoos with MIT License | 2 votes |
/** * Ctor. * * @param bytes Bytes to encapsulate */ private BytesOf(final Bytes bytes) { this.origin = bytes; }
Example #11
Source File: TeeInput.java From cactoos with MIT License | 2 votes |
/** * Ctor. * @param bytes The source * @param output The output * @since 0.13.3 */ public TeeInput(final Bytes bytes, final Output output) { this(new InputOf(bytes), output); }
Example #12
Source File: TeeInput.java From cactoos with MIT License | 2 votes |
/** * Ctor. * @param bytes The source * @param file The output file * @since 0.13.3 */ public TeeInput(final Bytes bytes, final File file) { this(new InputOf(bytes), new OutputTo(file)); }
Example #13
Source File: SkipInput.java From cactoos-http with MIT License | 2 votes |
/** * Ctor. * * @param origin The input. * @param delimiter The bytes delimiter to skip until. */ public SkipInput(final Input origin, final Bytes delimiter) { this.origin = origin; this.delimiter = delimiter; }
Example #14
Source File: IteratorOfBytes.java From cactoos with MIT License | 2 votes |
/** * Ctor. * @param bytes Bytes to iterate * @throws Exception If fails */ public IteratorOfBytes(final Bytes bytes) throws Exception { this(bytes.asBytes()); }
Example #15
Source File: TextOf.java From cactoos with MIT License | 2 votes |
/** * Ctor. * * @param bytes The Bytes * @param cset The Charset */ public TextOf(final Bytes bytes, final String cset) { this(() -> new String(bytes.asBytes(), cset)); }
Example #16
Source File: TextOf.java From cactoos with MIT License | 2 votes |
/** * Ctor. * * @param bytes The Bytes * @param cset The Charset */ public TextOf(final Bytes bytes, final Charset cset) { this(() -> new String(bytes.asBytes(), cset)); }
Example #17
Source File: TextOf.java From cactoos with MIT License | 2 votes |
/** * Ctor. * * @param bytes The Bytes */ public TextOf(final Bytes bytes) { this(bytes, StandardCharsets.UTF_8); }
Example #18
Source File: HexOf.java From cactoos with MIT License | 2 votes |
/** * Ctor. * @param source The bytes */ public HexOf(final Bytes source) { this.bytes = source; }
Example #19
Source File: BytesBase64.java From cactoos with MIT License | 2 votes |
/** * Ctor. * * @param origin Origin bytes. * @param enc The encoder to use. */ public BytesBase64(final Bytes origin, final Base64.Encoder enc) { this.origin = origin; this.encoder = enc; }
Example #20
Source File: BytesBase64.java From cactoos with MIT License | 2 votes |
/** * Ctor uses a RFC4648 {@link java.util.Base64.Encoder}. * * @param origin Origin bytes. */ public BytesBase64(final Bytes origin) { this(origin, Base64.getEncoder()); }
Example #21
Source File: NoNulls.java From cactoos with MIT License | 2 votes |
/** * Ctor. * @param bytes The input */ public NoNulls(final Bytes bytes) { this.origin = bytes; }
Example #22
Source File: Base64Bytes.java From cactoos with MIT License | 2 votes |
/** * Ctor. * * @param origin Origin bytes. * @param dec Decoder to use. */ public Base64Bytes(final Bytes origin, final Base64.Decoder dec) { this.origin = origin; this.decoder = dec; }
Example #23
Source File: Base64Bytes.java From cactoos with MIT License | 2 votes |
/** * Ctor uses a RFC4648 {@link java.util.Base64.Decoder}. * * @param origin Origin bytes */ public Base64Bytes(final Bytes origin) { this(origin, Base64.getDecoder()); }