1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002, 2013 Oracle and/or its affiliates.  All rights reserved.
5  *
6  */
7 
8 package com.sleepycat.persist.impl;
9 
10 import java.lang.reflect.Field;
11 import java.math.BigDecimal;
12 import java.math.BigInteger;
13 import java.util.Date;
14 import java.util.Map;
15 import java.util.Set;
16 
17 import com.sleepycat.compat.DbCompat;
18 import com.sleepycat.db.DatabaseEntry;
19 import com.sleepycat.persist.model.EntityModel;
20 
21 /**
22  * Format for simple types, including primitives.  Additional methods are
23  * included to optimize the handling of primitives.  Other classes such as
24  * PrimitiveArrayFormat and ReflectAccessor take advantage of these methods.
25  *
26  * @author Mark Hayes
27  */
28 public abstract class SimpleFormat extends Format {
29 
30     private static final long serialVersionUID = 4595245575868697702L;
31 
32     private final boolean primitive;
33     private SimpleFormat wrapperFormat;
34 
SimpleFormat(Catalog catalog, Class type, boolean primitive)35     SimpleFormat(Catalog catalog, Class type, boolean primitive) {
36         super(catalog, type);
37         this.primitive = primitive;
38     }
39 
setWrapperFormat(SimpleFormat wrapperFormat)40     void setWrapperFormat(SimpleFormat wrapperFormat) {
41         this.wrapperFormat = wrapperFormat;
42     }
43 
44     @Override
getWrapperFormat()45     Format getWrapperFormat() {
46         return wrapperFormat;
47     }
48 
49     @Override
isSimple()50     public boolean isSimple() {
51         return true;
52     }
53 
54     @Override
isPrimitive()55     public boolean isPrimitive() {
56         return primitive;
57     }
58 
59     @Override
collectRelatedFormats(Catalog catalog, Map<String, Format> newFormats)60     void collectRelatedFormats(Catalog catalog,
61                                Map<String, Format> newFormats) {
62     }
63 
64     @Override
initialize(Catalog catalog, EntityModel model, int initVersion)65     void initialize(Catalog catalog, EntityModel model, int initVersion) {
66     }
67 
68     @Override
readObject(Object o, EntityInput input, boolean rawAccess)69     public Object readObject(Object o, EntityInput input, boolean rawAccess) {
70         /* newInstance reads the value -- do nothing here. */
71         return o;
72     }
73 
74     @Override
evolve(Format newFormat, Evolver evolver)75     boolean evolve(Format newFormat, Evolver evolver) {
76         evolver.useOldFormat(this, newFormat);
77         return true;
78     }
79 
80     /* -- Begin methods to be overridden by primitive formats only. -- */
81 
newPrimitiveArray(int len, EntityInput input)82     Object newPrimitiveArray(int len, EntityInput input)
83         throws RefreshException {
84 
85         throw DbCompat.unexpectedState();
86     }
87 
writePrimitiveArray(Object o, EntityOutput output)88     void writePrimitiveArray(Object o, EntityOutput output) {
89         throw DbCompat.unexpectedState();
90     }
91 
getPrimitiveLength()92     int getPrimitiveLength() {
93         throw DbCompat.unexpectedState();
94     }
95 
96     /**
97      * @throws IllegalAccessException from subclasses.
98      */
readPrimitiveField(Object o, EntityInput input, Field field)99     void readPrimitiveField(Object o, EntityInput input, Field field)
100         throws IllegalAccessException, RefreshException {
101 
102         throw DbCompat.unexpectedState();
103     }
104 
105     /**
106      * @throws IllegalAccessException from subclasses.
107      */
writePrimitiveField(Object o, EntityOutput output, Field field)108     void writePrimitiveField(Object o, EntityOutput output, Field field)
109         throws IllegalAccessException {
110 
111         throw DbCompat.unexpectedState();
112     }
113 
114     /* -- End methods to be overridden by primitive formats only. -- */
115 
skipPrimitiveArray(int len, RecordInput input)116     void skipPrimitiveArray(int len, RecordInput input) {
117         input.skipFast(len * getPrimitiveLength());
118     }
119 
copySecMultiKeyPrimitiveArray(int len, RecordInput input, Set results)120     void copySecMultiKeyPrimitiveArray(int len,
121                                        RecordInput input,
122                                        Set results) {
123         int primLen = getPrimitiveLength();
124         for (int i = 0; i < len; i += 1) {
125             DatabaseEntry entry = new DatabaseEntry
126                 (input.getBufferBytes(), input.getBufferOffset(), primLen);
127             results.add(entry);
128             input.skipFast(primLen);
129         }
130     }
131 
132     public static class FBool extends SimpleFormat {
133 
134         private static final long serialVersionUID = -7724949525068533451L;
135 
FBool(Catalog catalog, boolean primitive)136         FBool(Catalog catalog, boolean primitive) {
137             super(catalog, primitive ? Boolean.TYPE : Boolean.class,
138                   primitive);
139         }
140 
141         @Override
newArray(int len)142         Object newArray(int len) {
143             return new Boolean[len];
144         }
145 
146         @Override
newInstance(EntityInput input, boolean rawAccess)147         public Object newInstance(EntityInput input, boolean rawAccess)
148             throws RefreshException {
149 
150             return Boolean.valueOf(input.readBoolean());
151         }
152 
153         @Override
writeObject(Object o, EntityOutput output, boolean rawAccess)154         void writeObject(Object o, EntityOutput output, boolean rawAccess) {
155             output.writeBoolean(((Boolean) o).booleanValue());
156         }
157 
158         @Override
skipContents(RecordInput input)159         void skipContents(RecordInput input) {
160             input.skipFast(1);
161         }
162 
163         @Override
copySecKey(RecordInput input, RecordOutput output)164         void copySecKey(RecordInput input, RecordOutput output) {
165             output.writeFast(input.readFast());
166         }
167 
168         @Override
newPrimitiveArray(int len, EntityInput input)169         Object newPrimitiveArray(int len, EntityInput input)
170             throws RefreshException {
171 
172             boolean[] a = new boolean[len];
173             for (int i = 0; i < len; i += 1) {
174                 a[i] = input.readBoolean();
175             }
176             return a;
177         }
178 
179         @Override
writePrimitiveArray(Object o, EntityOutput output)180         void writePrimitiveArray(Object o, EntityOutput output) {
181             boolean[] a = (boolean[]) o;
182             int len = a.length;
183             output.writeArrayLength(len);
184             for (int i = 0; i < len; i += 1) {
185                 output.writeBoolean(a[i]);
186             }
187         }
188 
189         @Override
getPrimitiveLength()190         int getPrimitiveLength() {
191             return 1;
192         }
193 
194         @Override
readPrimitiveField(Object o, EntityInput input, Field field)195         void readPrimitiveField(Object o, EntityInput input, Field field)
196             throws IllegalAccessException, RefreshException {
197 
198             field.setBoolean(o, input.readBoolean());
199         }
200 
201         @Override
writePrimitiveField(Object o, EntityOutput output, Field field)202         void writePrimitiveField(Object o, EntityOutput output, Field field)
203             throws IllegalAccessException {
204 
205             output.writeBoolean(field.getBoolean(o));
206         }
207     }
208 
209     public static class FByte extends SimpleFormat {
210 
211         private static final long serialVersionUID = 3651752958101447257L;
212 
FByte(Catalog catalog, boolean primitive)213         FByte(Catalog catalog, boolean primitive) {
214             super(catalog, primitive ? Byte.TYPE : Byte.class, primitive);
215         }
216 
217         @Override
newArray(int len)218         Object newArray(int len) {
219             return new Byte[len];
220         }
221 
222         @Override
newInstance(EntityInput input, boolean rawAccess)223         public Object newInstance(EntityInput input, boolean rawAccess)
224             throws RefreshException {
225 
226             return Byte.valueOf(input.readByte());
227         }
228 
229         @Override
writeObject(Object o, EntityOutput output, boolean rawAccess)230         void writeObject(Object o, EntityOutput output, boolean rawAccess) {
231             output.writeByte(((Number) o).byteValue());
232         }
233 
234         @Override
skipContents(RecordInput input)235         void skipContents(RecordInput input) {
236             input.skipFast(1);
237         }
238 
239         @Override
copySecKey(RecordInput input, RecordOutput output)240         void copySecKey(RecordInput input, RecordOutput output) {
241             output.writeFast(input.readFast());
242         }
243 
244         @Override
newPrimitiveArray(int len, EntityInput input)245         Object newPrimitiveArray(int len, EntityInput input)
246             throws RefreshException {
247 
248             byte[] a = new byte[len];
249             for (int i = 0; i < len; i += 1) {
250                 a[i] = input.readByte();
251             }
252             return a;
253         }
254 
255         @Override
writePrimitiveArray(Object o, EntityOutput output)256         void writePrimitiveArray(Object o, EntityOutput output) {
257             byte[] a = (byte[]) o;
258             int len = a.length;
259             output.writeArrayLength(len);
260             for (int i = 0; i < len; i += 1) {
261                 output.writeByte(a[i]);
262             }
263         }
264 
265         @Override
getPrimitiveLength()266         int getPrimitiveLength() {
267             return 1;
268         }
269 
270         @Override
readPrimitiveField(Object o, EntityInput input, Field field)271         void readPrimitiveField(Object o, EntityInput input, Field field)
272             throws IllegalAccessException, RefreshException {
273 
274             field.setByte(o, input.readByte());
275         }
276 
277         @Override
writePrimitiveField(Object o, EntityOutput output, Field field)278         void writePrimitiveField(Object o, EntityOutput output, Field field)
279             throws IllegalAccessException {
280 
281             output.writeByte(field.getByte(o));
282         }
283 
284         @Override
getSequenceKeyFormat()285         Format getSequenceKeyFormat() {
286             return this;
287         }
288     }
289 
290     public static class FShort extends SimpleFormat {
291 
292         private static final long serialVersionUID = -4909138198491785624L;
293 
FShort(Catalog catalog, boolean primitive)294         FShort(Catalog catalog, boolean primitive) {
295             super(catalog, primitive ? Short.TYPE : Short.class, primitive);
296         }
297 
298         @Override
newArray(int len)299         Object newArray(int len) {
300             return new Short[len];
301         }
302 
303         @Override
newInstance(EntityInput input, boolean rawAccess)304         public Object newInstance(EntityInput input, boolean rawAccess)
305             throws RefreshException {
306 
307             return Short.valueOf(input.readShort());
308         }
309 
310         @Override
writeObject(Object o, EntityOutput output, boolean rawAccess)311         void writeObject(Object o, EntityOutput output, boolean rawAccess) {
312             output.writeShort(((Number) o).shortValue());
313         }
314 
315         @Override
skipContents(RecordInput input)316         void skipContents(RecordInput input) {
317             input.skipFast(2);
318         }
319 
320         @Override
copySecKey(RecordInput input, RecordOutput output)321         void copySecKey(RecordInput input, RecordOutput output) {
322             output.writeFast(input.readFast());
323             output.writeFast(input.readFast());
324         }
325 
326         @Override
newPrimitiveArray(int len, EntityInput input)327         Object newPrimitiveArray(int len, EntityInput input)
328             throws RefreshException {
329 
330             short[] a = new short[len];
331             for (int i = 0; i < len; i += 1) {
332                 a[i] = input.readShort();
333             }
334             return a;
335         }
336 
337         @Override
writePrimitiveArray(Object o, EntityOutput output)338         void writePrimitiveArray(Object o, EntityOutput output) {
339             short[] a = (short[]) o;
340             int len = a.length;
341             output.writeArrayLength(len);
342             for (int i = 0; i < len; i += 1) {
343                 output.writeShort(a[i]);
344             }
345         }
346 
347         @Override
getPrimitiveLength()348         int getPrimitiveLength() {
349             return 2;
350         }
351 
352         @Override
readPrimitiveField(Object o, EntityInput input, Field field)353         void readPrimitiveField(Object o, EntityInput input, Field field)
354             throws IllegalAccessException, RefreshException {
355 
356             field.setShort(o, input.readShort());
357         }
358 
359         @Override
writePrimitiveField(Object o, EntityOutput output, Field field)360         void writePrimitiveField(Object o, EntityOutput output, Field field)
361             throws IllegalAccessException {
362 
363             output.writeShort(field.getShort(o));
364         }
365 
366         @Override
getSequenceKeyFormat()367         Format getSequenceKeyFormat() {
368             return this;
369         }
370     }
371 
372     public static class FInt extends SimpleFormat {
373 
374         private static final long serialVersionUID = 2695910006049980013L;
375 
FInt(Catalog catalog, boolean primitive)376         FInt(Catalog catalog, boolean primitive) {
377             super(catalog, primitive ? Integer.TYPE : Integer.class,
378                   primitive);
379         }
380 
381         @Override
newArray(int len)382         Object newArray(int len) {
383             return new Integer[len];
384         }
385 
386         @Override
newInstance(EntityInput input, boolean rawAccess)387         public Object newInstance(EntityInput input, boolean rawAccess)
388             throws RefreshException {
389 
390             return Integer.valueOf(input.readInt());
391         }
392 
393         @Override
writeObject(Object o, EntityOutput output, boolean rawAccess)394         void writeObject(Object o, EntityOutput output, boolean rawAccess) {
395             output.writeInt(((Number) o).intValue());
396         }
397 
398         @Override
skipContents(RecordInput input)399         void skipContents(RecordInput input) {
400             input.skipFast(4);
401         }
402 
403         @Override
copySecKey(RecordInput input, RecordOutput output)404         void copySecKey(RecordInput input, RecordOutput output) {
405             output.writeFast(input.readFast());
406             output.writeFast(input.readFast());
407             output.writeFast(input.readFast());
408             output.writeFast(input.readFast());
409         }
410 
411         @Override
newPrimitiveArray(int len, EntityInput input)412         Object newPrimitiveArray(int len, EntityInput input)
413             throws RefreshException {
414 
415             int[] a = new int[len];
416             for (int i = 0; i < len; i += 1) {
417                 a[i] = input.readInt();
418             }
419             return a;
420         }
421 
422         @Override
writePrimitiveArray(Object o, EntityOutput output)423         void writePrimitiveArray(Object o, EntityOutput output) {
424             int[] a = (int[]) o;
425             int len = a.length;
426             output.writeArrayLength(len);
427             for (int i = 0; i < len; i += 1) {
428                 output.writeInt(a[i]);
429             }
430         }
431 
432         @Override
getPrimitiveLength()433         int getPrimitiveLength() {
434             return 4;
435         }
436 
437         @Override
readPrimitiveField(Object o, EntityInput input, Field field)438         void readPrimitiveField(Object o, EntityInput input, Field field)
439             throws IllegalAccessException, RefreshException {
440 
441             field.setInt(o, input.readInt());
442         }
443 
444         @Override
writePrimitiveField(Object o, EntityOutput output, Field field)445         void writePrimitiveField(Object o, EntityOutput output, Field field)
446             throws IllegalAccessException {
447 
448             output.writeInt(field.getInt(o));
449         }
450 
451         @Override
getSequenceKeyFormat()452         Format getSequenceKeyFormat() {
453             return this;
454         }
455     }
456 
457     public static class FLong extends SimpleFormat {
458 
459         private static final long serialVersionUID = 1872661106534776520L;
460 
FLong(Catalog catalog, boolean primitive)461         FLong(Catalog catalog, boolean primitive) {
462             super(catalog, primitive ? Long.TYPE : Long.class, primitive);
463         }
464 
465         @Override
newArray(int len)466         Object newArray(int len) {
467             return new Long[len];
468         }
469 
470         @Override
newInstance(EntityInput input, boolean rawAccess)471         public Object newInstance(EntityInput input, boolean rawAccess)
472             throws RefreshException {
473 
474             return Long.valueOf(input.readLong());
475         }
476 
477         @Override
writeObject(Object o, EntityOutput output, boolean rawAccess)478         void writeObject(Object o, EntityOutput output, boolean rawAccess) {
479             output.writeLong(((Number) o).longValue());
480         }
481 
482         @Override
skipContents(RecordInput input)483         void skipContents(RecordInput input) {
484             input.skipFast(8);
485         }
486 
487         @Override
copySecKey(RecordInput input, RecordOutput output)488         void copySecKey(RecordInput input, RecordOutput output) {
489             output.writeFast
490                 (input.getBufferBytes(), input.getBufferOffset(), 8);
491             input.skipFast(8);
492         }
493 
494         @Override
newPrimitiveArray(int len, EntityInput input)495         Object newPrimitiveArray(int len, EntityInput input)
496             throws RefreshException {
497 
498             long[] a = new long[len];
499             for (int i = 0; i < len; i += 1) {
500                 a[i] = input.readLong();
501             }
502             return a;
503         }
504 
505         @Override
writePrimitiveArray(Object o, EntityOutput output)506         void writePrimitiveArray(Object o, EntityOutput output) {
507             long[] a = (long[]) o;
508             int len = a.length;
509             output.writeArrayLength(len);
510             for (int i = 0; i < len; i += 1) {
511                 output.writeLong(a[i]);
512             }
513         }
514 
515         @Override
getPrimitiveLength()516         int getPrimitiveLength() {
517             return 8;
518         }
519 
520         @Override
readPrimitiveField(Object o, EntityInput input, Field field)521         void readPrimitiveField(Object o, EntityInput input, Field field)
522             throws IllegalAccessException, RefreshException {
523 
524             field.setLong(o, input.readLong());
525         }
526 
527         @Override
writePrimitiveField(Object o, EntityOutput output, Field field)528         void writePrimitiveField(Object o, EntityOutput output, Field field)
529             throws IllegalAccessException {
530 
531             output.writeLong(field.getLong(o));
532         }
533 
534         @Override
getSequenceKeyFormat()535         Format getSequenceKeyFormat() {
536             return this;
537         }
538     }
539 
540     public static class FFloat extends SimpleFormat {
541 
542         private static final long serialVersionUID = 1033413049495053602L;
543 
FFloat(Catalog catalog, boolean primitive)544         FFloat(Catalog catalog, boolean primitive) {
545             super(catalog, primitive ? Float.TYPE : Float.class, primitive);
546         }
547 
548         @Override
newArray(int len)549         Object newArray(int len) {
550             return new Float[len];
551         }
552 
553         @Override
newInstance(EntityInput input, boolean rawAccess)554         public Object newInstance(EntityInput input, boolean rawAccess)
555             throws RefreshException {
556 
557             return Float.valueOf(input.readSortedFloat());
558         }
559 
560         @Override
writeObject(Object o, EntityOutput output, boolean rawAccess)561         void writeObject(Object o, EntityOutput output, boolean rawAccess) {
562             output.writeSortedFloat(((Number) o).floatValue());
563         }
564 
565         @Override
skipContents(RecordInput input)566         void skipContents(RecordInput input) {
567             input.skipFast(4);
568         }
569 
570         @Override
copySecKey(RecordInput input, RecordOutput output)571         void copySecKey(RecordInput input, RecordOutput output) {
572             output.writeFast(input.readFast());
573             output.writeFast(input.readFast());
574             output.writeFast(input.readFast());
575             output.writeFast(input.readFast());
576         }
577 
578         @Override
newPrimitiveArray(int len, EntityInput input)579         Object newPrimitiveArray(int len, EntityInput input)
580             throws RefreshException {
581 
582             float[] a = new float[len];
583             for (int i = 0; i < len; i += 1) {
584                 a[i] = input.readSortedFloat();
585             }
586             return a;
587         }
588 
589         @Override
writePrimitiveArray(Object o, EntityOutput output)590         void writePrimitiveArray(Object o, EntityOutput output) {
591             float[] a = (float[]) o;
592             int len = a.length;
593             output.writeArrayLength(len);
594             for (int i = 0; i < len; i += 1) {
595                 output.writeSortedFloat(a[i]);
596             }
597         }
598 
599         @Override
getPrimitiveLength()600         int getPrimitiveLength() {
601             return 4;
602         }
603 
604         @Override
readPrimitiveField(Object o, EntityInput input, Field field)605         void readPrimitiveField(Object o, EntityInput input, Field field)
606             throws IllegalAccessException, RefreshException {
607 
608             field.setFloat(o, input.readSortedFloat());
609         }
610 
611         @Override
writePrimitiveField(Object o, EntityOutput output, Field field)612         void writePrimitiveField(Object o, EntityOutput output, Field field)
613             throws IllegalAccessException {
614 
615             output.writeSortedFloat(field.getFloat(o));
616         }
617     }
618 
619     public static class FDouble extends SimpleFormat {
620 
621         private static final long serialVersionUID = 646904456811041423L;
622 
FDouble(Catalog catalog, boolean primitive)623         FDouble(Catalog catalog, boolean primitive) {
624             super(catalog, primitive ? Double.TYPE : Double.class, primitive);
625         }
626 
627         @Override
newArray(int len)628         Object newArray(int len) {
629             return new Double[len];
630         }
631 
632         @Override
newInstance(EntityInput input, boolean rawAccess)633         public Object newInstance(EntityInput input, boolean rawAccess)
634             throws RefreshException {
635 
636             return Double.valueOf(input.readSortedDouble());
637         }
638 
639         @Override
writeObject(Object o, EntityOutput output, boolean rawAccess)640         void writeObject(Object o, EntityOutput output, boolean rawAccess) {
641             output.writeSortedDouble(((Number) o).doubleValue());
642         }
643 
644         @Override
skipContents(RecordInput input)645         void skipContents(RecordInput input) {
646             input.skipFast(8);
647         }
648 
649         @Override
copySecKey(RecordInput input, RecordOutput output)650         void copySecKey(RecordInput input, RecordOutput output) {
651             output.writeFast
652                 (input.getBufferBytes(), input.getBufferOffset(), 8);
653             input.skipFast(8);
654         }
655 
656         @Override
newPrimitiveArray(int len, EntityInput input)657         Object newPrimitiveArray(int len, EntityInput input)
658             throws RefreshException {
659 
660             double[] a = new double[len];
661             for (int i = 0; i < len; i += 1) {
662                 a[i] = input.readSortedDouble();
663             }
664             return a;
665         }
666 
667         @Override
writePrimitiveArray(Object o, EntityOutput output)668         void writePrimitiveArray(Object o, EntityOutput output) {
669             double[] a = (double[]) o;
670             int len = a.length;
671             output.writeArrayLength(len);
672             for (int i = 0; i < len; i += 1) {
673                 output.writeSortedDouble(a[i]);
674             }
675         }
676 
677         @Override
getPrimitiveLength()678         int getPrimitiveLength() {
679             return 8;
680         }
681 
682         @Override
readPrimitiveField(Object o, EntityInput input, Field field)683         void readPrimitiveField(Object o, EntityInput input, Field field)
684             throws IllegalAccessException, RefreshException {
685 
686             field.setDouble(o, input.readSortedDouble());
687         }
688 
689         @Override
writePrimitiveField(Object o, EntityOutput output, Field field)690         void writePrimitiveField(Object o, EntityOutput output, Field field)
691             throws IllegalAccessException {
692 
693             output.writeSortedDouble(field.getDouble(o));
694         }
695     }
696 
697     public static class FChar extends SimpleFormat {
698 
699         private static final long serialVersionUID = -7609118195770005374L;
700 
FChar(Catalog catalog, boolean primitive)701         FChar(Catalog catalog, boolean primitive) {
702             super(catalog, primitive ? Character.TYPE : Character.class,
703                   primitive);
704         }
705 
706         @Override
newArray(int len)707         Object newArray(int len) {
708             return new Character[len];
709         }
710 
711         @Override
newInstance(EntityInput input, boolean rawAccess)712         public Object newInstance(EntityInput input, boolean rawAccess)
713             throws RefreshException {
714 
715             return Character.valueOf(input.readChar());
716         }
717 
718         @Override
writeObject(Object o, EntityOutput output, boolean rawAccess)719         void writeObject(Object o, EntityOutput output, boolean rawAccess) {
720             output.writeChar(((Character) o).charValue());
721         }
722 
723         @Override
skipContents(RecordInput input)724         void skipContents(RecordInput input) {
725             input.skipFast(2);
726         }
727 
728         @Override
copySecKey(RecordInput input, RecordOutput output)729         void copySecKey(RecordInput input, RecordOutput output) {
730             output.writeFast(input.readFast());
731             output.writeFast(input.readFast());
732         }
733 
734         @Override
newPrimitiveArray(int len, EntityInput input)735         Object newPrimitiveArray(int len, EntityInput input)
736             throws RefreshException {
737 
738             char[] a = new char[len];
739             for (int i = 0; i < len; i += 1) {
740                 a[i] = input.readChar();
741             }
742             return a;
743         }
744 
745         @Override
writePrimitiveArray(Object o, EntityOutput output)746         void writePrimitiveArray(Object o, EntityOutput output) {
747             char[] a = (char[]) o;
748             int len = a.length;
749             output.writeArrayLength(len);
750             for (int i = 0; i < len; i += 1) {
751                 output.writeChar(a[i]);
752             }
753         }
754 
755         @Override
getPrimitiveLength()756         int getPrimitiveLength() {
757             return 2;
758         }
759 
760         @Override
readPrimitiveField(Object o, EntityInput input, Field field)761         void readPrimitiveField(Object o, EntityInput input, Field field)
762             throws IllegalAccessException, RefreshException {
763 
764             field.setChar(o, input.readChar());
765         }
766 
767         @Override
writePrimitiveField(Object o, EntityOutput output, Field field)768         void writePrimitiveField(Object o, EntityOutput output, Field field)
769             throws IllegalAccessException {
770 
771             output.writeChar(field.getChar(o));
772         }
773     }
774 
775     public static class FString extends SimpleFormat {
776 
777         private static final long serialVersionUID = 5710392786480064612L;
778 
FString(Catalog catalog)779         FString(Catalog catalog) {
780             super(catalog, String.class, false);
781         }
782 
783         @Override
newArray(int len)784         Object newArray(int len) {
785             return new String[len];
786         }
787 
788         @Override
newInstance(EntityInput input, boolean rawAccess)789         public Object newInstance(EntityInput input, boolean rawAccess)
790             throws RefreshException {
791 
792             return input.readString();
793         }
794 
795         @Override
writeObject(Object o, EntityOutput output, boolean rawAccess)796         void writeObject(Object o, EntityOutput output, boolean rawAccess) {
797             output.writeString((String) o);
798         }
799 
800         @Override
skipContents(RecordInput input)801         void skipContents(RecordInput input) {
802             input.skipFast(input.getStringByteLength());
803         }
804 
805         @Override
copySecKey(RecordInput input, RecordOutput output)806         void copySecKey(RecordInput input, RecordOutput output) {
807             int len = input.getStringByteLength();
808             output.writeFast
809                 (input.getBufferBytes(), input.getBufferOffset(), len);
810             input.skipFast(len);
811         }
812     }
813 
814     public static class FBigInt extends SimpleFormat {
815 
816         private static final long serialVersionUID = -5027098112507644563L;
817 
FBigInt(Catalog catalog)818         FBigInt(Catalog catalog) {
819             super(catalog, BigInteger.class, false);
820         }
821 
822         @Override
newArray(int len)823         Object newArray(int len) {
824             return new BigInteger[len];
825         }
826 
827         @Override
newInstance(EntityInput input, boolean rawAccess)828         public Object newInstance(EntityInput input, boolean rawAccess)
829             throws RefreshException {
830 
831             return input.readBigInteger();
832         }
833 
834         @Override
writeObject(Object o, EntityOutput output, boolean rawAccess)835         void writeObject(Object o, EntityOutput output, boolean rawAccess) {
836             output.writeBigInteger((BigInteger) o);
837         }
838 
839         @Override
skipContents(RecordInput input)840         void skipContents(RecordInput input) {
841             input.skipFast(input.getBigIntegerByteLength());
842         }
843 
844         @Override
copySecKey(RecordInput input, RecordOutput output)845         void copySecKey(RecordInput input, RecordOutput output) {
846             int len = input.getBigIntegerByteLength();
847             output.writeFast
848                 (input.getBufferBytes(), input.getBufferOffset(), len);
849             input.skipFast(len);
850         }
851     }
852 
853     public static class FBigDec extends SimpleFormat {
854         private static final long serialVersionUID = 6108874887143696463L;
855 
FBigDec(Catalog catalog)856         FBigDec(Catalog catalog) {
857             super(catalog, BigDecimal.class, false);
858         }
859 
860         @Override
newArray(int len)861         Object newArray(int len) {
862             return new BigDecimal[len];
863         }
864 
865         @Override
newInstance(EntityInput input, boolean rawAccess)866         public Object newInstance(EntityInput input, boolean rawAccess)
867             throws RefreshException {
868 
869             return input.readSortedBigDecimal();
870         }
871 
872         @Override
writeObject(Object o, EntityOutput output, boolean rawAccess)873         void writeObject(Object o, EntityOutput output, boolean rawAccess) {
874             output.writeSortedBigDecimal((BigDecimal) o);
875         }
876 
877         @Override
skipContents(RecordInput input)878         void skipContents(RecordInput input) {
879             input.skipFast(input.getSortedBigDecimalByteLength());
880         }
881 
882         @Override
copySecKey(RecordInput input, RecordOutput output)883         void copySecKey(RecordInput input, RecordOutput output) {
884             int len = input.getSortedBigDecimalByteLength();
885             output.writeFast
886                 (input.getBufferBytes(), input.getBufferOffset(), len);
887             input.skipFast(len);
888         }
889 
890         @Override
allowEvolveFromProxy()891         public boolean allowEvolveFromProxy() {
892             return true;
893         }
894     }
895 
896     public static class FDate extends SimpleFormat {
897 
898         private static final long serialVersionUID = -5665773229869034145L;
899 
FDate(Catalog catalog)900         FDate(Catalog catalog) {
901             super(catalog, Date.class, false);
902         }
903 
904         @Override
newArray(int len)905         Object newArray(int len) {
906             return new Date[len];
907         }
908 
909         @Override
newInstance(EntityInput input, boolean rawAccess)910         public Object newInstance(EntityInput input, boolean rawAccess)
911             throws RefreshException {
912 
913             return new Date(input.readLong());
914         }
915 
916         @Override
writeObject(Object o, EntityOutput output, boolean rawAccess)917         void writeObject(Object o, EntityOutput output, boolean rawAccess) {
918             output.writeLong(((Date) o).getTime());
919         }
920 
921         @Override
skipContents(RecordInput input)922         void skipContents(RecordInput input) {
923             input.skipFast(8);
924         }
925 
926         @Override
copySecKey(RecordInput input, RecordOutput output)927         void copySecKey(RecordInput input, RecordOutput output) {
928             output.writeFast
929                 (input.getBufferBytes(), input.getBufferOffset(), 8);
930             input.skipFast(8);
931         }
932     }
933 }
934