001: ///////////////////////////////////////////////////////////////////////////////
002: // Copyright (c) 2002, Eric D. Friedman All Rights Reserved.
003: //
004: // This library is free software; you can redistribute it and/or
005: // modify it under the terms of the GNU Lesser General Public
006: // License as published by the Free Software Foundation; either
007: // version 2.1 of the License, or (at your option) any later version.
008: //
009: // This library is distributed in the hope that it will be useful,
010: // but WITHOUT ANY WARRANTY; without even the implied warranty of
011: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: // GNU General Public License for more details.
013: //
014: // You should have received a copy of the GNU Lesser General Public
015: // License along with this program; if not, write to the Free Software
016: // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: ///////////////////////////////////////////////////////////////////////////////
018:
019: package gnu.trove;
020:
021: import java.io.IOException;
022: import java.io.ObjectOutput;
023:
024: /**
025: * Implementation of the variously typed procedure interfaces that supports
026: * writing the arguments to the procedure out on an ObjectOutputStream.
027: * In the case of two-argument procedures, the arguments are written out
028: * in the order received.
029: *
030: * <p>
031: * Any IOException is trapped here so that it can be rethrown in a writeObject
032: * method.
033: * </p>
034: *
035: * Created: Sun Jul 7 00:14:18 2002
036: *
037: * @author Eric D. Friedman
038: * @version $Id: SerializationProcedure.java,v 1.5 2006/11/10 23:27:54 robeden Exp $
039: */
040:
041: class SerializationProcedure implements TDoubleDoubleProcedure,
042: TDoubleFloatProcedure, TDoubleIntProcedure,
043: TDoubleLongProcedure, TDoubleShortProcedure,
044: TDoubleByteProcedure, TDoubleObjectProcedure, TDoubleProcedure,
045: TFloatDoubleProcedure, TFloatFloatProcedure,
046: TFloatIntProcedure, TFloatLongProcedure, TFloatShortProcedure,
047: TFloatByteProcedure, TFloatObjectProcedure, TFloatProcedure,
048: TIntDoubleProcedure, TIntFloatProcedure, TIntIntProcedure,
049: TIntLongProcedure, TIntShortProcedure, TIntByteProcedure,
050: TIntObjectProcedure, TIntProcedure, TLongDoubleProcedure,
051: TLongFloatProcedure, TLongIntProcedure, TLongLongProcedure,
052: TLongShortProcedure, TLongByteProcedure, TLongObjectProcedure,
053: TLongProcedure, TShortDoubleProcedure, TShortFloatProcedure,
054: TShortIntProcedure, TShortLongProcedure, TShortShortProcedure,
055: TShortByteProcedure, TShortObjectProcedure, TShortProcedure,
056: TByteDoubleProcedure, TByteFloatProcedure, TByteIntProcedure,
057: TByteLongProcedure, TByteShortProcedure, TByteByteProcedure,
058: TByteObjectProcedure, TByteProcedure, TObjectDoubleProcedure,
059: TObjectFloatProcedure, TObjectIntProcedure,
060: TObjectLongProcedure, TObjectShortProcedure,
061: TObjectByteProcedure, TObjectObjectProcedure, TObjectProcedure {
062:
063: private final ObjectOutput stream;
064: IOException exception;
065:
066: SerializationProcedure(ObjectOutput stream) {
067: this .stream = stream;
068: }
069:
070: public boolean execute(byte val) {
071: try {
072: stream.writeByte(val);
073: } catch (IOException e) {
074: this .exception = e;
075: return false;
076: }
077: return true;
078: }
079:
080: public boolean execute(short val) {
081: try {
082: stream.writeShort(val);
083: } catch (IOException e) {
084: this .exception = e;
085: return false;
086: }
087: return true;
088: }
089:
090: public boolean execute(int val) {
091: try {
092: stream.writeInt(val);
093: } catch (IOException e) {
094: this .exception = e;
095: return false;
096: }
097: return true;
098: }
099:
100: public boolean execute(double val) {
101: try {
102: stream.writeDouble(val);
103: } catch (IOException e) {
104: this .exception = e;
105: return false;
106: }
107: return true;
108: }
109:
110: public boolean execute(long val) {
111: try {
112: stream.writeLong(val);
113: } catch (IOException e) {
114: this .exception = e;
115: return false;
116: }
117: return true;
118: }
119:
120: public boolean execute(float val) {
121: try {
122: stream.writeFloat(val);
123: } catch (IOException e) {
124: this .exception = e;
125: return false;
126: }
127: return true;
128: }
129:
130: public boolean execute(Object val) {
131: try {
132: stream.writeObject(val);
133: } catch (IOException e) {
134: this .exception = e;
135: return false;
136: }
137: return true;
138: }
139:
140: public boolean execute(Object key, Object val) {
141: try {
142: stream.writeObject(key);
143: stream.writeObject(val);
144: } catch (IOException e) {
145: this .exception = e;
146: return false;
147: }
148: return true;
149: }
150:
151: public boolean execute(Object key, byte val) {
152: try {
153: stream.writeObject(key);
154: stream.writeByte(val);
155: } catch (IOException e) {
156: this .exception = e;
157: return false;
158: }
159: return true;
160: }
161:
162: public boolean execute(Object key, short val) {
163: try {
164: stream.writeObject(key);
165: stream.writeShort(val);
166: } catch (IOException e) {
167: this .exception = e;
168: return false;
169: }
170: return true;
171: }
172:
173: public boolean execute(Object key, int val) {
174: try {
175: stream.writeObject(key);
176: stream.writeInt(val);
177: } catch (IOException e) {
178: this .exception = e;
179: return false;
180: }
181: return true;
182: }
183:
184: public boolean execute(Object key, long val) {
185: try {
186: stream.writeObject(key);
187: stream.writeLong(val);
188: } catch (IOException e) {
189: this .exception = e;
190: return false;
191: }
192: return true;
193: }
194:
195: public boolean execute(Object key, double val) {
196: try {
197: stream.writeObject(key);
198: stream.writeDouble(val);
199: } catch (IOException e) {
200: this .exception = e;
201: return false;
202: }
203: return true;
204: }
205:
206: public boolean execute(Object key, float val) {
207: try {
208: stream.writeObject(key);
209: stream.writeFloat(val);
210: } catch (IOException e) {
211: this .exception = e;
212: return false;
213: }
214: return true;
215: }
216:
217: public boolean execute(int key, byte val) {
218: try {
219: stream.writeInt(key);
220: stream.writeByte(val);
221: } catch (IOException e) {
222: this .exception = e;
223: return false;
224: }
225: return true;
226: }
227:
228: public boolean execute(int key, short val) {
229: try {
230: stream.writeInt(key);
231: stream.writeShort(val);
232: } catch (IOException e) {
233: this .exception = e;
234: return false;
235: }
236: return true;
237: }
238:
239: public boolean execute(int key, Object val) {
240: try {
241: stream.writeInt(key);
242: stream.writeObject(val);
243: } catch (IOException e) {
244: this .exception = e;
245: return false;
246: }
247: return true;
248: }
249:
250: public boolean execute(int key, int val) {
251: try {
252: stream.writeInt(key);
253: stream.writeInt(val);
254: } catch (IOException e) {
255: this .exception = e;
256: return false;
257: }
258: return true;
259: }
260:
261: public boolean execute(int key, long val) {
262: try {
263: stream.writeInt(key);
264: stream.writeLong(val);
265: } catch (IOException e) {
266: this .exception = e;
267: return false;
268: }
269: return true;
270: }
271:
272: public boolean execute(int key, double val) {
273: try {
274: stream.writeInt(key);
275: stream.writeDouble(val);
276: } catch (IOException e) {
277: this .exception = e;
278: return false;
279: }
280: return true;
281: }
282:
283: public boolean execute(int key, float val) {
284: try {
285: stream.writeInt(key);
286: stream.writeFloat(val);
287: } catch (IOException e) {
288: this .exception = e;
289: return false;
290: }
291: return true;
292: }
293:
294: public boolean execute(long key, Object val) {
295: try {
296: stream.writeLong(key);
297: stream.writeObject(val);
298: } catch (IOException e) {
299: this .exception = e;
300: return false;
301: }
302: return true;
303: }
304:
305: public boolean execute(long key, byte val) {
306: try {
307: stream.writeLong(key);
308: stream.writeByte(val);
309: } catch (IOException e) {
310: this .exception = e;
311: return false;
312: }
313: return true;
314: }
315:
316: public boolean execute(long key, short val) {
317: try {
318: stream.writeLong(key);
319: stream.writeShort(val);
320: } catch (IOException e) {
321: this .exception = e;
322: return false;
323: }
324: return true;
325: }
326:
327: public boolean execute(long key, int val) {
328: try {
329: stream.writeLong(key);
330: stream.writeInt(val);
331: } catch (IOException e) {
332: this .exception = e;
333: return false;
334: }
335: return true;
336: }
337:
338: public boolean execute(long key, long val) {
339: try {
340: stream.writeLong(key);
341: stream.writeLong(val);
342: } catch (IOException e) {
343: this .exception = e;
344: return false;
345: }
346: return true;
347: }
348:
349: public boolean execute(long key, double val) {
350: try {
351: stream.writeLong(key);
352: stream.writeDouble(val);
353: } catch (IOException e) {
354: this .exception = e;
355: return false;
356: }
357: return true;
358: }
359:
360: public boolean execute(long key, float val) {
361: try {
362: stream.writeLong(key);
363: stream.writeFloat(val);
364: } catch (IOException e) {
365: this .exception = e;
366: return false;
367: }
368: return true;
369: }
370:
371: public boolean execute(double key, Object val) {
372: try {
373: stream.writeDouble(key);
374: stream.writeObject(val);
375: } catch (IOException e) {
376: this .exception = e;
377: return false;
378: }
379: return true;
380: }
381:
382: public boolean execute(double key, byte val) {
383: try {
384: stream.writeDouble(key);
385: stream.writeByte(val);
386: } catch (IOException e) {
387: this .exception = e;
388: return false;
389: }
390: return true;
391: }
392:
393: public boolean execute(double key, short val) {
394: try {
395: stream.writeDouble(key);
396: stream.writeShort(val);
397: } catch (IOException e) {
398: this .exception = e;
399: return false;
400: }
401: return true;
402: }
403:
404: public boolean execute(double key, int val) {
405: try {
406: stream.writeDouble(key);
407: stream.writeInt(val);
408: } catch (IOException e) {
409: this .exception = e;
410: return false;
411: }
412: return true;
413: }
414:
415: public boolean execute(double key, long val) {
416: try {
417: stream.writeDouble(key);
418: stream.writeLong(val);
419: } catch (IOException e) {
420: this .exception = e;
421: return false;
422: }
423: return true;
424: }
425:
426: public boolean execute(double key, double val) {
427: try {
428: stream.writeDouble(key);
429: stream.writeDouble(val);
430: } catch (IOException e) {
431: this .exception = e;
432: return false;
433: }
434: return true;
435: }
436:
437: public boolean execute(double key, float val) {
438: try {
439: stream.writeDouble(key);
440: stream.writeFloat(val);
441: } catch (IOException e) {
442: this .exception = e;
443: return false;
444: }
445: return true;
446: }
447:
448: public boolean execute(float key, Object val) {
449: try {
450: stream.writeFloat(key);
451: stream.writeObject(val);
452: } catch (IOException e) {
453: this .exception = e;
454: return false;
455: }
456: return true;
457: }
458:
459: public boolean execute(float key, byte val) {
460: try {
461: stream.writeFloat(key);
462: stream.writeByte(val);
463: } catch (IOException e) {
464: this .exception = e;
465: return false;
466: }
467: return true;
468: }
469:
470: public boolean execute(float key, short val) {
471: try {
472: stream.writeFloat(key);
473: stream.writeShort(val);
474: } catch (IOException e) {
475: this .exception = e;
476: return false;
477: }
478: return true;
479: }
480:
481: public boolean execute(float key, int val) {
482: try {
483: stream.writeFloat(key);
484: stream.writeInt(val);
485: } catch (IOException e) {
486: this .exception = e;
487: return false;
488: }
489: return true;
490: }
491:
492: public boolean execute(float key, long val) {
493: try {
494: stream.writeFloat(key);
495: stream.writeLong(val);
496: } catch (IOException e) {
497: this .exception = e;
498: return false;
499: }
500: return true;
501: }
502:
503: public boolean execute(float key, double val) {
504: try {
505: stream.writeFloat(key);
506: stream.writeDouble(val);
507: } catch (IOException e) {
508: this .exception = e;
509: return false;
510: }
511: return true;
512: }
513:
514: public boolean execute(float key, float val) {
515: try {
516: stream.writeFloat(key);
517: stream.writeFloat(val);
518: } catch (IOException e) {
519: this .exception = e;
520: return false;
521: }
522: return true;
523: }
524:
525: public boolean execute(byte key, Object val) {
526: try {
527: stream.writeByte(key);
528: stream.writeObject(val);
529: } catch (IOException e) {
530: this .exception = e;
531: return false;
532: }
533: return true;
534: }
535:
536: public boolean execute(byte key, byte val) {
537: try {
538: stream.writeByte(key);
539: stream.writeByte(val);
540: } catch (IOException e) {
541: this .exception = e;
542: return false;
543: }
544: return true;
545: }
546:
547: public boolean execute(byte key, short val) {
548: try {
549: stream.writeByte(key);
550: stream.writeShort(val);
551: } catch (IOException e) {
552: this .exception = e;
553: return false;
554: }
555: return true;
556: }
557:
558: public boolean execute(byte key, int val) {
559: try {
560: stream.writeByte(key);
561: stream.writeInt(val);
562: } catch (IOException e) {
563: this .exception = e;
564: return false;
565: }
566: return true;
567: }
568:
569: public boolean execute(byte key, long val) {
570: try {
571: stream.writeByte(key);
572: stream.writeLong(val);
573: } catch (IOException e) {
574: this .exception = e;
575: return false;
576: }
577: return true;
578: }
579:
580: public boolean execute(byte key, double val) {
581: try {
582: stream.writeByte(key);
583: stream.writeDouble(val);
584: } catch (IOException e) {
585: this .exception = e;
586: return false;
587: }
588: return true;
589: }
590:
591: public boolean execute(byte key, float val) {
592: try {
593: stream.writeByte(key);
594: stream.writeFloat(val);
595: } catch (IOException e) {
596: this .exception = e;
597: return false;
598: }
599: return true;
600: }
601:
602: public boolean execute(short key, Object val) {
603: try {
604: stream.writeShort(key);
605: stream.writeObject(val);
606: } catch (IOException e) {
607: this .exception = e;
608: return false;
609: }
610: return true;
611: }
612:
613: public boolean execute(short key, byte val) {
614: try {
615: stream.writeShort(key);
616: stream.writeByte(val);
617: } catch (IOException e) {
618: this .exception = e;
619: return false;
620: }
621: return true;
622: }
623:
624: public boolean execute(short key, short val) {
625: try {
626: stream.writeShort(key);
627: stream.writeShort(val);
628: } catch (IOException e) {
629: this .exception = e;
630: return false;
631: }
632: return true;
633: }
634:
635: public boolean execute(short key, int val) {
636: try {
637: stream.writeShort(key);
638: stream.writeInt(val);
639: } catch (IOException e) {
640: this .exception = e;
641: return false;
642: }
643: return true;
644: }
645:
646: public boolean execute(short key, long val) {
647: try {
648: stream.writeShort(key);
649: stream.writeLong(val);
650: } catch (IOException e) {
651: this .exception = e;
652: return false;
653: }
654: return true;
655: }
656:
657: public boolean execute(short key, double val) {
658: try {
659: stream.writeShort(key);
660: stream.writeDouble(val);
661: } catch (IOException e) {
662: this .exception = e;
663: return false;
664: }
665: return true;
666: }
667:
668: public boolean execute(short key, float val) {
669: try {
670: stream.writeShort(key);
671: stream.writeFloat(val);
672: } catch (IOException e) {
673: this .exception = e;
674: return false;
675: }
676: return true;
677: }
678: }// SerializationProcedure
|