Java Utililty Methods ObjectOutputStream Write

List of utility methods to do ObjectOutputStream Write

Description

The list of methods to do ObjectOutputStream Write are organized into topic(s).

Method

voidsaveObject2FileImpl(final Serializable object, final File file)
save Object File Impl
ObjectOutputStream output = null;
try {
    output = new ObjectOutputStream(
            new BufferedOutputStream(new DeflaterOutputStream(new FileOutputStream(file)), 1024 * 1024));
    output.writeObject(object);
    output.flush();
    output.close();
    output = null;
...
voidsaveObjectInFile(String fileName, Object obj)
save the serialized object into the specified file
FileOutputStream fileOut = new FileOutputStream(fileName);
ObjectOutputStream objectStream = new ObjectOutputStream(fileOut);
objectStream.writeObject(obj);
objectStream.close();
fileOut.close();
booleansaveObjectToFile(File file, Object object)
save Object To File
ObjectOutputStream os = null;
try {
    os = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
    os.writeObject(object);
    return true;
} catch (Exception e) {
    e.printStackTrace();
} finally {
...
voidsaveObjectToFile(File thatFile, Object... thisObject)
save Object To File
mylogger.log(Level.INFO, "Saving object{0} to file: {1}",
        new Object[] { thisObject.hashCode(), thatFile.getAbsolutePath() });
ObjectOutputStream stream;
try {
    thatFile.delete();
    if (thatFile.createNewFile()) {
        stream = new ObjectOutputStream(new FileOutputStream(thatFile));
        stream.writeObject(thisObject);
...
voidsaveObjectToFile(final Object object, final String fileName)
save Object To File
try {
    FileOutputStream fileOutputStream = new FileOutputStream(fileName);
    ObjectOutputStream oos = new ObjectOutputStream(fileOutputStream);
    oos.writeObject(object);
    oos.flush();
    oos.close();
} catch (IOException e) {
    throw new RuntimeException("Could not save '" + object + "' to file '" + fileName + "':  " + e);
...
voidsaveObjectToFile(Object obj, String fileName)
save Object To File
try (ObjectOutputStream stream = new ObjectOutputStream(new FileOutputStream(fileName))) {
    stream.writeObject(obj);
} catch (IOException e) {
    throw new RuntimeException(e);
voidsaveObjectToPath(T objectToSave, String pathToSaveTo)
Attempts to write an object to the provided path, creating the file if it does not already exist.
try {
    ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(pathToSaveTo));
    oos.writeObject(objectToSave);
    oos.close();
} catch (IOException e) {
    e.printStackTrace();
voidsaveParameters()
save Parameters
try {
    FileOutputStream fos = new FileOutputStream(FILENAME_PARAMETERS);
    ObjectOutputStream oos = new ObjectOutputStream(fos);
    oos.writeObject(paramsMap);
    oos.close();
    fos.close();
    System.out.printf("Serialized HashMap data is saved in parameters.pfe");
} catch (IOException ioe) {
...
voidsaveResultToStream(ObjectOutputStream oos, Object result)
save Result To Stream
if (oos != null) {
    oos.writeObject(result);
    oos.flush();
voidsaveResultToStream(ObjectOutputStream oos, Object result)
Saves result set to output stream
if (oos != null) {
    oos.writeObject(result);
    oos.flush();