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
14329
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;
  }
1021936
public static void writeByteArrayToFile(final String filename, final byte[] byteArray)
		throws IOException
	{
		final File file = new File(filename);
		writeByteArrayToFile(file, byteArray);
	}
992915
public void serialize(Map<String, T> map, OutputStream os) throws IOException {
        JsonGenerator jsonGenerator = LoganSquare.JSON_FACTORY.createGenerator(os);
        serialize(map, jsonGenerator);
        jsonGenerator.close();
    }
621186
public static File writeObjectToTempFile(Object o, String filename)
  throws IOException {
    File file = File.createTempFile(filename, ".tmp");
    file.deleteOnExit();
    ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(
        new GZIPOutputStream(new FileOutputStream(file))));
    oos.writeObject(o);
    oos.close();
    return file;
  }
487514
public NamedOdsFileWriter createWriter(final String filename) throws IOException {
        final NamedOdsDocument document = this.createNamedDocument();
        final NamedOdsFileWriter writer = OdsFileDirectWriter.builder(this.logger, document)
                .openResult(this.openFile(filename)).build();
        document.addObserver(writer);
        document.prepareFlush();
        return writer;
    }
1356518
public void writeToFileWithoutFactors(String filename) throws IOException {
        FileOutputStream fos = new FileOutputStream(filename);
        writeToStreamWithoutFactors(fos);
        fos.close();
    }
1063525
public static Object xmlToObject(String fileName) throws FileNotFoundException {
		FileInputStream fi = new FileInputStream(fileName);
		XMLDecoder decoder = new XMLDecoder(fi);
		Object object = decoder.readObject();
		decoder.close();
		return object;
	}
769946
public static JsonValue serializeAsJson(Object o) throws IOException {
        try {
            return findFieldsToSerialize(o).mainObject;
        } catch (IllegalStateException ise) {
            // the reflective attempt to build the object failed.
            throw new IOException("Unable to build JSON for Object", ise);
        } catch (JsonException e) {
            throw new IOException("Unable to build JSON for Object", e);
        }
    }
351365
public File write(File file) throws IOException {
        try (FileOutputStream fos = new FileOutputStream(file)) {
            write(fos);
            return file;
        }
    }
216795
public static String encode(Serializable o) {
                ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
            try {
                        ObjectOutputStream oos = new ObjectOutputStream(bos);
                        try {
                                oos.writeObject(o);
                                oos.flush();
                        } finally {
                                oos.close();
                        }
                        return Base64.encodeBytes(bos.toByteArray());
                } catch (IOException e) {
                        throw new RuntimeException(e);
                }
        }
755358
public static byte[] serialize(Object value) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    serialize(value, out);
    return out.toByteArray();
  }
258097
private static String readFile(final String fileName) throws IOException {
    return new String(Files.readAllBytes(Paths.get(fileName)), StandardCharsets.UTF_8);
  }
366948
public static function serialize( $object, $fileName )
	{
		$serial	= parent::serialize( $object );
		$file	= new FS_File_Writer( $fileName );
		return $file->writeString( $serial );
	}
1305690
public File newFile(String fileName) throws IOException {
        File file = new File(getRoot(), fileName);
        if (!file.createNewFile()) {
            throw new IOException(
                    "a file with the name \'" + fileName + "\' already exists in the test folder");
        }
        return file;
    }
1056446
public void serialize(OutputStream os, String name, Configuration configuration) throws XMLStreamException {
      serialize(os, null, Collections.singletonMap(name, configuration));
   }
177474
public static String encodeFromFile(final String filename) {

        java.io.File file = new java.io.File(filename);
        long fileLength = file.length();

        java.io.InputStream ins;
        try {
            ins = new java.io.FileInputStream(file);
        } catch (FileNotFoundException e) {
            System.out.println("Error opening file " + filename + e.getMessage());
            return null;
        }
        String encodedData = encodeFromInputStream(ins, fileLength);
        if (encodedData == null) {
            System.err.println("Error encoding from file " + filename);
        }
        return encodedData;
    }
490220
public static void writeObject(Object object, String fileName) throws DISIException {
        log.info("Writing " + fileName);
        try {
            FileOutputStream fos = new FileOutputStream(fileName);
            ObjectOutputStream oos = new ObjectOutputStream(fos);
            oos.writeObject(object);
            oos.close();
            fos.close();
        } catch (IOException e) {
            final String errMessage = e.getClass().getSimpleName() + ": " + e.getMessage();
            log.error(errMessage, e);
            throw new DISIException(errMessage, e);
        }
    }