Java源码示例:org.cactoos.Bytes

示例1
/**
 * 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())
        );
    }
}
 
示例2
/**
 * 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)
        );
    }
}
 
示例3
/**
 * Ctor.
 * @param bts Encapsulated bytes
 */
@SuppressWarnings("PMD.AvoidThrowingRawExceptionTypes")
public UncheckedBytes(final Bytes bts) {
    this(
        bts,
        error -> {
            throw new RuntimeException(error);
        }
    );
}
 
示例4
/**
 * Ctor.
 * @param src The bytes
 */
public InputOf(final Bytes src) {
    this(
        () -> new IoChecked<InputStream>(
            () -> new ByteArrayInputStream(src.asBytes())
        ).value()
    );
}
 
示例5
/**
 * 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;
}
 
示例6
/**
 * Ctor uses a RFC4648 {@link java.util.Base64.Decoder}.
 *
 * @param origin Origin bytes
 */
public Base64Bytes(final Bytes origin) {
    this(origin, Base64.getDecoder());
}
 
示例7
/**
 * 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;
}
 
示例8
/**
 * Ctor.
 * @param bytes The input
 */
public NoNulls(final Bytes bytes) {
    this.origin = bytes;
}
 
示例9
/**
 * Ctor uses a RFC4648 {@link java.util.Base64.Encoder}.
 *
 * @param origin Origin bytes.
 */
public BytesBase64(final Bytes origin) {
    this(origin, Base64.getEncoder());
}
 
示例10
/**
 * 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;
}
 
示例11
/**
 * Ctor.
 * @param source The bytes
 */
public HexOf(final Bytes source) {
    this.bytes = source;
}
 
示例12
/**
 * Ctor.
 *
 * @param bytes The Bytes
 */
public TextOf(final Bytes bytes) {
    this(bytes, StandardCharsets.UTF_8);
}
 
示例13
/**
 * Ctor.
 *
 * @param bytes The Bytes
 * @param cset The Charset
 */
public TextOf(final Bytes bytes, final Charset cset) {
    this(() -> new String(bytes.asBytes(), cset));
}
 
示例14
/**
 * Ctor.
 *
 * @param bytes The Bytes
 * @param cset The Charset
 */
public TextOf(final Bytes bytes, final String cset) {
    this(() -> new String(bytes.asBytes(), cset));
}
 
示例15
/**
 * Ctor.
 * @param bytes Bytes to iterate
 * @throws Exception If fails
 */
public IteratorOfBytes(final Bytes bytes) throws Exception {
    this(bytes.asBytes());
}
 
示例16
/**
 * 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));
}
 
示例17
/**
 * 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));
}
 
示例18
/**
 * 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);
}
 
示例19
/**
 * Ctor.
 *
 * @param bytes Bytes to encapsulate
 */
private BytesOf(final Bytes bytes) {
    this.origin = bytes;
}
 
示例20
/**
 * 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;
}
 
示例21
/**
 * Ctor.
 * @param bytes The text
 */
public InputStreamOf(final Bytes bytes) {
    this(new InputOf(bytes));
}
 
示例22
/**
 * 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;
}
 
示例23
/**
 * Ctor.
 * @param bytes The text
 */
public ReaderOf(final Bytes bytes) {
    this(new InputOf(bytes));
}