1 | package org.medias.eccad.persistance; |
---|
2 | |
---|
3 | import java.io.File; |
---|
4 | import java.io.FileInputStream; |
---|
5 | import java.io.FileOutputStream; |
---|
6 | import java.io.IOException; |
---|
7 | import java.io.InputStream; |
---|
8 | import java.io.OutputStream; |
---|
9 | |
---|
10 | |
---|
11 | import org.medias.eccad.helpers.LoggerPerso; |
---|
12 | import org.medias.eccad.metier.TempPictureDeleter; |
---|
13 | |
---|
14 | public class GestionFichier { |
---|
15 | public void effacerFichier(String path) { |
---|
16 | File fichier = new File(path); |
---|
17 | fichier.delete(); |
---|
18 | } |
---|
19 | |
---|
20 | public void effacerFichierAncien(String path) { |
---|
21 | TempPictureDeleter deleteur = new TempPictureDeleter(); |
---|
22 | deleteur.deleteFiles(path); |
---|
23 | } |
---|
24 | |
---|
25 | public void copy(String source, String destination) { |
---|
26 | InputStream in = null; |
---|
27 | OutputStream out = null; |
---|
28 | |
---|
29 | int c=0; |
---|
30 | |
---|
31 | try { |
---|
32 | if (source != null) in=new FileInputStream(source); |
---|
33 | if (destination != null) out=new FileOutputStream(destination); |
---|
34 | while ((c=in.read())!=-1) out.write(c); |
---|
35 | in.close(); |
---|
36 | out.close(); |
---|
37 | } catch (IOException e) { |
---|
38 | //system.out.println(e.toString()); |
---|
39 | } |
---|
40 | } |
---|
41 | |
---|
42 | public void deplace(String source, String destination) { |
---|
43 | File fsource = new File(source); |
---|
44 | if (!fsource.exists()) |
---|
45 | LoggerPerso.log(GestionFichier.class, LoggerPerso.WARN, "fichier source non existant : " + source); |
---|
46 | File fdestination = new File(destination); |
---|
47 | |
---|
48 | if (!fsource.renameTo(fdestination)) |
---|
49 | LoggerPerso.log(GestionFichier.class, LoggerPerso.ERROR, "impossible de copier la legende") ; |
---|
50 | |
---|
51 | LoggerPerso.log(GestionFichier.class, LoggerPerso.INFO, "source : " + source + "\ndestination : " + destination) ; |
---|
52 | } |
---|
53 | |
---|
54 | public void creerDossier(String dossier) { |
---|
55 | File fdossier = new File(dossier); |
---|
56 | fdossier.mkdir(); |
---|
57 | } |
---|
58 | } |
---|