Search in sources :

Example 1 with LengthOf

use of org.cactoos.scalar.LengthOf in project cactoos by yegor256.

the class GzipOutputTest method writeToGzipOutput.

@Test
public void writeToGzipOutput() throws Exception {
    final String content = "Hello!";
    final ByteArrayOutputStream expected = new ByteArrayOutputStream();
    try (Writer writer = new BufferedWriter(new OutputStreamWriter(new GZIPOutputStream(expected)))) {
        writer.write(content);
    }
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try (OutputStream output = new GzipOutput(new OutputTo(baos)).stream()) {
        new LengthOf(new TeeInput(content, new OutputTo(output))).value();
    }
    new Assertion<>("Can't write to a gzip output", baos.toByteArray(), new IsEqual<>(expected.toByteArray())).affirm();
}
Also used : OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedWriter(java.io.BufferedWriter) IsEqual(org.hamcrest.core.IsEqual) GZIPOutputStream(java.util.zip.GZIPOutputStream) LengthOf(org.cactoos.scalar.LengthOf) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) Test(org.junit.Test)

Example 2 with LengthOf

use of org.cactoos.scalar.LengthOf in project cactoos by yegor256.

the class GzipOutputTest method writeToClosedGzipOutput.

@Test(expected = IOException.class)
public void writeToClosedGzipOutput() throws Exception {
    final OutputStream stream = Files.newOutputStream(Paths.get(this.folder.newFile("cactoos.txt").getPath()));
    stream.close();
    new LengthOf(new TeeInput("Hello!", new GzipOutput(new OutputTo(stream)))).value();
}
Also used : OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) LengthOf(org.cactoos.scalar.LengthOf) Test(org.junit.Test)

Example 3 with LengthOf

use of org.cactoos.scalar.LengthOf in project cactoos by yegor256.

the class TeeInputFromReaderTest method copiesFromReaderToFile.

@Test
public void copiesFromReaderToFile() throws Exception {
    final String input = "Hello, товарищ file #1 äÄ üÜ öÖ and ß";
    final File output = this.folder.newFile();
    new LengthOf(new TeeInput(new ReaderOf(input), output)).value();
    new Assertion<>("Must copy from reader to file.", new InputOf(output), new HasContent(input)).affirm();
}
Also used : HasContent(org.llorllale.cactoos.matchers.HasContent) LengthOf(org.cactoos.scalar.LengthOf) File(java.io.File) Test(org.junit.Test)

Example 4 with LengthOf

use of org.cactoos.scalar.LengthOf in project cactoos by yegor256.

the class TeeInputFromReaderTest method copiesFromReaderWithCharsetToPath.

@Test
public void copiesFromReaderWithCharsetToPath() throws Exception {
    final String input = "Hello, товарищ path #3 äÄ üÜ öÖ and ß";
    final File output = this.folder.newFile();
    new LengthOf(new TeeInput(new ReaderOf(input), output.toPath(), StandardCharsets.UTF_8)).value();
    new Assertion<>("Must copy from reader with charset to path.", new InputOf(output), new HasContent(input)).affirm();
}
Also used : HasContent(org.llorllale.cactoos.matchers.HasContent) LengthOf(org.cactoos.scalar.LengthOf) File(java.io.File) Test(org.junit.Test)

Example 5 with LengthOf

use of org.cactoos.scalar.LengthOf in project cactoos by yegor256.

the class TeeInputFromReaderTest method copiesFromReaderWithSizeToOutput.

@Test
public void copiesFromReaderWithSizeToOutput() throws Exception {
    final String input = "Hello, товарищ output #2 äÄ üÜ öÖ and ß";
    final File output = this.folder.newFile();
    new LengthOf(new TeeInput(new ReaderOf(input), new OutputTo(output), input.length())).value();
    new Assertion<>("Must copy from reader with size to output.", new InputOf(output), new HasContent(input)).affirm();
}
Also used : HasContent(org.llorllale.cactoos.matchers.HasContent) LengthOf(org.cactoos.scalar.LengthOf) File(java.io.File) Test(org.junit.Test)

Aggregations

LengthOf (org.cactoos.scalar.LengthOf)103 Test (org.junit.Test)92 HasContent (org.llorllale.cactoos.matchers.HasContent)80 File (java.io.File)75 TextOf (org.cactoos.text.TextOf)20 Test (org.junit.jupiter.api.Test)11 Logger (java.util.logging.Logger)9 StringWriter (java.io.StringWriter)7 HasString (org.llorllale.cactoos.matchers.HasString)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 Path (java.nio.file.Path)5 OutputStream (java.io.OutputStream)4 AllOf (org.hamcrest.core.AllOf)4 IsEqual (org.hamcrest.core.IsEqual)4 IsText (org.llorllale.cactoos.matchers.IsText)4 BytesOf (org.cactoos.bytes.BytesOf)3 StringContains (org.hamcrest.core.StringContains)3 OutputStreamWriter (java.io.OutputStreamWriter)2 GZIPOutputStream (java.util.zip.GZIPOutputStream)2 BufferedWriter (java.io.BufferedWriter)1