1 /*
2 * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
511 copy[i] = uc[i];
512 }
513 return copy;
514 }
515
516 /*
517 * Utility method to copy long[] updateCount to int[] updateCount.
518 * No checks for overflow will be done as it is expected a user will call
519 * getLargeUpdateCounts.
520 */
521 private static int[] copyUpdateCount(long[] uc) {
522 int[] copy = new int[uc.length];
523 for(int i= 0; i< uc.length; i++) {
524 copy[i] = (int) uc[i];
525 }
526 return copy;
527 }
528 /**
529 * readObject is called to restore the state of the
530 * {@code BatchUpdateException} from a stream.
531 */
532 private void readObject(ObjectInputStream s)
533 throws IOException, ClassNotFoundException {
534
535 ObjectInputStream.GetField fields = s.readFields();
536 int[] tmp = (int[])fields.get("updateCounts", null);
537 long[] tmp2 = (long[])fields.get("longUpdateCounts", null);
538 if(tmp != null && tmp2 != null && tmp.length != tmp2.length)
539 throw new InvalidObjectException("update counts are not the expected size");
540 if (tmp != null)
541 updateCounts = tmp.clone();
542 if (tmp2 != null)
543 longUpdateCounts = tmp2.clone();
544 if(updateCounts == null && longUpdateCounts != null)
545 updateCounts = copyUpdateCount(longUpdateCounts);
546 if(longUpdateCounts == null && updateCounts != null)
547 longUpdateCounts = copyUpdateCount(updateCounts);
548
549 }
550
551 /**
552 * writeObject is called to save the state of the {@code BatchUpdateException}
553 * to a stream.
554 */
555 private void writeObject(ObjectOutputStream s)
556 throws IOException {
557
558 ObjectOutputStream.PutField fields = s.putFields();
559 fields.put("updateCounts", updateCounts);
560 fields.put("longUpdateCounts", longUpdateCounts);
561 s.writeFields();
562 }
563 }
|
1 /*
2 * Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
511 copy[i] = uc[i];
512 }
513 return copy;
514 }
515
516 /*
517 * Utility method to copy long[] updateCount to int[] updateCount.
518 * No checks for overflow will be done as it is expected a user will call
519 * getLargeUpdateCounts.
520 */
521 private static int[] copyUpdateCount(long[] uc) {
522 int[] copy = new int[uc.length];
523 for(int i= 0; i< uc.length; i++) {
524 copy[i] = (int) uc[i];
525 }
526 return copy;
527 }
528 /**
529 * readObject is called to restore the state of the
530 * {@code BatchUpdateException} from a stream.
531 * @param s the {@code ObjectInputStream} to read from.
532 *
533 * @throws ClassNotFoundException if the class of a serialized object
534 * could not be found.
535 * @throws IOException if an I/O error occurs.
536 */
537 private void readObject(ObjectInputStream s)
538 throws IOException, ClassNotFoundException {
539
540 ObjectInputStream.GetField fields = s.readFields();
541 int[] tmp = (int[])fields.get("updateCounts", null);
542 long[] tmp2 = (long[])fields.get("longUpdateCounts", null);
543 if(tmp != null && tmp2 != null && tmp.length != tmp2.length)
544 throw new InvalidObjectException("update counts are not the expected size");
545 if (tmp != null)
546 updateCounts = tmp.clone();
547 if (tmp2 != null)
548 longUpdateCounts = tmp2.clone();
549 if(updateCounts == null && longUpdateCounts != null)
550 updateCounts = copyUpdateCount(longUpdateCounts);
551 if(longUpdateCounts == null && updateCounts != null)
552 longUpdateCounts = copyUpdateCount(updateCounts);
553
554 }
555
556 /**
557 * writeObject is called to save the state of the {@code BatchUpdateException}
558 * to a stream.
559 * @param s the {@code ObjectOutputStream} to write to.
560 + @throws IOException if I/O errors occur.
561 */
562 private void writeObject(ObjectOutputStream s)
563 throws IOException {
564
565 ObjectOutputStream.PutField fields = s.putFields();
566 fields.put("updateCounts", updateCounts);
567 fields.put("longUpdateCounts", longUpdateCounts);
568 s.writeFields();
569 }
570 }
|