Example usage for org.apache.commons.io.output NullOutputStream nullOutputStream

List of usage examples for org.apache.commons.io.output NullOutputStream nullOutputStream

Introduction

In this page you can find the example usage for org.apache.commons.io.output NullOutputStream nullOutputStream.

Prototype

public static OutputStream nullOutputStream() 

Source Link

Document

Returns a new OutputStream which discards all bytes.

Usage

From source file:org.lightjason.agentspeak.language.CCommon.java

/**
 * compression algorithm//from w ww.  jav  a  2 s.  c o m
 *
 * @param p_compression compression algorithm
 * @param p_input input string
 * @return number of compression bytes
 * @warning counting stream returns the correct number of bytes after flushing
 */
private static double compress(final ECompression p_compression, final String p_input) {
    final DataOutputStream l_counting = new DataOutputStream(new NullOutputStream());

    try (final InputStream l_input = new ByteArrayInputStream(p_input.getBytes(StandardCharsets.UTF_8));
            final OutputStream l_compress = p_compression.get(l_counting)) {
        IOUtils.copy(l_input, l_compress);
    } catch (final IOException l_exception) {
        return 0;
    }

    return l_counting.size();
}

From source file:org.lockss.exporter.kbart.TestKbartExporter.java

/**
 * This does not actually make any assertions, but involves the KbartDummyExporter,
 * which tests the records it receives./*from w w w  .j  a v  a2 s .  c om*/
 */
public final void testExport() {
    // Test basic export
    this.kb = new KbartDummyExporter(titles, KbartExporter.OutputFormat.HTML, this);
    this.omitEmptyFields = false;
    this.showHealthRatings = false;
    this.filter = KbartExportFilter.identityFilter(titles);
    kb.setFilter(filter);
    kb.setCompress(false);
    kb.export(new NullOutputStream());
    assertEquals("Number of titles does not match export count.", titles.size(), kb.exportCount);

    // Test predefined custom export
    this.kb = new KbartDummyExporter(titles, KbartExporter.OutputFormat.HTML, this);
    this.omitEmptyFields = false;
    this.showHealthRatings = false;
    this.filter = new KbartExportFilter(titles, KbartExportFilter.PredefinedColumnOrdering.ISSN_ONLY,
            omitEmptyFields, omitHeader, excludeNoIdTitles);
    kb.setFilter(filter);
    kb.export(new NullOutputStream());
    assertEquals("Number of titles does not match export count.", titles.size(), kb.exportCount);

    // Test custom export
    List<Field> ordering = new ArrayList<Field>() {
        {
            add(EMPTY_FIELD);
            add(Field.FIRST_AUTHOR);
            add(Field.ONLINE_IDENTIFIER);
            add(Field.TITLE_ID);
        }
    };
    this.kb = new KbartDummyExporter(titles, KbartExporter.OutputFormat.HTML, this);
    this.omitEmptyFields = true;
    this.showHealthRatings = false;
    this.filter = new KbartExportFilter(titles, KbartExportFilter.CustomColumnOrdering.create(ordering),
            omitEmptyFields, omitHeader, excludeNoIdTitles);
    kb.setFilter(filter);
    kb.export(new NullOutputStream());
    assertEquals("Number of titles does not match export count.", titles.size(), kb.exportCount);
}

From source file:org.lockss.util.TestStreamUtil.java

public void testCopyInputStreamPokeWatchdog() throws IOException {
    TimeBase.setSimulated(1000);//w w w.  j a  v a  2  s  .  c  o m
    final MyLockssWatchdog wdog = new MyLockssWatchdog(100);
    SimpleBinarySemaphore wait = new SimpleBinarySemaphore();
    SimpleBinarySemaphore poke = new SimpleBinarySemaphore();
    int size = 50 * StreamUtil.COPY_WDOG_CHECK_EVERY_BYTES;
    // make an InputStream that waits every time it has supplied twice the
    // byte interval at which StreamUtil.copy() checks to see if it's time
    // to poke the watchdog
    final InputStream is = new SemwaitInputStream(new ZeroInputStream(size),
            StreamUtil.COPY_WDOG_CHECK_EVERY_BYTES * 2, wait, poke);
    final OutputStream os = new NullOutputStream();
    Thread th = new Thread() {
        public void run() {
            try {
                StreamUtil.copy(is, os, wdog);
            } catch (IOException e) {
                throw new RuntimeException("", e);
            }
        }
    };
    th.start();
    assertTrue(wait.take(TIMEOUT_SHOULDNT));
    assertEquals(0, wdog.times.size());
    TimeBase.step(1000);
    poke.give();
    assertTrue(wait.take(TIMEOUT_SHOULDNT));
    assertEquals(1, wdog.times.size());
    TimeBase.step(1000);
    poke.give();
    assertTrue(wait.take(TIMEOUT_SHOULDNT));
    poke.give();
    assertTrue(wait.take(TIMEOUT_SHOULDNT));
    assertEquals(2, wdog.times.size());
    is.close();
    os.close();
}

From source file:org.lockss.util.TestStreamUtil.java

public void testCopyExceptionWrapping() throws IOException {
    InputStream is;/*from w  w  w. j  a  va 2s  .  c  om*/
    OutputStream os;

    is = new ThrowingInputStream(new StringInputStream("test string"), e1, null);
    os = new NullOutputStream();
    try {
        StreamUtil.copy(is, os, -1, null, false);
        fail("StreamUtil.copy(ThrowingInputStream) didn't throw on read");
    } catch (StreamUtil.InputException e) {
        fail("StreamUtil.copy(ThrowingInputStream) shouldn't have wrapped exception");
    } catch (IOException e) {
        assertSame(e1, e);
    }
    is = new ThrowingInputStream(new StringInputStream("test string"), e1, null);
    try {
        StreamUtil.copy(is, os, -1, null, true);
        fail("StreamUtil.copy(ThrowingInputStream) didn't throw on read");
    } catch (StreamUtil.InputException e) {
        assertSame(e1, e.getCause());
    }
    is = new StringInputStream("test string");
    os = new ThrowingOutputStream(new NullOutputStream(), e2, null);
    try {
        StreamUtil.copy(is, os, -1, null, false);
        fail("StreamUtil.copy(ThrowingOutputStream) didn't throw on write");
    } catch (StreamUtil.OutputException e) {
        fail("StreamUtil.copy(ThrowingOutputStream) shouldn't have wrapped exception");
    } catch (IOException e) {
        assertSame(e2, e);
    }
    is = new StringInputStream("test string");
    os = new ThrowingOutputStream(new NullOutputStream(), e2, null);
    try {
        StreamUtil.copy(is, os, -1, null, true);
        fail("StreamUtil.copy(ThrowingOutputStream) didn't throw on write");
    } catch (StreamUtil.OutputException e) {
        assertSame(e2, e.getCause());
    }
}

From source file:org.mediawiki.importer.UTF8BoundsTest.java

private boolean runImportThingy(String sample) throws IOException {
    OutputStream output = new NullOutputStream();
    InputStream input = new ByteArrayInputStream(sample.getBytes(StandardCharsets.UTF_8));
    DumpWriter sink = new XmlDumpWriter0_10(output);
    XmlDumpReader source = new XmlDumpReader(input, sink);

    source.readDump();//w w w. j  a  v  a2  s  .c o m

    return true; // did not throw
}

From source file:org.moe.gradle.tasks.Launchers.java

public static void addTasks(@NotNull MoePlugin plugin) {
    Require.nonNull(plugin);//w  w  w .ja v a 2  s.c  om

    final Project project = plugin.getProject();
    final TaskContainer tasks = project.getTasks();

    // Collect devices
    final List<String> devices = new ArrayList<>();
    if (project.hasProperty(MOE_LAUNCHER_DEVICE_UDID_PROPERTY)) {
        Arrays.stream(((String) project.property(MOE_LAUNCHER_DEVICE_UDID_PROPERTY)).split(Pattern.quote(",")))
                .map(String::trim).forEach(devices::add);
    }

    // Collect simulators
    final List<String> simulators = new ArrayList<>();
    if (project.hasProperty(MOE_LAUNCHER_SIMULATOR_UDID_PROPERTY)) {
        Arrays.stream(
                ((String) project.property(MOE_LAUNCHER_SIMULATOR_UDID_PROPERTY)).split(Pattern.quote(",")))
                .map(String::trim).forEach(simulators::add);
    }

    // If there were no devices & simulators specified, add null to devices to indicate first available device
    if (devices.size() == 0 && simulators.size() == 0) {
        devices.add(null);
    }

    // Options
    final Options options = new Options();
    options.read(project);

    { // List connected devices
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        tasks.create("moeListDevices", JavaExec.class, exec -> {
            exec.setGroup(AbstractMoePlugin.MOE);
            exec.setDescription("Lists all connected devices.");
            new DeviceLauncherBuilder().setList(true).build(plugin, exec);

            exec.setIgnoreExitValue(true);
            exec.setStandardOutput(baos);
            exec.setErrorOutput(new NullOutputStream());

        }).getActions().add(task -> LOG.quiet("\n" + baos.toString().trim() + "\n"));
    }

    { // List available simulators
        tasks.create("moeListSimulators", DefaultTask.class, exec -> {
            exec.setGroup(AbstractMoePlugin.MOE);
            exec.setDescription("Lists all simulators.");
        }).getActions().add(task -> {

            final String list;
            if (Os.isFamily(Os.FAMILY_MAC) && TaskUtils.checkExec(project, "which", "xcrun")) {
                LOG.info("Initializing");
                try {
                    list = SimCtl.getDevices().stream().map(d -> "- " + d).collect(Collectors.joining("\n"));
                } catch (Throwable t) {
                    throw new GradleException("Failed to get list of simulators", t);
                }
            } else {
                list = "";
            }

            LOG.quiet("\nAvailable Simulators:\n" + list.trim() + "\n");
        });
    }

    final SourceSetContainer sourceSets = plugin.getJavaConvention().getSourceSets();

    { // Launch an application on a device or simulator
        final SourceSet sourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);

        // Get XcodeBuild task for device
        final XcodeBuild xcodeBuildDev;
        if (devices.size() > 0) {
            xcodeBuildDev = plugin.getTaskBy(XcodeBuild.class, sourceSet, options.mode,
                    plugin.getExtension().getPlatformType());
        } else {
            xcodeBuildDev = null;
        }

        // Get XcodeBuild task for simulator
        final XcodeBuild xcodeBuildSim;
        if (simulators.size() > 0) {
            xcodeBuildSim = plugin.getTaskBy(XcodeBuild.class, sourceSet, options.mode,
                    plugin.getExtension().getPlatformType().simulatorPlatform);
        } else {
            xcodeBuildSim = null;
        }

        // Create task
        final Task launch = tasks.create("moeLaunch", task -> {
            task.setGroup(AbstractMoePlugin.MOE);
            task.setDescription("Build and run the MOE application on a device or simulator.");
            setupDevicesAndSimulators(plugin, project, devices, simulators, options, xcodeBuildDev,
                    xcodeBuildSim, task, false);
        });
        if (options.build && xcodeBuildDev != null) {
            launch.dependsOn(xcodeBuildDev);
        }
        if (xcodeBuildDev != null) {
            launch.mustRunAfter(xcodeBuildDev);
        }
        if (options.build && xcodeBuildSim != null) {
            launch.dependsOn(xcodeBuildSim);
        }
        if (xcodeBuildSim != null) {
            launch.mustRunAfter(xcodeBuildSim);
        }
    }

    { // Launch tests on a device or simulator
        final SourceSet sourceSet = sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME);

        // Get XcodeBuild task for device
        final XcodeBuild xcodeBuildDev;
        if (devices.size() > 0) {
            xcodeBuildDev = plugin.getTaskBy(XcodeBuild.class, sourceSet, options.mode,
                    plugin.getExtension().getPlatformType());
        } else {
            xcodeBuildDev = null;
        }

        // Get XcodeBuild task for simulator
        final XcodeBuild xcodeBuildSim;
        if (simulators.size() > 0) {
            xcodeBuildSim = plugin.getTaskBy(XcodeBuild.class, sourceSet, options.mode,
                    plugin.getExtension().getPlatformType().simulatorPlatform);
        } else {
            xcodeBuildSim = null;
        }

        // Create task
        final Task launch = tasks.create("moeTest", task -> {
            task.setGroup(AbstractMoePlugin.MOE);
            task.setDescription("Build and run tests on a device or simulator.");
            setupDevicesAndSimulators(plugin, project, devices, simulators, options, xcodeBuildDev,
                    xcodeBuildSim, task, true);
        });
        if (options.build && xcodeBuildDev != null) {
            launch.dependsOn(xcodeBuildDev);
        }
        if (xcodeBuildDev != null) {
            launch.mustRunAfter(xcodeBuildDev);
        }
        if (options.build && xcodeBuildSim != null) {
            launch.dependsOn(xcodeBuildSim);
        }
        if (xcodeBuildSim != null) {
            launch.mustRunAfter(xcodeBuildSim);
        }
    }
}

From source file:org.moe.gradle.utils.TaskUtils.java

public static boolean checkExec(@NotNull Project project, @NotNull String... commands) {
    Require.nonNull(project);/* w  w w.  j  a v a  2s  .  c o m*/
    final List<String> cmds = new ArrayList<>(Arrays.asList(Require.nonNull(commands)));
    Require.sizeGT(cmds, 0);

    final ExecResult result = project.exec(spec -> {
        spec.setIgnoreExitValue(true);
        spec.setExecutable(cmds.remove(0));
        spec.args(cmds);
        spec.setErrorOutput(new NullOutputStream());
        spec.setStandardOutput(new NullOutputStream());
    });
    return result.getExitValue() == 0;
}

From source file:org.nuxeo.ecm.core.storage.binary.DefaultBinaryManager.java

protected String storeAndDigest(FileSource source) throws IOException {
    File sourceFile = source.getFile();
    InputStream in = source.getStream();
    OutputStream out = new NullOutputStream();
    String digest;// w  w  w  .  j a  v  a 2  s.  c om
    try {
        digest = storeAndDigest(in, out);
    } finally {
        in.close();
        out.close();
    }
    File digestFile = getFileForDigest(digest, true);
    atomicMove(sourceFile, digestFile);
    source.setFile(digestFile);
    return digest;
}

From source file:org.nuxeo.ecm.core.storage.sql.DefaultBinaryManager.java

protected String storeAndDigest(FileSource source) throws IOException {
    File sourceFile = source.getFile();
    InputStream in = source.getStream();
    OutputStream out = new NullOutputStream();
    String digest;//from   w  w w .  ja  v  a 2 s.  c o m
    try {
        digest = storeAndDigest(in, out);
    } finally {
        in.close();
        out.close();
    }
    File digestFile = getFileForDigest(digest, true);
    if (!sourceFile.renameTo(digestFile)) {
        FileUtils.copy(sourceFile, digestFile);
        sourceFile.delete();
    }
    source.setFile(digestFile);
    return digest;
}

From source file:org.nuxeo.ftest.cap.ITErrorTest.java

/** Fully reads the stream of a page. */
protected void getAllPage(WebClient client, WebRequest request) throws IOException {
    HtmlPage page = client.getPage(request);
    try (InputStream in = page.getWebResponse().getContentAsStream(); //
            OutputStream out = new NullOutputStream()) {
        IOUtils.copy(in, out);//from   w  w  w . ja v  a 2  s. co m
    }
}