Example usage for java.io ByteArrayOutputStream reset

List of usage examples for java.io ByteArrayOutputStream reset

Introduction

In this page you can find the example usage for java.io ByteArrayOutputStream reset.

Prototype

public synchronized void reset() 

Source Link

Document

Resets the count field of this ByteArrayOutputStream to zero, so that all currently accumulated output in the output stream is discarded.

Usage

From source file:org.kuali.ole.module.purap.document.web.struts.PurchaseOrderAction.java

/**
 * Is invoked when the user clicks on the Retransmit button on both the PO tabbed page and on the Purchase Order
 * Retransmit Document page, which is essentially a PO tabbed page with the other irrelevant tabs being hidden. If it was
 * invoked from the PO tabbed page, if the PO's pending indicator is false, this method will invoke a method in the
 * PurchaseOrderService to update the flags, create the PurchaseOrderRetransmitDocument and route it. If the routing was
 * successful, we'll display the Purchase Order Retransmit Document page to the user, containing the newly created and routed
 * PurchaseOrderRetransmitDocument and a retransmit button as well as a list of items that the user can select to be
 * retransmitted. If it was invoked from the Purchase Order Retransmit Document page, we'll invoke the
 * retransmitPurchaseOrderPDF method to create a PDF document based on the PO information and the items that were selected by
 * the user on the Purchase Order Retransmit Document page to be retransmitted, then display the PDF to the browser.
 *
 * @param mapping  An ActionMapping/*from  www.  ja v a 2s.c om*/
 * @param form     An ActionForm
 * @param request  The HttpServletRequest
 * @param response The HttpServletResponse
 * @return An ActionForward
 * @throws Exception
 */
public ActionForward printingPreviewPo(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    String poDocId = ((PurchaseOrderForm) form).getDocId();
    ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
    try {
        SpringContext.getBean(PurchaseOrderService.class).performPurchaseOrderPreviewPrinting(poDocId, baosPDF);
    } finally {
        if (baosPDF != null) {
            baosPDF.reset();
        }
    }
    String basePath = getApplicationBaseUrl();
    String docId = ((PurchaseOrderForm) form).getDocId();
    String methodToCallPrintPurchaseOrderPDF = "printPurchaseOrderPDFOnly";
    String methodToCallDocHandler = "docHandler";
    String printPOPDFUrl = getUrlForPrintPO(basePath, docId, methodToCallPrintPurchaseOrderPDF);
    String displayPOTabbedPageUrl = getUrlForPrintPO(basePath, docId, methodToCallDocHandler);
    request.setAttribute("printPOPDFUrl", printPOPDFUrl);
    request.setAttribute("displayPOTabbedPageUrl", displayPOTabbedPageUrl);
    String label = SpringContext.getBean(DataDictionaryService.class)
            .getDocumentLabelByTypeName(OLEConstants.FinancialDocumentTypeCodes.PURCHASE_ORDER);
    request.setAttribute("purchaseOrderLabel", label);
    GlobalVariables.getUserSession().addObject("isPreview", new Boolean(true));

    return mapping.findForward("printPurchaseOrderPDF");
}

From source file:test.jamocha.languages.clips.SystemTest.java

@Test
public void testSimpleNegatedTest() throws ParseException {
    final Network network = new Network();
    final ByteArrayOutputStream out = initializeAppender(network);
    {//from   w  ww.  j  a  va  2  s  .c o  m
        final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(unwatch all)\n(watch facts)\n");
        assertThat(returnValues.getLeft(), empty());
        assertThat(returnValues.getRight(), empty());
        assertThat(out.toString(), isEmptyString());
    }
    {
        final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network,
                "(deftemplate t1 (slot s1 (type INTEGER)))\n");
        assertThat(returnValues.getLeft(), empty());
        assertThat(returnValues.getRight(), empty());
        assertThat(out.toString(), isEmptyString());
    }
    {
        final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network,
                "(defrule r1 (t1 (s1 ?x)) (not (test (> ?x 5))) => (assert (t1 (s1 999))) )\n");
        assertThat(returnValues.getLeft(), empty());
        assertThat(returnValues.getRight(), empty());
        assertThat(out.toString(), isEmptyString());
    }
    {
        final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(assert (t1 (s1 111)))\n");
        final Queue<Object> values = returnValues.getLeft();
        assertThat(values, hasSize(1));
        final Object value = values.iterator().next();
        assertThat(value, instanceOf(String.class));
        assertEquals("<Fact-2>", value);
        assertThat(returnValues.getRight(), empty());
        final String[] lines = out.toString().split(linesep);
        assertThat(lines, arrayWithSize(1));
        assertEquals("==> f-2\t(t1 (s1 111))", lines[0]);
        out.reset();
    }
    {
        final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(run)\n");
        assertThat(returnValues.getLeft(), empty());
        assertThat(returnValues.getRight(), empty());
        assertThat(out.toString(), isEmptyString());
        out.reset();
    }
    {
        final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(assert (t1 (s1 1)))\n");
        final Queue<Object> values = returnValues.getLeft();
        assertThat(values, hasSize(1));
        final Object value = values.iterator().next();
        assertThat(value, instanceOf(String.class));
        assertEquals("<Fact-3>", value);
        assertThat(returnValues.getRight(), empty());
        final String[] lines = out.toString().split(linesep);
        assertThat(lines, arrayWithSize(1));
        assertEquals("==> f-3\t(t1 (s1 1))", lines[0]);
        out.reset();
    }
    {
        final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(run)\n");
        assertThat(returnValues.getLeft(), empty());
        assertThat(returnValues.getRight(), empty());
        final String[] lines = out.toString().split(linesep);
        assertThat(lines, arrayWithSize(1));
        assertEquals("==> f-4\t(t1 (s1 999))", lines[0]);
        out.reset();
    }
}

From source file:org.kuali.ole.module.purap.document.web.struts.PurchaseOrderAction.java

/**
 * Is executed when the user clicks on the "print" button on a Purchase Order Print Document page. On a non
 * javascript enabled browser, it will display a page with 2 buttons. One is to display the PDF, the other is to view the PO
 * tabbed page where the PO document statuses, buttons, etc have already been updated (the updates of those occurred while the
 * <code>performPurchaseOrderFirstTransmitViaPrinting</code> method is invoked. On a javascript enabled browser, it will
 * display both the PO tabbed page containing the updated PO document info and the pdf on the next window/tab of the browser.
 *
 * @param mapping  An ActionMapping/*w  ww .j av a 2s. c o  m*/
 * @param form     An ActionForm
 * @param request  The HttpServletRequest
 * @param response The HttpServletResponse
 * @return An ActionForward
 * @throws Exception
 */
public ActionForward firstTransmitPrintPo(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    String poDocId = ((PurchaseOrderForm) form).getDocId();
    ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
    try {
        SpringContext.getBean(PurchaseOrderService.class).performPurchaseOrderFirstTransmitViaPrinting(poDocId,
                baosPDF);
    } finally {
        if (baosPDF != null) {
            baosPDF.reset();
        }
    }
    String basePath = getApplicationBaseUrl();
    String docId = ((PurchaseOrderForm) form).getDocId();
    String methodToCallPrintPurchaseOrderPDF = "printPurchaseOrderPDFOnly";
    String methodToCallDocHandler = "docHandler";
    String printPOPDFUrl = getUrlForPrintPO(basePath, docId, methodToCallPrintPurchaseOrderPDF);
    String displayPOTabbedPageUrl = getUrlForPrintPO(basePath, docId, methodToCallDocHandler);
    request.setAttribute("printPOPDFUrl", printPOPDFUrl);
    request.setAttribute("displayPOTabbedPageUrl", displayPOTabbedPageUrl);
    String label = SpringContext.getBean(DataDictionaryService.class)
            .getDocumentLabelByTypeName(OLEConstants.FinancialDocumentTypeCodes.PURCHASE_ORDER);
    request.setAttribute("purchaseOrderLabel", label);

    return mapping.findForward("printPurchaseOrderPDF");
}

From source file:org.apache.hadoop.hbase.ipc.RpcServer.java

/**
 * Setup response for the RPC Call./*from   w  w w.j  av a 2s. c  om*/
 *
 * @param response buffer to serialize the response into
 * @param call {@link Call} to which we are setting up the response
 * @param error error message, if the call failed
 * @param t
 * @throws IOException
 */
private void setupResponse(ByteArrayOutputStream response, Call call, Throwable t, String error)
        throws IOException {
    if (response != null)
        response.reset();
    call.setResponse(null, null, t, error);
}

From source file:org.kuali.kfs.module.purap.document.web.struts.PurchaseOrderAction.java

/**
 * Is invoked when the user clicks on the Retransmit button on both the PO tabbed page and on the Purchase Order Retransmit
 * Document page, which is essentially a PO tabbed page with the other irrelevant tabs being hidden. If it was invoked from the
 * PO tabbed page, if the PO's pending indicator is false, this method will invoke a method in the PurchaseOrderService to
 * update the flags, create the PurchaseOrderRetransmitDocument and route it. If the routing was successful, we'll display the
 * Purchase Order Retransmit Document page to the user, containing the newly created and routed PurchaseOrderRetransmitDocument
 * and a retransmit button as well as a list of items that the user can select to be retransmitted. If it was invoked from the
 * Purchase Order Retransmit Document page, we'll invoke the retransmitPurchaseOrderPDF method to create a PDF document based on
 * the PO information and the items that were selected by the user on the Purchase Order Retransmit Document page to be
 * retransmitted, then display the PDF to the browser.
 *
 * @param mapping An ActionMapping//w  ww . j av a2s  .com
 * @param form An ActionForm
 * @param request The HttpServletRequest
 * @param response The HttpServletResponse
 * @throws Exception
 * @return An ActionForward
 */
public ActionForward printingPreviewPo(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    String poDocId = ((PurchaseOrderForm) form).getDocId();
    ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
    try {
        SpringContext.getBean(PurchaseOrderService.class).performPurchaseOrderPreviewPrinting(poDocId, baosPDF);
    } finally {
        if (baosPDF != null) {
            baosPDF.reset();
        }
    }
    String basePath = getApplicationBaseUrl();
    String docId = ((PurchaseOrderForm) form).getDocId();
    String methodToCallPrintPurchaseOrderPDF = "printPurchaseOrderPDFOnly";
    String methodToCallDocHandler = "docHandler";
    String printPOPDFUrl = getUrlForPrintPO(basePath, docId, methodToCallPrintPurchaseOrderPDF);
    String displayPOTabbedPageUrl = getUrlForPrintPO(basePath, docId, methodToCallDocHandler);
    request.setAttribute("printPOPDFUrl", printPOPDFUrl);
    request.setAttribute("displayPOTabbedPageUrl", displayPOTabbedPageUrl);
    String label = SpringContext.getBean(DataDictionaryService.class)
            .getDocumentLabelByTypeName(KFSConstants.FinancialDocumentTypeCodes.PURCHASE_ORDER);
    request.setAttribute("purchaseOrderLabel", label);
    GlobalVariables.getUserSession().addObject("isPreview", new Boolean(true));

    return mapping.findForward("printPurchaseOrderPDF");
}

From source file:StringUtilities.java

/**
 * Parses digest-challenge string, extracting each token and value(s). Each token
 * is a directive.// w w  w  . ja  v a 2s .c o  m
 *
 * @param buf A non-null digest-challenge string.
 * @throws UnsupportedEncodingException 
 * @throws SaslException if the String cannot be parsed according to RFC 2831
 */
public static HashMap<String, String> parseDirectives(byte[] buf) throws SaslException {
    HashMap<String, String> map = new HashMap<String, String>();
    boolean gettingKey = true;
    boolean gettingQuotedValue = false;
    boolean expectSeparator = false;
    byte bch;

    ByteArrayOutputStream key = new ByteArrayOutputStream(10);
    ByteArrayOutputStream value = new ByteArrayOutputStream(10);

    int i = skipLws(buf, 0);
    while (i < buf.length) {
        bch = buf[i];

        if (gettingKey) {
            if (bch == ',') {
                if (key.size() != 0) {
                    throw new SaslException("Directive key contains a ',':" + key);
                }

                // Empty element, skip separator and lws
                i = skipLws(buf, i + 1);
            } else if (bch == '=') {
                if (key.size() == 0) {
                    throw new SaslException("Empty directive key");
                }

                gettingKey = false; // Termination of key
                i = skipLws(buf, i + 1); // Skip to next non whitespace

                // Check whether value is quoted
                if (i < buf.length) {
                    if (buf[i] == '"') {
                        gettingQuotedValue = true;
                        ++i; // Skip quote
                    }
                } else {
                    throw new SaslException("Valueless directive found: " + key.toString());
                }
            } else if (isLws(bch)) {
                // LWS that occurs after key
                i = skipLws(buf, i + 1);

                // Expecting '='
                if (i < buf.length) {
                    if (buf[i] != '=') {
                        throw new SaslException("'=' expected after key: " + key.toString());
                    }
                } else {
                    throw new SaslException("'=' expected after key: " + key.toString());
                }
            } else {
                key.write(bch); // Append to key
                ++i; // Advance
            }
        } else if (gettingQuotedValue) {
            // Getting a quoted value
            if (bch == '\\') {
                // quoted-pair = "\" CHAR ==> CHAR
                ++i; // Skip escape
                if (i < buf.length) {
                    value.write(buf[i]);
                    ++i; // Advance
                } else {
                    // Trailing escape in a quoted value
                    throw new SaslException("Unmatched quote found for directive: " + key.toString()
                            + " with value: " + value.toString());
                }
            } else if (bch == '"') {
                // closing quote
                ++i; // Skip closing quote
                gettingQuotedValue = false;
                expectSeparator = true;
            } else {
                value.write(bch);
                ++i; // Advance
            }
        } else if (isLws(bch) || bch == ',') {
            // Value terminated
            extractDirective(map, key.toString(), value.toString());
            key.reset();
            value.reset();
            gettingKey = true;
            gettingQuotedValue = expectSeparator = false;
            i = skipLws(buf, i + 1); // Skip separator and LWS
        } else if (expectSeparator) {
            throw new SaslException(
                    "Expecting comma or linear whitespace after quoted string: \"" + value.toString() + "\"");
        } else {
            value.write(bch); // Unquoted value
            ++i; // Advance
        }
    }

    if (gettingQuotedValue) {
        throw new SaslException(
                "Unmatched quote found for directive: " + key.toString() + " with value: " + value.toString());
    }

    // Get last pair
    if (key.size() > 0) {
        extractDirective(map, key.toString(), value.toString());
    }

    return map;
}

From source file:test.jamocha.languages.clips.SystemTest.java

@Test
public void testExistentialSlotAndFactVariable() throws ParseException {
    final Network network = new Network();
    final ByteArrayOutputStream out = initializeAppender(network);
    {/*w ww  . j a  va2 s  .  c  o m*/
        final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(unwatch all)\n(watch facts)\n");
        assertThat(returnValues.getLeft(), empty());
        assertThat(returnValues.getRight(), empty());
        assertThat(out.toString(), isEmptyString());
    }
    {
        final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network,
                "(deftemplate t1 (slot s1 (type FACT-ADDRESS)))\n");
        assertThat(returnValues.getLeft(), empty());
        assertThat(returnValues.getRight(), empty());
        assertThat(out.toString(), isEmptyString());
    }
    {
        final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network,
                "(defrule r1 ?x <- (initial-fact) (not (t1)) => (assert (t1 (s1 ?x))) )\n");
        assertThat(returnValues.getLeft(), empty());
        assertThat(returnValues.getRight(), empty());
        assertThat(out.toString(), isEmptyString());
    }
    {
        final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network,
                "(defrule r2 (exists ?x <- (t1 (s1 ~?x))) => )\n");
        assertThat(returnValues.getLeft(), empty());
        assertThat(returnValues.getRight(), empty());
        assertThat(out.toString(), isEmptyString());
    }
    {
        final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(run 1)\n");
        assertThat(returnValues.getLeft(), empty());
        assertThat(returnValues.getRight(), empty());
        final String[] lines = out.toString().split(linesep);
        assertThat(lines, arrayWithSize(1));
        assertEquals("==> f-2\t(t1 (s1 <Fact-1>))", lines[0]);
        out.reset();
    }
    {
        final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(watch rules)\n");
        assertThat(returnValues.getLeft(), empty());
        assertThat(returnValues.getRight(), empty());
        assertThat(out.toString(), isEmptyString());
    }
    {
        final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(run 1)\n");
        assertThat(returnValues.getLeft(), empty());
        assertThat(returnValues.getRight(), empty());
        final String[] lines = out.toString().split(linesep);
        assertThat(lines, arrayWithSize(1));
        assertThat(lines[0], isOneOf("FIRE r2 : *,f-1", "FIRE r2 : f-1,*"));
        out.reset();
    }
}

From source file:org.kuali.kfs.module.purap.document.web.struts.PurchaseOrderAction.java

/**
 * Is executed when the user clicks on the "print" button on a Purchase Order Print Document page. On a non javascript enabled
 * browser, it will display a page with 2 buttons. One is to display the PDF, the other is to view the PO tabbed page where the
 * PO document statuses, buttons, etc have already been updated (the updates of those occurred while the
 * <code>performPurchaseOrderFirstTransmitViaPrinting</code> method is invoked. On a javascript enabled browser, it will display
 * both the PO tabbed page containing the updated PO document info and the pdf on the next window/tab of the browser.
 *
 * @param mapping An ActionMapping/*from  w ww  . ja  va  2  s . c om*/
 * @param form An ActionForm
 * @param request The HttpServletRequest
 * @param response The HttpServletResponse
 * @throws Exception
 * @return An ActionForward
 */
public ActionForward firstTransmitPrintPo(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    String poDocId = ((PurchaseOrderForm) form).getDocId();
    ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
    try {
        SpringContext.getBean(PurchaseOrderService.class).performPurchaseOrderFirstTransmitViaPrinting(poDocId,
                baosPDF);
    } finally {
        if (baosPDF != null) {
            baosPDF.reset();
        }
    }
    String basePath = getApplicationBaseUrl();
    String docId = ((PurchaseOrderForm) form).getDocId();
    String methodToCallPrintPurchaseOrderPDF = "printPurchaseOrderPDFOnly";
    String methodToCallDocHandler = "docHandler";
    String printPOPDFUrl = getUrlForPrintPO(basePath, docId, methodToCallPrintPurchaseOrderPDF);
    String displayPOTabbedPageUrl = getUrlForPrintPO(basePath, docId, methodToCallDocHandler);
    request.setAttribute("printPOPDFUrl", printPOPDFUrl);
    request.setAttribute("displayPOTabbedPageUrl", displayPOTabbedPageUrl);
    String label = SpringContext.getBean(DataDictionaryService.class)
            .getDocumentLabelByTypeName(KFSConstants.FinancialDocumentTypeCodes.PURCHASE_ORDER);
    request.setAttribute("purchaseOrderLabel", label);

    return mapping.findForward("printPurchaseOrderPDF");
}

From source file:test.jamocha.languages.clips.SystemTest.java

@Test
public void testRegularSlotVariableExistentialFactVariable() throws ParseException {
    final Network network = new Network();
    final ByteArrayOutputStream out = initializeAppender(network);
    {/*from   w  w w.j a v a  2 s  .  c  o  m*/
        final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(unwatch all)\n(watch facts)\n");
        assertThat(returnValues.getLeft(), empty());
        assertThat(returnValues.getRight(), empty());
        assertThat(out.toString(), isEmptyString());
    }
    {
        final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network,
                "(deftemplate t1 (slot s1 (type FACT-ADDRESS)))\n");
        assertThat(returnValues.getLeft(), empty());
        assertThat(returnValues.getRight(), empty());
        assertThat(out.toString(), isEmptyString());
    }
    {
        final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network,
                "(defrule r1 ?x <- (initial-fact) (not (t1)) => (assert (t1 (s1 ?x))) )\n");
        assertThat(returnValues.getLeft(), empty());
        assertThat(returnValues.getRight(), empty());
        assertThat(out.toString(), isEmptyString());
    }
    {
        final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network,
                "(defrule r2 (t1 (s1 ?x)) (exists ?x <- (initial-fact)) => )\n");
        assertThat(returnValues.getLeft(), empty());
        assertThat(returnValues.getRight(), empty());
        assertThat(out.toString(), isEmptyString());
    }
    {
        final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(run 1)\n");
        assertThat(returnValues.getLeft(), empty());
        assertThat(returnValues.getRight(), empty());
        final String[] lines = out.toString().split(linesep);
        assertThat(lines, arrayWithSize(1));
        assertEquals("==> f-2\t(t1 (s1 <Fact-1>))", lines[0]);
        out.reset();
    }
    {
        final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(watch rules)\n");
        assertThat(returnValues.getLeft(), empty());
        assertThat(returnValues.getRight(), empty());
        assertThat(out.toString(), isEmptyString());
    }
    {
        final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(run 1)\n");
        assertThat(returnValues.getLeft(), empty());
        assertThat(returnValues.getRight(), empty());
        final String[] lines = out.toString().split(linesep);
        assertThat(lines, arrayWithSize(1));
        assertThat(lines[0], isOneOf("FIRE r2 : *,f-2", "FIRE r2 : f-2,*"));
        out.reset();
    }
}

From source file:org.g_node.converter.ConvCliToolControllerTest.java

/**
 * Tests the run method of the {@link ConvCliToolController}.
 * @throws Exception//  w  w w  . ja v a2s.c  o  m
 */
@Test
public void runTest() throws Exception {
    // TODO check if this should be split up into different tests.

    // Set up environment
    final PrintStream stdout = System.out;
    final ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    System.setOut(new PrintStream(outStream));
    final PrintStream errout = System.err;
    final ByteArrayOutputStream errStream = new ByteArrayOutputStream();
    System.setErr(new PrintStream(errStream));

    Logger rootLogger = Logger.getRootLogger();
    rootLogger.setLevel(Level.INFO);
    rootLogger.addAppender(new ConsoleAppender(new PatternLayout("[%-5p] %m%n")));

    // Create test files
    final String tmpRoot = System.getProperty("java.io.tmpdir");
    final String testFolderName = "fileservicetest";
    final String testFileName = "test.txt";
    final Path testFileFolder = Paths.get(tmpRoot, testFolderName);
    final File currTestFile = testFileFolder.resolve(testFileName).toFile();
    FileUtils.write(currTestFile, "This is a normal test file");

    final String testTurtleFileName = "test.ttl";
    final String testTurtleDefaultOutName = "test_out.ttl";
    final File currTurtleTestFile = testFileFolder.resolve(testTurtleFileName).toFile();
    FileUtils.write(currTurtleTestFile, "");

    final String testInvalidFileName = "test.rdf";
    final File currInvalidTestFile = testFileFolder.resolve(testInvalidFileName).toFile();
    FileUtils.write(currInvalidTestFile, "I shall crash!");

    final String outFileName = testFileFolder.resolve("out.ttl").toString();

    final CommandLineParser parser = new DefaultParser();
    final Options useOptions = this.convCont.options();
    String[] args;
    CommandLine cmd;

    // Test missing argument
    args = new String[1];
    args[0] = "-i";
    try {
        parser.parse(useOptions, args, false);
    } catch (MissingArgumentException e) {
        assertThat(e).hasMessage("Missing argument for option: i");
    }

    // Test non existent input file
    args = new String[2];
    args[0] = "-i";
    args[1] = "iDoNotExist";
    cmd = parser.parse(useOptions, args, false);
    this.convCont.run(cmd);

    assertThat(outStream.toString()).contains("Input file iDoNotExist does not exist");
    outStream.reset();

    // Test existing input file, unsupported file type
    args = new String[2];
    args[0] = "-i";
    args[1] = currTestFile.toString();
    cmd = parser.parse(useOptions, args, false);
    this.convCont.run(cmd);

    assertThat(outStream.toString())
            .contains(String.join("", "[ERROR] Input RDF file ", currTestFile.toString(), " cannot be read."));
    outStream.reset();

    // Test provide supported input file type, unsupported output RDF format
    args = new String[4];
    args[0] = "-i";
    args[1] = currTurtleTestFile.toString();
    args[2] = "-f";
    args[3] = "iDoNotExist";
    cmd = parser.parse(useOptions, args, false);
    this.convCont.run(cmd);

    assertThat(outStream.toString()).contains("[ERROR] Unsupported output format: 'IDONOTEXIST'");
    outStream.reset();

    // Test provide supported input file type, test write output file w/o providing output filename
    args = new String[2];
    args[0] = "-i";
    args[1] = currTurtleTestFile.toString();
    cmd = parser.parse(useOptions, args, false);
    this.convCont.run(cmd);

    assertThat(outStream.toString()).contains(String.join("", "[INFO ] Writing data to RDF file '",
            testFileFolder.resolve(testTurtleDefaultOutName).toString(), "' using format 'TTL'"));
    outStream.reset();

    // Test invalid RDF input file
    args = new String[2];
    args[0] = "-i";
    args[1] = currInvalidTestFile.toString();
    cmd = parser.parse(useOptions, args, false);
    this.convCont.run(cmd);

    assertThat(outStream.toString()).contains("[line: 1, col: 1 ] Content is not allowed in prolog.");
    outStream.reset();

    // Test writing to provided output file does not match provided output format
    args = new String[6];
    args[0] = "-i";
    args[1] = currTurtleTestFile.toString();
    args[2] = "-o";
    args[3] = outFileName;
    args[4] = "-f";
    args[5] = "JSON-LD";

    cmd = parser.parse(useOptions, args, false);
    this.convCont.run(cmd);

    assertThat(outStream.toString()).contains(String.join("", "[INFO ] Writing data to RDF file '", outFileName,
            ".jsonld' using format 'JSON-LD'"));
    outStream.reset();

    // Test writing to provided output file
    args = new String[4];
    args[0] = "-i";
    args[1] = currTurtleTestFile.toString();
    args[2] = "-o";
    args[3] = outFileName;

    cmd = parser.parse(useOptions, args, false);
    this.convCont.run(cmd);

    assertThat(outStream.toString()).contains(
            String.join("", "[INFO ] Writing data to RDF file '", outFileName, "' using format 'TTL'"));
    outStream.reset();

    // Clean up
    if (Files.exists(testFileFolder)) {
        FileUtils.deleteDirectory(testFileFolder.toFile());
    }
    rootLogger.removeAllAppenders();
    System.setOut(stdout);
    System.setErr(errout);
}