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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations