Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void zipFile(Map<String, Employee> employees,String filename){
- try {
- FileOutputStream fos = new FileOutputStream(filename);
- ZipOutputStream zos= new ZipOutputStream(fos);
- zos.putNextEntry(new ZipEntry("file"));
- ObjectOutputStream oos=new ObjectOutputStream(zos);
- oos.writeObject(employees);
- zos.closeEntry();
- zos.close();
- } catch(FileNotFoundException ex) {
- System.err.format("Nie znaleziono pliku !");
- }catch(IOException ex){
- System.err.println("I/O error: " +ex);
- }
- }
- public static void gzipFile(Map<String, Employee> employees,String filename){
- try {
- FileOutputStream fos = new FileOutputStream(filename);
- GZIPOutputStream gz = new GZIPOutputStream(fos);
- ObjectOutputStream oos=new ObjectOutputStream(gz);
- oos.writeObject(employees);
- gz.close();
- fos.close();
- } catch(FileNotFoundException ex) {
- System.err.format("Nie znaleziono pliku !");
- }catch(IOException ex){
- System.err.println("I/O error: " +ex);
- }
- }
- //czytanie z pliku
- public static Map<String,Employee>loadFiles(String filename){
- if(filename.endsWith(".zip")){
- try {
- FileInputStream fis = new FileInputStream(filename);
- ZipInputStream zis = new ZipInputStream(fis);
- ZipEntry ze = zis.getNextEntry();
- ObjectInputStream ois = new ObjectInputStream(zis);
- Map<String, Employee> temp =(Map<String, Employee>) ois.readObject();
- fis.close();
- return temp;
- }catch(FileNotFoundException ex){
- System.err.format("Nie znaleziono pliku !");
- return null;
- }catch(IOException ex){
- System.err.println("I/O error: " +ex);
- return null;
- }catch(ClassNotFoundException ex){
- System.err.println("Nie znaleziono klasy " +ex);
- return null;
- }
- }
- else if(filename.endsWith(".gzip")){
- try{
- FileInputStream fis = new FileInputStream(filename);
- GZIPInputStream gz = new GZIPInputStream(fis);
- ObjectInputStream ois=new ObjectInputStream(gz);
- Map<String,Employee>temp= (Map<String, Employee>) ois.readObject();
- fis.close();
- return temp;
- }catch(FileNotFoundException ex){
- System.err.format("Nie znaleziono pliku !");
- return null;
- }catch(IOException ex){
- System.err.println("I/O error: " +ex);
- return null;
- }catch(ClassNotFoundException ex){
- System.err.println("Nie znaleziono klasy " +ex);
- return null;
- }
- }
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement