BrightSide Workbench Full Report + Source Code
Serializer.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.elephant.impl.util;
19 
20 import java.io.File;
21 import java.io.FileFilter;
22 import org.turro.elephant.context.ElephantContext;
23 
28 public class Serializer {
29 
30  public static File getFile(String fileName) {
31  return new File(ElephantContext.getRealPath("/WEB-INF/serializer" + fileName));
32  }
33 
34  public static File[] getFiles(String rootName) {
35  File root = new File(ElephantContext.getRealPath("/WEB-INF/serializer" + rootName));
36  if(!root.exists()) root.mkdirs();
37  return getFiles(root);
38  }
39 
40  public static File[] getFiles(File root) {
41  return root.listFiles(new FileFilter() {
42  @Override
43  public boolean accept(File pathname) {
44  return pathname.isFile() || !pathname.isHidden();
45  }
46  });
47  }
48 
49  public static void serialize(String fileName, Object instance) {
50  File file = new File(ElephantContext.getRealPath("/WEB-INF/serializer" + fileName));
51  serialize(file, instance);
52  }
53 
54  public static void serialize(File file, Object instance) {
55  File root = new File(org.amic.util.file.FileUtil.getParentPath(file));
56  if(!root.exists()) root.mkdirs();
57  org.turro.reflection.Serializer.serialize(file, instance);
58  }
59 
60  public static Object deserialize(String fileName) {
61  File file = new File(ElephantContext.getRealPath("/WEB-INF/serializer" + fileName));
62  return deserialize(file);
63  }
64 
65  public static Object deserialize(File file) {
66  return org.turro.reflection.Serializer.deserialize(file);
67  }
68 
69  public static void remove(String fileName) {
70  File file = new File(ElephantContext.getRealPath("/WEB-INF/serializer" + fileName));
71  remove(file);
72  }
73 
74  public static void remove(File file) {
75  file.delete();
76  }
77 
78  private Serializer() {
79  }
80 
81 }
static void serialize(File file, Object instance)
Definition: Serializer.java:54
static void serialize(String fileName, Object instance)
Definition: Serializer.java:49
static Object deserialize(String fileName)
Definition: Serializer.java:60
static File getFile(String fileName)
Definition: Serializer.java:30
static File[] getFiles(File root)
Definition: Serializer.java:40
static File[] getFiles(String rootName)
Definition: Serializer.java:34
static Object deserialize(File file)
Definition: Serializer.java:65