| | |
| | | * |
| | | * @param entity |
| | | */ |
| | | public File writeToFile(Entity entity) throws IOException { |
| | | public File writeToFile(Entity entity, boolean overwrite) throws IOException { |
| | | String className = entity.getClass().getSimpleName(); |
| | | logger.finer(className); |
| | | File dir = new File(fileBase, className); |
| | | dir.mkdirs(); |
| | | File file = new File(dir, entity.getName()); |
| | | if(file.exists()) { |
| | | file.delete(); |
| | | //if(file.exists()) { |
| | | // file.delete(); |
| | | //} |
| | | if(file.exists() && !overwrite) { |
| | | return null; |
| | | } else { |
| | | FileWriter fw = new FileWriter(file); |
| | | Gson gson = new Gson(); |
| | | fw.write(gson.toJson(entity)); |
| | | fw.flush(); |
| | | fw.close(); |
| | | return file; |
| | | } |
| | | FileWriter fw = new FileWriter(file); |
| | | Gson gson = new Gson(); |
| | | fw.write(gson.toJson(entity)); |
| | | fw.flush(); |
| | | fw.close(); |
| | | return file; |
| | | } |
| | | |
| | | public String readFromFile(File file) throws IOException { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Object write(Entity e) { |
| | | public Object write(Entity e, boolean overwrite) { |
| | | try { |
| | | return writeToFile(e); |
| | | return writeToFile(e, overwrite); |
| | | } catch (IOException ex) { |
| | | logger.log(Level.SEVERE, null, ex); |
| | | return null; |
| | |
| | | public List<String> list(String typ) { |
| | | File base = new File(fileBase); |
| | | File dir = new File(base, typ); |
| | | File[] files = dir.listFiles(); |
| | | List<String> list = new ArrayList(); |
| | | for(File file : files) { |
| | | //NamedItem n = new NamedItem(); |
| | | //n.setLabel(file.getName()); |
| | | list.add(file.getName()); |
| | | File[] files = dir.listFiles(); |
| | | if(files != null) { |
| | | for(File file : files) { |
| | | //NamedItem n = new NamedItem(); |
| | | //n.setLabel(file.getName()); |
| | | list.add(file.getName()); |
| | | } |
| | | } |
| | | return list; |
| | | } |