Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/utils/FileUtils.java @ 806:2cea76f1112e
Added Javadoc in utils package.
gnv-artifacts/trunk@888 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 08 Apr 2010 13:10:39 +0000 |
parents | c4156275c1e1 |
children | a645bd23c1c8 |
comparison
equal
deleted
inserted
replaced
805:bb7afd783321 | 806:2cea76f1112e |
---|---|
11 | 11 |
12 import java.util.zip.ZipEntry; | 12 import java.util.zip.ZipEntry; |
13 import java.util.zip.ZipOutputStream; | 13 import java.util.zip.ZipOutputStream; |
14 | 14 |
15 /** | 15 /** |
16 * A helper class to provide some methods for working with files and | |
17 * directories. | |
18 * | |
16 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> | 19 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> |
17 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 20 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
18 */ | 21 */ |
19 public final class FileUtils | 22 public final class FileUtils |
20 { | 23 { |
21 private FileUtils() { | 24 private FileUtils() { |
22 } | 25 } |
23 | 26 |
27 /** | |
28 * Deletes everything in a directory. | |
29 * | |
30 * @param dir The directory. | |
31 */ | |
24 public final static void deleteContent(File dir) { | 32 public final static void deleteContent(File dir) { |
25 if (dir == null || !dir.isDirectory()) { | 33 if (dir == null || !dir.isDirectory()) { |
26 return; | 34 return; |
27 } | 35 } |
28 | 36 |
34 } | 42 } |
35 | 43 |
36 return; | 44 return; |
37 } | 45 } |
38 | 46 |
47 /** | |
48 * Delete <i>file</i> and everything in <i>file</i> if it is a directory. | |
49 * | |
50 * @param file The file or directory. | |
51 * @return true, if deletion was successful - otherwise false. | |
52 */ | |
39 public final static boolean deleteRecursive(File file) { | 53 public final static boolean deleteRecursive(File file) { |
40 | 54 |
41 if (file == null) { | 55 if (file == null) { |
42 return false; | 56 return false; |
43 } | 57 } |
54 } | 68 } |
55 | 69 |
56 return file.delete(); | 70 return file.delete(); |
57 } | 71 } |
58 | 72 |
73 /** | |
74 * Put the given file or directory into a zip archive. | |
75 * | |
76 * @param file The file or directory. | |
77 * @param outputStream The stream to write the archive to. | |
78 * @throws IOException if an error occured while zip creation or writing to | |
79 * output stream. | |
80 */ | |
59 public static void createZipArchive( | 81 public static void createZipArchive( |
60 File file, | 82 File file, |
61 OutputStream outputStream | 83 OutputStream outputStream |
62 ) | 84 ) |
63 throws IOException | 85 throws IOException |
96 } | 118 } |
97 | 119 |
98 out.finish(); | 120 out.finish(); |
99 } | 121 } |
100 | 122 |
123 /** | |
124 * A class representing a directory with a prefix. | |
125 */ | |
101 private static final class PrefixDir { | 126 private static final class PrefixDir { |
102 | 127 |
103 String prefix; | 128 String prefix; |
104 File dir; | 129 File dir; |
105 | 130 |
108 this.dir = dir; | 133 this.dir = dir; |
109 } | 134 } |
110 | 135 |
111 } // class PrefixDir | 136 } // class PrefixDir |
112 | 137 |
138 /** | |
139 * Write a file to zip archive. | |
140 * | |
141 * @param prefix A prefix. | |
142 * @param file The file. | |
143 * @param out The output stream. | |
144 * @throws IOException if an error occured while writing to zip output | |
145 * stream. | |
146 */ | |
113 private static void copyFileToZip( | 147 private static void copyFileToZip( |
114 String prefix, | 148 String prefix, |
115 File file, | 149 File file, |
116 ZipOutputStream out | 150 ZipOutputStream out |
117 ) | 151 ) |