Mercurial > dive4elements > gnv-client
annotate gnv-artifacts/src/main/java/de/intevation/gnv/utils/FileUtils.java @ 864:2b8707432121
ISSUE262: Removed duplicate StateIds
gnv-artifacts/trunk@1002 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Tue, 27 Apr 2010 13:10:24 +0000 |
parents | a645bd23c1c8 |
children | f953c9a559d8 |
rev | line source |
---|---|
480
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.gnv.utils; |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import java.io.BufferedInputStream; |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 import java.io.File; |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 import java.io.FileInputStream; |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 import java.io.IOException; |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 import java.io.InputStream; |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 import java.io.OutputStream; |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 import java.util.Stack; |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 import java.util.zip.ZipEntry; |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 import java.util.zip.ZipOutputStream; |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 /** |
806
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
16 * A helper class to provide some methods for working with files and |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
17 * directories. |
807
a645bd23c1c8
Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
806
diff
changeset
|
18 * |
780
c4156275c1e1
Bring @author javadoc tags in form '@author <a href="john.doe@example.com">John Doe</a>'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
775
diff
changeset
|
19 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> |
c4156275c1e1
Bring @author javadoc tags in form '@author <a href="john.doe@example.com">John Doe</a>'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
775
diff
changeset
|
20 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
480
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 */ |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 public final class FileUtils |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 { |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 private FileUtils() { |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 } |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 |
806
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
27 /** |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
28 * Deletes everything in a directory. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
29 * |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
30 * @param dir The directory. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
31 */ |
775
eedad2ddad14
Removed race-condition while shapefile creation (issue164).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
480
diff
changeset
|
32 public final static void deleteContent(File dir) { |
eedad2ddad14
Removed race-condition while shapefile creation (issue164).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
480
diff
changeset
|
33 if (dir == null || !dir.isDirectory()) { |
eedad2ddad14
Removed race-condition while shapefile creation (issue164).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
480
diff
changeset
|
34 return; |
eedad2ddad14
Removed race-condition while shapefile creation (issue164).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
480
diff
changeset
|
35 } |
eedad2ddad14
Removed race-condition while shapefile creation (issue164).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
480
diff
changeset
|
36 |
eedad2ddad14
Removed race-condition while shapefile creation (issue164).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
480
diff
changeset
|
37 File[] files = dir.listFiles(); |
eedad2ddad14
Removed race-condition while shapefile creation (issue164).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
480
diff
changeset
|
38 if (files != null) { |
eedad2ddad14
Removed race-condition while shapefile creation (issue164).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
480
diff
changeset
|
39 for (File file: files) { |
eedad2ddad14
Removed race-condition while shapefile creation (issue164).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
480
diff
changeset
|
40 deleteRecursive(file); |
eedad2ddad14
Removed race-condition while shapefile creation (issue164).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
480
diff
changeset
|
41 } |
eedad2ddad14
Removed race-condition while shapefile creation (issue164).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
480
diff
changeset
|
42 } |
eedad2ddad14
Removed race-condition while shapefile creation (issue164).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
480
diff
changeset
|
43 |
eedad2ddad14
Removed race-condition while shapefile creation (issue164).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
480
diff
changeset
|
44 return; |
eedad2ddad14
Removed race-condition while shapefile creation (issue164).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
480
diff
changeset
|
45 } |
eedad2ddad14
Removed race-condition while shapefile creation (issue164).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
480
diff
changeset
|
46 |
806
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
47 /** |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
48 * Delete <i>file</i> and everything in <i>file</i> if it is a directory. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
49 * |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
50 * @param file The file or directory. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
51 * @return true, if deletion was successful - otherwise false. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
52 */ |
480
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 public final static boolean deleteRecursive(File file) { |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 if (file == null) { |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 return false; |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 } |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 if (file.isDirectory()) { |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 File [] files = file.listFiles(); |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 if (files != null) { |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 for (File sub: files) { |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 if (!deleteRecursive(sub)) { |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 return false; |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 } |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 } |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 } |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 } |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 return file.delete(); |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 } |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 |
806
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
73 /** |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
74 * Put the given file or directory into a zip archive. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
75 * |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
76 * @param file The file or directory. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
77 * @param outputStream The stream to write the archive to. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
78 * @throws IOException if an error occured while zip creation or writing to |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
79 * output stream. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
80 */ |
480
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
81 public static void createZipArchive( |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 File file, |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 OutputStream outputStream |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 ) |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 throws IOException |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 { |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 ZipOutputStream out = new ZipOutputStream(outputStream); |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 if (file.isFile()) { |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 copyFileToZip("", file, out); |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 } |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 else if (file.isDirectory()) { |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 Stack<PrefixDir> stack = new Stack<PrefixDir>(); |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 stack.push(new PrefixDir(file.getName() + "/", file)); |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
97 while (!stack.isEmpty()) { |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
98 PrefixDir pd = stack.pop(); |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
99 |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
100 ZipEntry dirEntry = new ZipEntry(pd.prefix); |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
101 out.putNextEntry(dirEntry); |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
102 out.closeEntry(); |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
103 |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
104 File [] files = pd.dir.listFiles(); |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
105 if (files != null) { |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
106 for (File sub: files) { |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
107 if (sub.isDirectory()) { |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
108 stack.push(new PrefixDir( |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
109 pd.prefix + sub.getName() + "/", |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
110 sub)); |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 } |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
112 else if (sub.isFile()) { |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
113 copyFileToZip(pd.prefix, sub, out); |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
114 } |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
115 } |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 } |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
117 } |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
118 } |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
119 |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
120 out.finish(); |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
121 } |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
122 |
806
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
123 /** |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
124 * A class representing a directory with a prefix. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
125 */ |
480
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 private static final class PrefixDir { |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
128 String prefix; |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
129 File dir; |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
130 |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
131 public PrefixDir(String prefix, File dir) { |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
132 this.prefix = prefix; |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
133 this.dir = dir; |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
134 } |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
135 |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
136 } // class PrefixDir |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
137 |
806
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
138 /** |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
139 * Write a file to zip archive. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
140 * |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
141 * @param prefix A prefix. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
142 * @param file The file. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
143 * @param out The output stream. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
144 * @throws IOException if an error occured while writing to zip output |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
145 * stream. |
2cea76f1112e
Added Javadoc in utils package.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
780
diff
changeset
|
146 */ |
480
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
147 private static void copyFileToZip( |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
148 String prefix, |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 File file, |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
150 ZipOutputStream out |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 ) |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
152 throws IOException |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
153 { |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
154 String entryName = prefix + file.getName(); |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
155 ZipEntry entry = new ZipEntry(entryName); |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
156 out.putNextEntry(entry); |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
157 InputStream in = null; |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
158 try { |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
159 in = |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
160 new BufferedInputStream( |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
161 new FileInputStream(file), 20*1024); |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
162 |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
163 byte [] buf = new byte[2048]; |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
164 |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
165 int r; |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
166 while ((r = in.read(buf)) > 0) { |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
167 out.write(buf, 0, r); |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
168 } |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
169 } |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
170 finally { |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
171 if (in != null) { |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
172 try { in.close(); } |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
173 catch (IOException ioe) {} |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
174 } |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
175 } |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
176 out.closeEntry(); |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
177 } |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
178 } |
211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
179 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |