code: public static File writeObjectToFile(final Object o, final String fileName)
        throws IOException {
      final File outFile = new File(fileName);
      OutputStream outputStream = new FileOutputStream(outFile);
      if (fileName.endsWith(".gz")) {
        outputStream = new GZIPOutputStream(outputStream);
      }
      outputStream = new BufferedOutputStream(outputStream);
      final ObjectOutputStream oos = new ObjectOutputStream(outputStream);
      oos.writeObject(o);
      oos.close();
      return outFile;
    }
docs: Serialize java object to a file.
  
  @param o
  the java object
  @param fileName
  the name of the file
  @return the file
  @throws IOException
  if io problems