1 14 package org.wings.io; 15 16 import java.io.IOException ; 17 import java.io.OutputStream ; 18 import java.io.PrintStream ; 19 20 26 public final class OutputStreamDevice implements Device { 27 private PrintStream out; 28 29 30 public OutputStreamDevice(OutputStream out) { 31 this.out = new PrintStream (out); 32 } 33 34 public boolean isSizePreserving() { return true; } 35 36 39 public void flush() throws IOException { 40 out.flush(); 41 } 42 43 public void close() throws IOException { 44 out.close(); 45 } 46 47 50 public Device print(String s) throws IOException { 51 if (s == null) 52 out.print("null"); 53 else 54 out.print(s); 55 return this; 56 } 57 58 61 public Device print(int i) throws IOException { 62 out.print(i); 63 return this; 64 } 65 66 69 public Device print(Object o) throws IOException { 70 if (o == null) 71 out.print("null"); 72 else 73 out.print(o.toString()); 74 return this; 75 } 76 77 80 public Device print(char c) throws IOException { 81 out.print(c); 82 return this; 83 } 84 85 88 public Device print(char[] c) throws IOException { 89 return print(c, 0, c.length - 1); 90 } 91 92 95 public Device print(char[] c, int start, int len) throws IOException { 96 final int end = start + len; 97 for (int i = start; i < end; ++i) 98 out.print(c[i]); 99 return this; 100 } 101 102 105 public Device write(int c) throws IOException { 106 out.write(c); 107 return this; 108 } 109 110 114 public Device write(byte b[]) throws IOException { 115 out.write(b); 116 return this; 117 } 118 119 123 public Device write(byte b[], int off, int len) throws IOException { 124 out.write(b, off, len); 125 return this; 126 } 127 } 128 129 130 | Popular Tags |