Search in sources :

Example 36 with ContentClaim

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));
}
Also used : ContentClaim(org.apache.nifi.controller.repository.claim.ContentClaim) StandardContentClaim(org.apache.nifi.controller.repository.claim.StandardContentClaim) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 37 with ContentClaim

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()));
}
Also used : Path(java.nio.file.Path) ContentClaim(org.apache.nifi.controller.repository.claim.ContentClaim) StandardContentClaim(org.apache.nifi.controller.repository.claim.StandardContentClaim) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) Test(org.junit.Test)

Example 38 with ContentClaim

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)));
}
Also used : Path(java.nio.file.Path) ContentClaim(org.apache.nifi.controller.repository.claim.ContentClaim) StandardContentClaim(org.apache.nifi.controller.repository.claim.StandardContentClaim) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Example 39 with ContentClaim

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)));
}
Also used : Path(java.nio.file.Path) ContentClaim(org.apache.nifi.controller.repository.claim.ContentClaim) StandardContentClaim(org.apache.nifi.controller.repository.claim.StandardContentClaim) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) File(java.io.File) Test(org.junit.Test)

Example 40 with ContentClaim

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)));
}
Also used : Path(java.nio.file.Path) ContentClaim(org.apache.nifi.controller.repository.claim.ContentClaim) StandardContentClaim(org.apache.nifi.controller.repository.claim.StandardContentClaim) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) Test(org.junit.Test)

Aggregations

ContentClaim (org.apache.nifi.controller.repository.claim.ContentClaim)79 StandardContentClaim (org.apache.nifi.controller.repository.claim.StandardContentClaim)51 Test (org.junit.Test)40 OutputStream (java.io.OutputStream)39 ByteArrayOutputStream (java.io.ByteArrayOutputStream)30 IOException (java.io.IOException)26 InputStream (java.io.InputStream)22 ResourceClaim (org.apache.nifi.controller.repository.claim.ResourceClaim)22 ByteArrayInputStream (java.io.ByteArrayInputStream)20 FlowFile (org.apache.nifi.flowfile.FlowFile)19 Path (java.nio.file.Path)18 ArrayList (java.util.ArrayList)16 HashMap (java.util.HashMap)16 FlowFileQueue (org.apache.nifi.controller.queue.FlowFileQueue)14 Map (java.util.Map)13 FileOutputStream (java.io.FileOutputStream)12 FilterOutputStream (java.io.FilterOutputStream)12 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)12 FlowFileAccessException (org.apache.nifi.processor.exception.FlowFileAccessException)12 ProvenanceEventRecord (org.apache.nifi.provenance.ProvenanceEventRecord)12