use of org.apache.nifi.controller.repository.claim.ContentClaim in project nifi by apache.
the class TestFileSystemRepository method testExportToOutputStream.
@Test
public void testExportToOutputStream() throws IOException {
final ContentClaim claim = repository.create(true);
try (final OutputStream out = repository.write(claim)) {
Files.copy(helloWorldFile.toPath(), out);
}
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
repository.exportTo(claim, baos);
final byte[] data = baos.toByteArray();
assertTrue(Arrays.equals(Files.readAllBytes(helloWorldFile.toPath()), data));
}
use of org.apache.nifi.controller.repository.claim.ContentClaim in project nifi by apache.
the class TestFileSystemRepository method testImportFromFile.
@Test
public void testImportFromFile() throws IOException {
final ContentClaim claim = repository.create(false);
final File testFile = new File("src/test/resources/hello.txt");
final File file1 = new File("target/testFile1");
final Path path1 = file1.toPath();
final File file2 = new File("target/testFile2");
final Path path2 = file2.toPath();
Files.copy(testFile.toPath(), path1, StandardCopyOption.REPLACE_EXISTING);
Files.copy(testFile.toPath(), path2, StandardCopyOption.REPLACE_EXISTING);
repository.importFrom(path1, claim);
assertTrue(file1.exists());
assertTrue(file2.exists());
// try to read the data back out.
final Path path = getPath(claim);
final byte[] data = Files.readAllBytes(path);
final byte[] expected = Files.readAllBytes(testFile.toPath());
assertTrue(Arrays.equals(expected, data));
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (final InputStream in = repository.read(claim)) {
StreamUtils.copy(in, baos);
}
assertTrue(Arrays.equals(expected, baos.toByteArray()));
}
use of org.apache.nifi.controller.repository.claim.ContentClaim in project nifi by apache.
the class TestFileSystemRepository method testImportFromStream.
@Test
public void testImportFromStream() throws IOException {
final ContentClaim claim = repository.create(false);
final byte[] data = "hello".getBytes();
final ByteArrayInputStream bais = new ByteArrayInputStream(data);
repository.importFrom(bais, claim);
final Path claimPath = getPath(claim);
assertTrue(Arrays.equals(data, Files.readAllBytes(claimPath)));
}
use of org.apache.nifi.controller.repository.claim.ContentClaim in project nifi by apache.
the class TestFileSystemRepository method testExportToFile.
@Test
public void testExportToFile() throws IOException {
final ContentClaim claim = repository.create(true);
try (final OutputStream out = repository.write(claim)) {
Files.copy(helloWorldFile.toPath(), out);
}
final File outFile = new File("target/testExportToFile");
final Path outPath = outFile.toPath();
Files.deleteIfExists(outPath);
final byte[] expected = Files.readAllBytes(helloWorldFile.toPath());
repository.exportTo(claim, outPath, false);
assertTrue(Arrays.equals(expected, Files.readAllBytes(outPath)));
repository.exportTo(claim, outPath, true);
final byte[] doubleExpected = new byte[expected.length * 2];
System.arraycopy(expected, 0, doubleExpected, 0, expected.length);
System.arraycopy(expected, 0, doubleExpected, expected.length, expected.length);
assertTrue(Arrays.equals(doubleExpected, Files.readAllBytes(outPath)));
}
use of org.apache.nifi.controller.repository.claim.ContentClaim in project nifi by apache.
the class TestFileSystemRepository method testWrite.
@Test
public void testWrite() throws IOException {
final ContentClaim claim = repository.create(true);
final byte[] data = "The quick brown fox jumps over the lazy dog".getBytes();
try (final OutputStream out = repository.write(claim)) {
out.write(data);
}
final Path path = getPath(claim);
assertTrue(Arrays.equals(data, Files.readAllBytes(path)));
}
Aggregations