Package org.jnode.util

Examples of org.jnode.util.WriterOutputStream


                final ShellManager sm = InitialNaming.lookup(ShellManager.NAME);
                final ConsoleManager conMgr = sm.getCurrentShell().getConsole().getManager();
                final PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
                TextConsole console = createConsoleWithShell(conMgr, out);
                System.setIn(new ReaderInputStream(console.getIn()));
                System.setOut(new PrintStream(new WriterOutputStream(console.getOut(), false), true));
                System.setErr(new PrintStream(new WriterOutputStream(console.getErr(), false), true));
            } catch (Exception ex) {
                // FIXME
                System.out.println("Problem creating the isolated console");
                ex.printStackTrace(System.err);
            }
View Full Code Here


    private Socket createSocketForOutput(Closeable closeable) throws IOException {
        OutputStream out;
        if (closeable instanceof Writer) {
            boolean isConsole = closeable instanceof ShellConsoleWriter;
            out = new WriterOutputStream((Writer) closeable, !isConsole);       
        } else {
            out = (OutputStream) closeable;
        }
        return new IsolateSocket(out);
    }
View Full Code Here

    }
   
    public synchronized OutputStream getOutputStream() {
        if (outputStream == null) {
            boolean isConsole = writer instanceof ShellConsoleWriter;
            outputStream = new WriterOutputStream(writer, getEncoding(), !isConsole);
        }
        return outputStream;
    }
View Full Code Here

    @Test
    public void testEmpty() throws Exception {
        String LINE = "";
        StringWriter sw = new StringWriter();
        WriterOutputStream wos = new WriterOutputStream(sw, "UTF-8", true);
        byte[] buffer = LINE.getBytes();
        wos.write(buffer);
        wos.flush();
        Assert.assertEquals(LINE, sw.getBuffer().toString());
    }
View Full Code Here

    @Test
    public void testLine() throws Exception {
        String LINE = "The quick brown fox jumped over the lazy doc";
        StringWriter sw = new StringWriter();
        WriterOutputStream wos = new WriterOutputStream(sw, "UTF-8", true);
        byte[] buffer = LINE.getBytes();
        wos.write(buffer);
        wos.flush();
        Assert.assertEquals(LINE, sw.getBuffer().toString());
    }
View Full Code Here

    @Test
    public void testByteAtATime() throws Exception {
        String LINE = "The quick brown fox jumped over the lazy doc";
        StringWriter sw = new StringWriter();
        WriterOutputStream wos = new WriterOutputStream(sw, "UTF-8", true);
        byte[] buffer = LINE.getBytes();
        for (byte b : buffer) {
            wos.write(b);
        }
        wos.flush();
        Assert.assertEquals(LINE, sw.getBuffer().toString());
    }
View Full Code Here

    @Test
    public void testByteAtATimeWithFlushes() throws Exception {
        String LINE = "The quick brown fox jumped over the lazy doc";
        StringWriter sw = new StringWriter();
        WriterOutputStream wos = new WriterOutputStream(sw, "UTF-8", true);
        byte[] buffer = LINE.getBytes();
        for (int i = 0; i < buffer.length; i++) {
            wos.write(buffer[i]);
            wos.flush();
            Assert.assertEquals(LINE.charAt(i), sw.getBuffer().charAt(i));
        }
        Assert.assertEquals(LINE, sw.getBuffer().toString());
    }
View Full Code Here

        for (int i = 0; i < chars.length; i++) {
            chars[i] = (char) i;
        }
        byte[] buffer = new String(chars).getBytes();
        StringWriter sw = new StringWriter();
        WriterOutputStream wos = new WriterOutputStream(sw, "UTF-8", true);
        wos.write(buffer);
        wos.flush();
        StringBuffer sb = sw.getBuffer();
        Assert.assertEquals(chars.length, sb.length());
        for (int i = 0; i < chars.length; i++) {
            Assert.assertEquals(chars[i], sb.charAt(i));
        }
View Full Code Here

    @Test
    public void testBadUnicode() throws Exception {
        byte[] BAD = new byte[] {(byte) 0x80};
        StringWriter sw = new StringWriter();
        WriterOutputStream wos = new WriterOutputStream(sw, "UTF-8", true);
        try {
            wos.write(BAD);
            wos.flush();
            Assert.fail("no exception thrown");
        } catch (MalformedInputException ex) {
            // expected
        }
    }
View Full Code Here

    @Test
    public void testBadUnicode2() throws Exception {
        byte[] BAD = new byte[] {(byte) 'h', (byte) 'i', (byte) 0x80};
        StringWriter sw = new StringWriter();
        WriterOutputStream wos = new WriterOutputStream(sw, "UTF-8", true);
        try {
            wos.write(BAD);
            wos.flush();
            Assert.fail("no exception thrown");
        } catch (MalformedInputException ex) {
            // expected
            Assert.assertEquals("hi", sw.getBuffer().toString());
        }
View Full Code Here

TOP

Related Classes of org.jnode.util.WriterOutputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.