1 14 package org.wings.io; 15 16 import java.io.IOException ; 17 18 public final class CountingDeviceDelegator implements Device { 19 private final Device deligee; 20 private long byteCount; 21 22 public CountingDeviceDelegator(Device d) { 23 deligee = d; 24 byteCount = 0; 25 } 26 27 public boolean isSizePreserving() { return deligee.isSizePreserving(); } 28 29 32 public void flush() throws IOException { deligee.flush(); } 33 34 public void close() throws IOException { deligee.close(); } 35 36 39 public long getSize() { return byteCount; } 40 41 44 public void resetSize() { byteCount = 0; } 45 46 49 public Device print(char c) throws IOException { 50 ++byteCount; 51 deligee.print(c); 52 return this; 53 } 54 55 58 public Device print(char[] c) throws IOException { 59 if (c != null) byteCount += c.length; 60 deligee.print(c); 61 return this; 62 } 63 64 68 public Device print(char[] c, int start, int len) throws IOException { 69 byteCount += len; 70 deligee.print(c, start, len); 71 return this; 72 } 73 74 76 79 public Device print(String s) throws IOException { 80 if (s != null) byteCount += s.length(); 81 deligee.print(s); 82 return this; 83 } 84 85 88 public Device print(int i) throws IOException { 89 byteCount += String.valueOf(i).length(); 90 deligee.print(i); 91 return this; 92 } 93 94 97 public Device print(Object o) throws IOException { 98 if (o != null) byteCount += o.toString().length(); 99 deligee.print(o); 100 return this; 101 } 102 103 106 107 110 public Device write(int c) throws IOException { 111 ++byteCount; 112 deligee.write(c); 113 return this; 114 } 115 116 120 public Device write(byte b[]) throws IOException { 121 if (b != null) byteCount += b.length; 122 deligee.write(b); 123 return this; 124 } 125 126 130 public Device write(byte b[], int off, int len) throws IOException { 131 if (b != null) byteCount += len; 132 deligee.write(b, off, len); 133 return this; 134 } 135 } 136 137 138 | Popular Tags |