625 public static void serialize() throws Exception { 626 int failCount = 0; 627 628 String bitPatterns[] = { 629 "ffffffff00000000ffffffff00000000ffffffff00000000", 630 "ffffffffffffffffffffffff000000000000000000000000", 631 "ffffffff0000000000000000000000000000000000000000", 632 "10000000ffffffffffffffffffffffffffffffffffffffff", 633 "100000000000000000000000000000000000000000000000", 634 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 635 "-ffffffff00000000ffffffff00000000ffffffff00000000", 636 "-ffffffffffffffffffffffff000000000000000000000000", 637 "-ffffffff0000000000000000000000000000000000000000", 638 "-10000000ffffffffffffffffffffffffffffffffffffffff", 639 "-100000000000000000000000000000000000000000000000", 640 "-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 641 }; 642 643 for(int i = 0; i < bitPatterns.length; i++) { 644 BigInteger b1 = new BigInteger(bitPatterns[i], 16); 645 646 File f = new File("serialtest"); 647 FileOutputStream fos = new FileOutputStream(f); 648 ObjectOutputStream oos = new ObjectOutputStream(fos); 649 oos.writeObject(b1); 650 oos.flush(); 651 oos.close(); 652 FileInputStream fis = new FileInputStream(f); 653 ObjectInputStream ois = new ObjectInputStream(fis); 654 BigInteger b2 = (BigInteger)ois.readObject(); 655 656 if (!b1.equals(b2) || 657 !b1.equals(b1.or(b2))) { 658 failCount++; 659 System.err.println("Serialized failed for hex " + 660 b1.toString(16)); 661 } 662 f.delete(); 663 } 664 665 for(int i=0; i<10; i++) { 666 BigInteger b1 = fetchNumber(rnd.nextInt(100)); 667 File f = new File("serialtest"); 668 FileOutputStream fos = new FileOutputStream(f); 669 ObjectOutputStream oos = new ObjectOutputStream(fos); 670 oos.writeObject(b1); 671 oos.flush(); 672 oos.close(); 673 FileInputStream fis = new FileInputStream(f); 674 ObjectInputStream ois = new ObjectInputStream(fis); 675 BigInteger b2 = (BigInteger)ois.readObject(); 676 677 if (!b1.equals(b2) || 678 !b1.equals(b1.or(b2))) 679 failCount++; 680 f.delete(); 681 } 682 683 report("Serialize", failCount); 684 } 685 686 /** 687 * Main to interpret arguments and run several tests. 688 * 689 * Up to three arguments may be given to specify the size of BigIntegers 690 * used for call parameters 1, 2, and 3. The size is interpreted as 691 * the maximum number of decimal digits that the parameters will have. 692 * 693 */ 694 public static void main(String[] args) throws Exception { 695 | 625 public static void serialize() throws Exception { 626 int failCount = 0; 627 628 String bitPatterns[] = { 629 "ffffffff00000000ffffffff00000000ffffffff00000000", 630 "ffffffffffffffffffffffff000000000000000000000000", 631 "ffffffff0000000000000000000000000000000000000000", 632 "10000000ffffffffffffffffffffffffffffffffffffffff", 633 "100000000000000000000000000000000000000000000000", 634 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 635 "-ffffffff00000000ffffffff00000000ffffffff00000000", 636 "-ffffffffffffffffffffffff000000000000000000000000", 637 "-ffffffff0000000000000000000000000000000000000000", 638 "-10000000ffffffffffffffffffffffffffffffffffffffff", 639 "-100000000000000000000000000000000000000000000000", 640 "-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 641 }; 642 643 for(int i = 0; i < bitPatterns.length; i++) { 644 BigInteger b1 = new BigInteger(bitPatterns[i], 16); 645 BigInteger b2 = null; 646 647 File f = new File("serialtest"); 648 FileOutputStream fos = new FileOutputStream(f); 649 try { 650 ObjectOutputStream oos = new ObjectOutputStream(fos); 651 try { 652 oos.writeObject(b1); 653 oos.flush(); 654 } finally { 655 oos.close(); 656 } 657 658 FileInputStream fis = new FileInputStream(f); 659 try { 660 ObjectInputStream ois = new ObjectInputStream(fis); 661 try { 662 b2 = (BigInteger)ois.readObject(); 663 } finally { 664 ois.close(); 665 } 666 } finally { 667 fis.close(); 668 } 669 670 if (!b1.equals(b2) || 671 !b1.equals(b1.or(b2))) { 672 failCount++; 673 System.err.println("Serialized failed for hex " + 674 b1.toString(16)); 675 } 676 } finally { 677 fos.close(); 678 } 679 f.delete(); 680 } 681 682 for(int i=0; i<10; i++) { 683 BigInteger b1 = fetchNumber(rnd.nextInt(100)); 684 BigInteger b2 = null; 685 File f = new File("serialtest"); 686 FileOutputStream fos = new FileOutputStream(f); 687 try { 688 ObjectOutputStream oos = new ObjectOutputStream(fos); 689 try { 690 oos.writeObject(b1); 691 oos.flush(); 692 } finally { 693 oos.close(); 694 } 695 696 FileInputStream fis = new FileInputStream(f); 697 try { 698 ObjectInputStream ois = new ObjectInputStream(fis); 699 try { 700 b2 = (BigInteger)ois.readObject(); 701 } finally { 702 ois.close(); 703 } 704 } finally { 705 fis.close(); 706 } 707 } finally { 708 fos.close(); 709 } 710 711 if (!b1.equals(b2) || 712 !b1.equals(b1.or(b2))) 713 failCount++; 714 f.delete(); 715 } 716 717 report("Serialize", failCount); 718 } 719 720 /** 721 * Main to interpret arguments and run several tests. 722 * 723 * Up to three arguments may be given to specify the size of BigIntegers 724 * used for call parameters 1, 2, and 3. The size is interpreted as 725 * the maximum number of decimal digits that the parameters will have. 726 * 727 */ 728 public static void main(String[] args) throws Exception { 729 |