fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. for (int i = 0; i < 100000; i++) {
  13.  
  14. Set<Object> set = new LinkedHashSet<>();
  15.  
  16. long items = Math.round(Math.random() * 10);
  17.  
  18. for (int j = 0; j < items; j++) {
  19. set.add(Double.toHexString(Math.random() * 1232330));
  20. }
  21.  
  22. byte[] source = toBytes(set);
  23. Object obj = toObject(source);
  24. byte[] result = toBytes(obj);
  25.  
  26. for (int j = 0; j < source.length; j++) {
  27. if (source[j] != result[j]) {
  28. throw new Exception("CHO ZA HOOINYA?");
  29. }
  30. }
  31. }
  32. System.out.println("OK!");
  33. }
  34.  
  35. static byte[] toBytes(Object obj) throws Exception {
  36. try {
  37. out.writeObject(obj);
  38. out.flush();
  39. return bos.toByteArray();
  40. } finally {
  41. try {
  42. bos.close();
  43. } catch (IOException ex) {
  44. // ignore close exception
  45. }
  46. }
  47. }
  48.  
  49. static Object toObject(byte[] bytes) throws Exception {
  50. ObjectInput in = null;
  51. try {
  52. in = new ObjectInputStream(bis);
  53. return in.readObject();
  54. } finally {
  55. try {
  56. if (in != null) {
  57. in.close();
  58. }
  59. } catch (IOException ex) {
  60. // ignore close exception
  61. }
  62. }
  63. }
  64. }
Runtime error #stdin #stdout #stderr 0.04s 711168KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Exception in thread "main" java.lang.Exception: CHO ZA HOOINYA?
	at Ideone.main(Main.java:28)