1 7 8 package java.io; 9 10 28 @Deprecated 29 public 30 class StringBufferInputStream extends InputStream { 31 34 protected String buffer; 35 36 41 protected int pos; 42 43 48 protected int count; 49 50 55 public StringBufferInputStream(String s) { 56 this.buffer = s; 57 count = s.length(); 58 } 59 60 74 public synchronized int read() { 75 return (pos < count) ? (buffer.charAt(pos++) & 0xFF) : -1; 76 } 77 78 94 public synchronized int read(byte b[], int off, int len) { 95 if (b == null) { 96 throw new NullPointerException (); 97 } else if ((off < 0) || (off > b.length) || (len < 0) || 98 ((off + len) > b.length) || ((off + len) < 0)) { 99 throw new IndexOutOfBoundsException (); 100 } 101 if (pos >= count) { 102 return -1; 103 } 104 if (pos + len > count) { 105 len = count - pos; 106 } 107 if (len <= 0) { 108 return 0; 109 } 110 String s = buffer; 111 int cnt = len; 112 while (--cnt >= 0) { 113 b[off++] = (byte)s.charAt(pos++); 114 } 115 116 return len; 117 } 118 119 126 public synchronized long skip(long n) { 127 if (n < 0) { 128 return 0; 129 } 130 if (n > count - pos) { 131 n = count - pos; 132 } 133 pos += n; 134 return n; 135 } 136 137 144 public synchronized int available() { 145 return count - pos; 146 } 147 148 152 public synchronized void reset() { 153 pos = 0; 154 } 155 } 156 | Popular Tags |