@Override
    protected Output createOutput() throws IOException {
        try {
            if (outputPaths == null || outputPaths.length == 0) {
                throw new IOException("No output paths have been set");
            }

            // Get a path to use.
            String path;
            if (outputPaths.length == 1) {
                path = outputPaths[0];
            } else {
                // Choose one of the output paths at random.
                path = outputPaths[(int) Math.round(Math.random() * (outputPaths.length - 1))];
            }

            // Replace some of the path elements with system variables.
            path = pathCreator.replaceAll(path);

            // Make sure we can create this path.
            final Path file = Paths.get(path);
            final Path dir = file.getParent();
            final Set<PosixFilePermission> permissions = parsePosixFilePermissions(filePermissions);
            if (!Files.isDirectory(dir)) {
                try {
                    Files.createDirectories(dir);

                    // Set permissions on the created directory
                    if (permissions != null) {
                        Files.setPosixFilePermissions(dir, permissions);
                    }
                } catch (final IOException e) {
                    throw ProcessException.create("Unable to create output dirs: " + FileUtil.getCanonicalPath(dir));
                }
            }

            final Path lockFile = Paths.get(path + LOCK_EXTENSION);

            // Make sure we can create both output files without overwriting
            // another file.
            if (Files.exists(lockFile)) {
                throw ProcessException.create(
                        "Output file \"" + FileUtil.getCanonicalPath(lockFile) + "\" already exists");
            }
            if (Files.exists(file)) {
                throw ProcessException.create(
                        "Output file \"" + FileUtil.getCanonicalPath(file) + "\" already exists");
            }
            LOGGER.trace("Creating output stream for path {}", path);

            // Get a writer for the new lock file.
            final Output output = outputFactory
                    .create(new BufferedOutputStream(Files.newOutputStream(lockFile)));

            return new LockedOutput(output, lockFile, file, permissions);

        } catch (final RuntimeException e) {
            error(e.getMessage(), e);
            throw new IOException(e.getMessage(), e);
        }
    }
Joins text instances into a single text instance.
stroom-pipeline/src/main/java/stroom/pipeline/writer/FileAppender.java