* read/write gzipped xml

This commit is contained in:
Reinhard Pointner 2009-05-20 16:47:18 +00:00
parent 7c2ee57f03
commit f0414361ee
2 changed files with 33 additions and 3 deletions

View File

@ -4,13 +4,20 @@ package net.sourceforge.filebot.ui.panel.rename;
import static java.util.Collections.*;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map.Entry;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
@ -191,7 +198,14 @@ class History {
Marshaller marshaller = JAXBContext.newInstance(History.class).createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.marshal(history, file);
// write gzipped xml
OutputStream out = new GZIPOutputStream(new FileOutputStream(file), 32 * 1024);
try {
marshaller.marshal(history, out);
} finally {
out.close();
}
} catch (JAXBException e) {
throw new IOException(e);
}
@ -202,9 +216,25 @@ class History {
try {
Unmarshaller unmarshaller = JAXBContext.newInstance(History.class).createUnmarshaller();
return ((History) unmarshaller.unmarshal(file));
// GZIPInputStream or BufferedInputStream
InputStream in;
try {
// read gzipped xml
in = new GZIPInputStream(new FileInputStream(file), 32 * 1024);
} catch (IOException e) {
// file is not gzipped, read uncompressed xml instead
in = new BufferedInputStream(new FileInputStream(file));
}
try {
return ((History) unmarshaller.unmarshal(in));
} finally {
in.close();
}
} catch (JAXBException e) {
throw new IOException(e);
}
}
}

View File

@ -20,7 +20,7 @@ final class HistorySpooler {
return instance;
}
private final File file = new File("history.xml");
private final File file = new File("history.xml.gz");
private final History sessionHistory = new History();