26
26
27
27
package com .oracle .appbundler ;
28
28
29
+ import java .io .BufferedOutputStream ;
29
30
import java .io .BufferedWriter ;
30
31
import java .io .File ;
32
+ import java .io .FileOutputStream ;
31
33
import java .io .FileWriter ;
32
34
import java .io .IOException ;
33
35
import java .io .InputStream ;
36
+ import java .io .OutputStream ;
34
37
import java .io .Writer ;
35
38
import java .net .URL ;
36
39
import java .nio .file .Files ;
37
40
import java .nio .file .LinkOption ;
38
41
import java .nio .file .Path ;
39
42
import java .nio .file .StandardCopyOption ;
40
43
import java .util .ArrayList ;
44
+ import java .util .zip .ZipEntry ;
45
+ import java .util .zip .ZipInputStream ;
41
46
42
47
import javax .xml .stream .XMLOutputFactory ;
43
48
import javax .xml .stream .XMLStreamException ;
@@ -87,6 +92,8 @@ public class AppBundlerTask extends Task {
87
92
private static final String ARRAY_TAG = "array" ;
88
93
private static final String STRING_TAG = "string" ;
89
94
95
+ private static final int BUFFER_SIZE = 2048 ;
96
+
90
97
public void setOutputDirectory (File outputDirectory ) {
91
98
this .outputDirectory = outputDirectory ;
92
99
}
@@ -276,6 +283,9 @@ public void execute() throws BuildException {
276
283
277
284
executableFile .setExecutable (true , false );
278
285
286
+ // Copy localized resources to Resources folder
287
+ copyResources (resourcesDirectory );
288
+
279
289
// Copy runtime to PlugIns folder
280
290
copyRuntime (plugInsDirectory );
281
291
@@ -292,6 +302,42 @@ public void execute() throws BuildException {
292
302
}
293
303
}
294
304
305
+ private void copyResources (File resourcesDirectory ) throws IOException {
306
+ // Unzip res.zip into resources directory
307
+ InputStream inputStream = getClass ().getResourceAsStream ("res.zip" );
308
+ ZipInputStream zipInputStream = new ZipInputStream (inputStream );
309
+
310
+ try {
311
+ ZipEntry zipEntry = zipInputStream .getNextEntry ();
312
+ while (zipEntry != null ) {
313
+ File file = new File (resourcesDirectory , zipEntry .getName ());
314
+
315
+ if (zipEntry .isDirectory ()) {
316
+ file .mkdir ();
317
+ } else {
318
+ OutputStream outputStream = new BufferedOutputStream (new FileOutputStream (file ), BUFFER_SIZE );
319
+
320
+ try {
321
+ int b = zipInputStream .read ();
322
+ while (b != -1 ) {
323
+ outputStream .write (b );
324
+ b = zipInputStream .read ();
325
+ }
326
+
327
+ outputStream .flush ();
328
+ } finally {
329
+ outputStream .close ();
330
+ }
331
+
332
+ }
333
+
334
+ zipEntry = zipInputStream .getNextEntry ();
335
+ }
336
+ } finally {
337
+ zipInputStream .close ();
338
+ }
339
+ }
340
+
295
341
private void copyRuntime (File plugInsDirectory ) throws IOException {
296
342
if (runtime != null ) {
297
343
File runtimeHomeDirectory = runtime .getDir ();
0 commit comments