mirror of
https://github.com/magefree/mage.git
synced 2025-12-21 02:52:02 -08:00
Serializing all net traffic (for tracking and optimization).
This commit is contained in:
parent
82716349db
commit
b76c0e5b16
2 changed files with 55 additions and 0 deletions
|
|
@ -0,0 +1,53 @@
|
|||
package mage.client.util.object;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
|
||||
|
||||
public class SaveObjectUtil {
|
||||
|
||||
private static boolean saveIncomeData = false;
|
||||
|
||||
static {
|
||||
saveIncomeData = System.getProperty("saveObjects") != null;
|
||||
}
|
||||
|
||||
public static void saveObject(Object object, String name) {
|
||||
if (saveIncomeData) {
|
||||
ObjectOutputStream oos = null;
|
||||
try {
|
||||
File dir = new File("income");
|
||||
if (!dir.exists() || dir.exists() && dir.isFile()) {
|
||||
boolean bCreated = dir.mkdir();
|
||||
if (!bCreated) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
String time = now("[yyyy_MM_dd][H-mm-ss]");
|
||||
File f = new File("income" + File.separator + name + "_" + time + ".save");
|
||||
if (!f.exists()) {
|
||||
f.createNewFile();
|
||||
}
|
||||
oos = new ObjectOutputStream(new FileOutputStream(f));
|
||||
oos.writeObject(object);
|
||||
oos.close();
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
return;
|
||||
} catch (IOException io) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String now(String dateFormat) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
|
||||
return sdf.format(cal.getTime());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue