Search in sources :

Example 16 with BytesOf

use of org.cactoos.bytes.BytesOf in project cactoos by yegor256.

the class TeeInputFromBytesTest method copiesFromBytesToPath.

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

Example 17 with BytesOf

use of org.cactoos.bytes.BytesOf in project cactoos by yegor256.

the class Zip method stream.

@Override
public InputStream stream() throws Exception {
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    try (ZipOutputStream zip = new ZipOutputStream(out)) {
        for (final Path path : this.origin) {
            final File file = path.toFile();
            final ZipEntry entry = new ZipEntry(file.getPath());
            zip.putNextEntry(entry);
            if (file.isFile()) {
                try (FileInputStream input = new FileInputStream(file)) {
                    zip.write(new BytesOf(new InputOf(input)).asBytes());
                }
            }
            zip.closeEntry();
        }
    }
    return new ByteArrayInputStream(out.toByteArray());
}
Also used : Path(java.nio.file.Path) BytesOf(org.cactoos.bytes.BytesOf) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

BytesOf (org.cactoos.bytes.BytesOf)17 Test (org.junit.Test)12 IsEqual (org.hamcrest.core.IsEqual)6 File (java.io.File)4 TextOf (org.cactoos.text.TextOf)4 Test (org.junit.jupiter.api.Test)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 LengthOf (org.cactoos.scalar.LengthOf)3 HasContent (org.llorllale.cactoos.matchers.HasContent)3 HasString (org.llorllale.cactoos.matchers.HasString)3 OutputStream (java.io.OutputStream)2 Logger (java.util.logging.Logger)2 AllOf (org.hamcrest.core.AllOf)2 StringContains (org.hamcrest.core.StringContains)2 EndsWith (org.llorllale.cactoos.matchers.EndsWith)2 IsText (org.llorllale.cactoos.matchers.IsText)2 StartsWith (org.llorllale.cactoos.matchers.StartsWith)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 StringReader (java.io.StringReader)1