Here you can find the source of serializeObject(Object obj, String dir)
public static void serializeObject(Object obj, String dir) throws IOException
//package com.java2s; /**/*from w w w .j a v a 2 s . co m*/ * Musite * Copyright (C) 2010 Digital Biology Laboratory, University Of Missouri * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import java.util.zip.GZIPOutputStream; import java.util.zip.ZipOutputStream; public class Main { public static void serializeObject(Object obj, String dir) throws IOException { if (obj == null || dir == null) { throw new NullPointerException(); } FileOutputStream fos = new FileOutputStream(dir); ObjectOutputStream out; if (dir.endsWith(".gz")) { GZIPOutputStream gzos = new GZIPOutputStream(fos); out = new ObjectOutputStream(gzos); } else if (dir.endsWith(".zip")) { ZipOutputStream zos = new ZipOutputStream(fos); out = new ObjectOutputStream(zos); } else { out = new ObjectOutputStream(fos); } out.writeObject(obj); out.close(); } public static void serializeObject(Object obj, String dir, String format) throws IOException { if (obj == null || dir == null) { throw new NullPointerException(); } FileOutputStream fos = new FileOutputStream(dir); ObjectOutputStream out; if (format.equalsIgnoreCase("gz")) { GZIPOutputStream gzos = new GZIPOutputStream(fos); out = new ObjectOutputStream(gzos); } else if (format.equalsIgnoreCase("zip")) { ZipOutputStream zos = new ZipOutputStream(fos); out = new ObjectOutputStream(zos); } else { out = new ObjectOutputStream(fos); } out.writeObject(obj); out.close(); } }