1 7 8 package javax.sql.rowset.serial; 9 10 import java.sql.*; 11 import javax.sql.*; 12 import java.io.*; 13 import java.lang.String ; 14 import java.math.*; 15 import java.util.Map ; 16 import java.util.Vector ; 17 18 39 public class SQLOutputImpl implements SQLOutput { 40 41 45 private Vector attribs; 46 47 55 private Map map; 56 57 78 public SQLOutputImpl(Vector <?> attributes, Map <String ,?> map) 79 throws SQLException 80 { 81 if ((attributes == null) || (map == null)) { 82 throw new SQLException("Cannot instantiate a SQLOutputImpl " + 83 "instance with null parameters"); 84 } 85 this.attribs = attributes; 86 this.map = map; 87 } 88 89 95 106 public void writeString(String x) throws SQLException { 107 attribs.add(x); 109 } 110 111 121 public void writeBoolean(boolean x) throws SQLException { 122 attribs.add(new Boolean (x)); 123 } 124 125 135 public void writeByte(byte x) throws SQLException { 136 attribs.add(new Byte (x)); 137 } 138 139 149 public void writeShort(short x) throws SQLException { 150 attribs.add(new Short (x)); 151 } 152 153 163 public void writeInt(int x) throws SQLException { 164 attribs.add(new Integer (x)); 165 } 166 167 177 public void writeLong(long x) throws SQLException { 178 attribs.add(new Long (x)); 179 } 180 181 191 public void writeFloat(float x) throws SQLException { 192 attribs.add(new Float (x)); 193 } 194 195 205 public void writeDouble(double x) throws SQLException{ 206 attribs.add(new Double (x)); 207 } 208 209 219 public void writeBigDecimal(java.math.BigDecimal x) throws SQLException{ 220 attribs.add(x); 221 } 222 223 234 public void writeBytes(byte[] x) throws SQLException { 235 attribs.add(x); 236 } 237 238 248 public void writeDate(java.sql.Date x) throws SQLException { 249 attribs.add(x); 250 } 251 252 262 public void writeTime(java.sql.Time x) throws SQLException { 263 attribs.add(x); 264 } 265 266 276 public void writeTimestamp(java.sql.Timestamp x) throws SQLException { 277 attribs.add(x); 278 } 279 280 290 public void writeCharacterStream(java.io.Reader x) throws SQLException { 291 BufferedReader bufReader = new BufferedReader(x); 292 try { 293 int i; 294 while( (i = bufReader.read()) != -1 ) { 295 char ch = (char)i; 296 StringBuffer strBuf = new StringBuffer (); 297 strBuf.append(ch); 298 299 String str = new String (strBuf); 300 String strLine = bufReader.readLine(); 301 302 writeString(str.concat(strLine)); 303 } 304 } catch(IOException ioe) { 305 306 } 307 } 308 309 319 public void writeAsciiStream(java.io.InputStream x) throws SQLException { 320 BufferedReader bufReader = new BufferedReader(new InputStreamReader(x)); 321 try { 322 int i; 323 while( (i=bufReader.read()) != -1 ) { 324 char ch = (char)i; 325 326 StringBuffer strBuf = new StringBuffer (); 327 strBuf.append(ch); 328 329 String str = new String (strBuf); 330 String strLine = bufReader.readLine(); 331 332 writeString(str.concat(strLine)); 333 } 334 }catch(IOException ioe) { 335 throw new SQLException(ioe.getMessage()); 336 } 337 } 338 339 348 public void writeBinaryStream(java.io.InputStream x) throws SQLException { 349 BufferedReader bufReader = new BufferedReader(new InputStreamReader(x)); 350 try { 351 int i; 352 while( (i=bufReader.read()) != -1 ) { 353 char ch = (char)i; 354 355 StringBuffer strBuf = new StringBuffer (); 356 strBuf.append(ch); 357 358 String str = new String (strBuf); 359 String strLine = bufReader.readLine(); 360 361 writeString(str.concat(strLine)); 362 } 363 } catch(IOException ioe) { 364 throw new SQLException(ioe.getMessage()); 365 } 366 } 367 368 376 399 public void writeObject(SQLData x) throws SQLException { 400 401 409 if (x == null) { 410 attribs.add(x); 411 return; 412 } 413 414 419 attribs.add(new SerialStruct ((SQLData)x, map)); 420 } 421 422 433 public void writeRef(Ref x) throws SQLException { 434 if (x == null) { 435 attribs.add(x); 436 return; 437 } 438 attribs.add(new SerialRef (x)); 439 } 440 441 452 public void writeBlob(Blob x) throws SQLException { 453 if (x == null) { 454 attribs.add(x); 455 return; 456 } 457 attribs.add(new SerialBlob (x)); 458 } 459 460 471 public void writeClob(Clob x) throws SQLException { 472 if (x == null) { 473 attribs.add(x); 474 return; 475 } 476 attribs.add(new SerialClob (x)); 477 } 478 479 496 public void writeStruct(Struct x) throws SQLException { 497 SerialStruct s = new SerialStruct (x,map);; 498 attribs.add(s); 499 } 500 501 513 public void writeArray(Array x) throws SQLException { 514 if (x == null) { 515 attribs.add(x); 516 return; 517 } 518 attribs.add(new SerialArray (x, map)); 519 } 520 521 532 public void writeURL(java.net.URL url) throws SQLException { 533 if (url == null) { 534 attribs.add(url); 535 return; 536 } 537 attribs.add(new SerialDatalink (url)); 538 539 } 540 } 541 542 543 544 545 546 | Popular Tags |