@Test
 public void testException() throws Exception {
   Object exceptions[] = {
     null,
     new Exception("test"),
     new ArrayIndexOutOfBoundsException(),
     new RuntimeException(new IllegalArgumentException("Blub"))
   };
   try {
     throw new IOException();
   } catch (Exception ex) {
     exceptions[0] = ex;
   }
   out.writeObject(exceptions);
   in.resetForReuseUseArray(out.getCopyOfWrittenBuffer());
   out.flush();
   Object res[] = (Object[]) in.readObject();
   //        assertTrue(DeepEquals.deepEquals(obj,res));
   for (int i = 0; i < res.length; i++) {
     Object ex = res[i];
     String message = ((Throwable) exceptions[i]).getMessage();
     String message1 = ((Throwable) ex).getMessage();
     assertTrue(DeepEquals.deepEquals(message, message1));
   }
 }
 @Test
 public void testBigNums() throws Exception {
   BigNums obj = new BigNums();
   out.writeObject(obj);
   in.resetForReuseUseArray(out.getCopyOfWrittenBuffer());
   out.flush();
   Object res = in.readObject();
   assertTrue(DeepEquals.deepEquals(obj, res));
 }
 @Test
 public void testWeirdArray() throws Exception {
   WeirdArrays obj = new WeirdArrays();
   out.writeObject(obj);
   in.resetForReuseUseArray(lastBinary = out.getCopyOfWrittenBuffer());
   out.flush();
   WeirdArrays res = (WeirdArrays) in.readObject();
   assertTrue(DeepEquals.deepEquals(obj, res));
 }
 @Test
 public void testStrings() throws Exception {
   Strings obj = new Strings();
   out.writeObject(obj);
   in.resetForReuseUseArray(out.getCopyOfWrittenBuffer());
   out.flush();
   Strings res = (Strings) in.readObject();
   assertTrue(DeepEquals.deepEquals(res.junk, res.junk1));
   assertTrue(DeepEquals.deepEquals(obj, res));
 }
 @Test
 public void testPrimitiveArray() throws Exception {
   PrimitiveArray obj = new PrimitiveArray();
   out.writeObject(obj);
   in.resetForReuseUseArray(lastBinary = out.getCopyOfWrittenBuffer());
   out.flush();
   PrimitiveArray res = (PrimitiveArray) in.readObject();
   assertTrue(res.aLong0 == res.aRef);
   assertTrue(res.aRef1 == res.mix[1]);
   assertTrue(DeepEquals.deepEquals(obj, res));
 }
  @Test
  public void testFlush() throws IOException, ClassNotFoundException {
    ByteArrayOutputStream bout = new ByteArrayOutputStream(1000 * 1000);
    FSTObjectOutput fout = new FSTObjectOutput(bout);
    Strings obj = new Strings();
    fout.writeObject(obj);
    fout.writeObject(new byte[1000 * 1000 * 10]);
    fout.writeObject(obj);
    fout.close();

    FSTObjectInput fin = new FSTObjectInput(new ByteArrayInputStream(bout.toByteArray()));
    Strings res = (Strings) fin.readObject();
    fin.readObject();
    Strings res1 = (Strings) fin.readObject();
    assertTrue(res == res1);
    assertTrue(DeepEquals.deepEquals(obj, res));
  }
  @Test
  public void testEnums() throws Exception {
    Basics obj = new Basics(123);
    out.writeObject(obj);
    in.resetForReuseUseArray(out.getCopyOfWrittenBuffer());
    out.flush();
    Basics res = (Basics) in.readObject();

    // note: fix false alarm with 1.7_71 + newer 1.8. (because stacktrace not serialized ofc)
    Object[] exceptions1 = res.exceptions;
    Object[] exceptions2 = obj.exceptions;
    res.exceptions = obj.exceptions = null;

    for (int i = 1; i < exceptions1.length; i++) {
      assertTrue(exceptions1[i].getClass() == exceptions2[i].getClass());
    }
    assertTrue(DeepEquals.deepEquals(obj, res));
  }
 @Override
 public void writeObject(
     FSTObjectOutput out,
     Object toWrite,
     FSTClazzInfo clzInfo,
     FSTClazzInfo.FSTFieldInfo referencedBy,
     int streamPosition)
     throws IOException {
   out.defaultWriteObject(toWrite, clzInfo);
 }
  @Test
  public void fastRoundTrip() throws IOException, ClassNotFoundException {
    TestArray list = new TestArray();

    ByteArrayOutputStream os = new ByteArrayOutputStream();
    FSTObjectOutput objOut = new FSTObjectOutput(os);
    objOut.writeObject(list);
    objOut.close();

    ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
    FSTObjectInput objIn = new FSTObjectInput(is);
    //        objIn.setReadExternalReadAHead(16000);
    TestArray res = (TestArray) objIn.readObject();
    for (int i = 0; i < res.bytes1.length; i++) {
      assertTrue(res.bytes1[i] == 1);
    }
    for (int i = 0; i < res.bytes2.length; i++) {
      assertTrue(res.bytes2[i] == 2);
    }
    assertTrue(res.bytes1[547] == 1 && res.bytes2[347] == 2);
  }
  @Test
  public void testSimpleCollections() throws Exception {
    HashMap obj = new HashMap();
    ArrayList li = new ArrayList();
    li.add("zero");
    li.add(null);
    li.add("second");
    obj.put("x", li);
    obj.put("y", li);
    obj.put("yy", null);
    obj.put(null, "asd");
    obj.put(3, "99999");
    out.writeObject(obj);

    final byte[] copyOfWrittenBuffer = out.getCopyOfWrittenBuffer();
    in.resetForReuseUseArray(copyOfWrittenBuffer);
    out.flush();
    HashMap res = (HashMap) in.readObject();
    assertTrue(res.get("x") == res.get("y"));
    assertTrue(DeepEquals.deepEquals(obj, res));
  }