Example usage for java.io PrintStream PrintStream

List of usage examples for java.io PrintStream PrintStream

Introduction

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

Prototype

public PrintStream(OutputStream out, boolean autoFlush, Charset charset) 

Source Link

Document

Creates a new print stream, with the specified OutputStream, automatic line flushing and charset.

Usage

From source file:com.arpnetworking.tsdcore.sinks.ConsoleSinkTest.java

@Before
public void before() throws UnsupportedEncodingException {
    _byteArrayStream = new ByteArrayOutputStream();
    _outputStream = new PrintStream(_byteArrayStream, true, Charsets.UTF_8.name());
    _consoleSinkBuilder = new ConsoleSink.Builder().setName("console_sink_test");
}

From source file:ca.nines.ise.cmd.Works.java

/**
 * {@inheritDoc}/* w w  w  . j  a v  a 2s  . c o m*/
 */
@Override
public void execute(CommandLine cmd) throws Exception {
    Corpus corpus;
    String root = "input";

    Locale.setDefault(Locale.ENGLISH);
    PrintStream out = new PrintStream(System.out, true, "UTF-8");

    if (cmd.hasOption("l")) {
        out = new PrintStream(new FileOutputStream(cmd.getOptionValue("l")), true, "UTF-8");
    }

    corpus = new Corpus(root);
    out.println(corpus);
}

From source file:ca.nines.ise.cmd.Fragment.java

/**
 * {@inheritDoc}/* w  w w.  ja  v  a 2 s .  co  m*/
 */
@Override
public void execute(CommandLine cmd) throws Exception {
    PrintStream out;
    Writer renderer;
    Locale.setDefault(Locale.ENGLISH);
    out = new PrintStream(System.out, true, "UTF-8");

    renderer = new SGMLWriter(out);
    String[] files = getArgList(cmd);
    if (files.length == 0) {
        System.err.println("At least one document is required.");
        System.exit(-1);
    }
    DOM dom = new DOMBuilder(new File(files[0])).build();
    if (dom.getStatus() == DOMStatus.ERROR) {
        System.err.println("Document contains errors. Cannot continue.");
        System.exit(-1);
    }

    int length = 2;
    if (cmd.hasOption("n")) {
        length = Integer.parseInt(cmd.getOptionValue("n"));
    }
    String tln = "1";
    if (cmd.hasOption("tln")) {
        tln = cmd.getOptionValue("tln");
    }

    dom = dom.getTlnFragment(tln, length);

    renderer.render(dom);
}

From source file:ca.nines.ise.cmd.Abbrs.java

/**
 * {@inheritDoc}//from  ww w.  j  a  v  a2s.c  om
 */
@Override
public void execute(CommandLine cmd) throws Exception {
    File[] files;

    Locale.setDefault(Locale.ENGLISH);
    PrintStream out = new PrintStream(System.out, true, "UTF-8");

    if (cmd.hasOption("l")) {
        out = new PrintStream(new FileOutputStream(cmd.getOptionValue("l")), true, "UTF-8");
    }

    files = getFilePaths(cmd);
    Formatter formatter = new Formatter(out);

    if (files != null) {
        out.println("Found " + files.length + " files to check.");
        for (File in : files) {
            DOM dom = new DOMBuilder(in).build();
            for (Node n : dom) {
                if (n.type() == NodeType.ABBR) {
                    formatter.format("%s:%d:%d%n", n.getSource(), n.getLine(), n.getColumn());
                    formatter.format("  near TLN %s%n", n.getTLN());
                    formatter.format("  %s%n", n.getText().substring(0, Math.min(64, n.getText().length())));
                    formatter.format("  %s%n", dom.getLine(n.getLine() - 1));
                    formatter.format("%n");
                }
            }
        }
    }
}

From source file:au.csiro.casda.sodalint.ValidateServiceDescriptorTest.java

/**
 * Test method forau.csiro.casda.sodalint.ValidateServiceDescriptor#verifyServiceDescriptor
 * .//w w w.  j av  a 2 s .  c o m
 * 
 * @throws IOException
 *             If the data file cannot be read.
 */
@Test
public void testVerifyV13ServiceDescriptor() throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos, false, CHARSET_UTF_8);
    Reporter reporter = new TextOutputReporter(ps, ReportType.values(), 10, false, 1024);
    String xmlContent = FileUtils
            .readFileToString(new File("src/test/resources/service-descriptor-v1_3-good.xml"));
    vsd.verifyServiceDescriptor(reporter, xmlContent);

    String result = baos.toString(CHARSET_UTF_8);
    System.out.println(result);
    assertEquals("No message should have been reported", "", result);
}

From source file:ca.nines.ise.cmd.Chars.java

/**
 * {@inheritDoc}/*from  w  ww .  j av a2s .  c om*/
 */
@Override
public void execute(CommandLine cmd) throws Exception {
    File[] files;
    Locale.setDefault(Locale.ENGLISH);
    PrintStream out = new PrintStream(System.out, true, "UTF-8");

    if (cmd.hasOption("l")) {
        out = new PrintStream(new FileOutputStream(cmd.getOptionValue("l")), true, "UTF-8");
    }

    Map<String, Integer> m = new HashMap<>();
    Map<CharType, HashMap<String, Integer>> types = new HashMap<>();
    files = getFilePaths(cmd);

    for (CharType type : CharType.values()) {
        types.put(type, new HashMap<String, Integer>());
    }

    out.println("Found " + files.length + " files to check.");
    for (File file : files) {
        DOM dom = new DOMBuilder(file).build();
        for (Node n : dom) {
            if (n instanceof CharNode) {
                CharNode c = (CharNode) n;
                m.put(n.getText(), 1);
                types.get(c.getCharType()).put(c.getText(), 1);
            }
        }
    }

    out.println("EXISTING CHARS BY TYPE:");
    for (CharType type : CharType.values()) {
        out.println(type.name());
        for (String str : types.get(type).keySet()) {
            out.println(str);
        }
    }

    out.println("EXISTING CHARS: ");
    for (String k : m.keySet()) {
        out.println(k);
    }
}

From source file:ca.nines.ise.cmd.Syntax.java

/**
 * {@inheritDoc}/* ww  w .  j  a  va2s .  c  o m*/
 */
@Override
public void execute(CommandLine cmd) throws Exception {
    File[] files;

    Log log = Log.getInstance();
    Locale.setDefault(Locale.ENGLISH);
    PrintStream out = new PrintStream(System.out, true, "UTF-8");

    if (cmd.hasOption("l")) {
        out = new PrintStream(new FileOutputStream(cmd.getOptionValue("l")), true, "UTF-8");
    }

    files = getFilePaths(cmd);
    out.println("Found " + files.length + " files to check.");
    for (File file : files) {
        DOM dom = new DOMBuilder(file).build();
        if (log.count() > 0) {
            out.println(log);
            log.clear();
        }
    }
}

From source file:ca.nines.ise.cmd.Renumber.java

@Override
public void execute(CommandLine cmd) throws Exception {
    PrintStream outputStream;//from  w w  w  . ja v  a  2 s.  co m
    Locale.setDefault(Locale.ENGLISH);
    outputStream = new PrintStream(System.out, true, "UTF-8");
    if (cmd.hasOption("o")) {
        outputStream = new PrintStream(new FileOutputStream(cmd.getOptionValue("o")), true, "UTF-8");
    }

    String[] files = getArgList(cmd);
    if (files.length > 1) {
        System.err.println("Can only renumber one file at a time.");
        help();
        System.exit(1);
    }
    DOM dom = new DOMBuilder(new File(files[0])).build();
    if (dom.getStatus() != DOMStatus.ERROR) {
        Renumberer r = new Renumberer();
        if (cmd.hasOption("l")) {
            r.setRenumberLine(true);
        }
        if (cmd.hasOption("qln")) {
            r.setRenumberQln(true);
        }
        if (cmd.hasOption("tln")) {
            r.setRenumberTln(true);
        }
        if (cmd.hasOption("wln")) {
            r.setRenumberWln(true);
        }
        if (cmd.hasOption("act")) {
            r.setRenumberAct(true);
        }
        if (cmd.hasOption("scene")) {
            r.setRenumberScene(true);
        }
        if (cmd.hasOption("stanza")) {
            r.setRenumberStanza(true);
        }
        if (cmd.hasOption("page")) {
            r.setRenumberPage(true);
        }

        dom = r.transform(dom);

    }
    Writer out = new SGMLWriter(outputStream);
    out.render(dom);
}

From source file:au.org.ala.delta.translation.delta.DeltaFormatTranslatorTest.java

@Before
public void setUp() throws Exception {

    _bytes = new ByteArrayOutputStream();
    PrintStream pout = new PrintStream(_bytes, false, "UTF-8");

    _context = new DeltaContext();
    _outputFile = new PrintFile(pout, 80);
    _context.getOutputFileSelector().setOutputFile(_outputFile);
    _factory = new DataSetTranslatorFactory();

}

From source file:com.centurylink.cloud.sdk.core.exceptions.ErrorsContainer.java

private String getStackTrace(Exception ex) {
    try {//from ww w .j av  a2 s .  c  o  m
        ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
        PrintStream out = new PrintStream(outBytes, true, UTF_8);

        ex.printStackTrace(out);

        return outBytes.toString(UTF_8);
    } catch (UnsupportedEncodingException e) {
        throw new ClcException(e);
    }
}