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