fix: use file-based stream
This commit is contained in:
parent
ad04d90940
commit
fcb01e21cd
1 changed files with 27 additions and 7 deletions
|
@ -304,8 +304,25 @@ helma.Zip = function(file) {
|
||||||
* @type ByteArray
|
* @type ByteArray
|
||||||
*/
|
*/
|
||||||
this.getData = function() {
|
this.getData = function() {
|
||||||
|
zOutStream.close();
|
||||||
|
fOutStream.close();
|
||||||
|
var inputStream = new java.io.FileInputStream(tempFile);
|
||||||
|
var bOutStream = new java.io.ByteArrayOutputStream();
|
||||||
|
var buffer = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 8192);
|
||||||
|
try {
|
||||||
|
var chunk;
|
||||||
|
while ((chunk = inputStream.read(buffer)) !== -1) {
|
||||||
|
bOutStream.write(buffer, 0, chunk);
|
||||||
|
}
|
||||||
|
bOutStream.flush();
|
||||||
|
} catch (ex) {
|
||||||
|
app.log(ex);
|
||||||
|
} finally {
|
||||||
|
if (inputStream) inputStream.close();
|
||||||
|
if (bOutStream) bOutStream.close();
|
||||||
|
}
|
||||||
return bOutStream.toByteArray();
|
return bOutStream.toByteArray();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the archive.
|
* Saves the archive.
|
||||||
|
@ -317,12 +334,13 @@ helma.Zip = function(file) {
|
||||||
throw new Error("no destination for ZipFile given");
|
throw new Error("no destination for ZipFile given");
|
||||||
// first of all, close the ZipOutputStream
|
// first of all, close the ZipOutputStream
|
||||||
zOutStream.close();
|
zOutStream.close();
|
||||||
|
fOutStream.close();
|
||||||
var destFile = new java.io.File(dest);
|
var destFile = new java.io.File(dest);
|
||||||
try {
|
try {
|
||||||
var outStream = new java.io.FileOutputStream(destFile);
|
if (destFile.exists()) destFile['delete']();
|
||||||
bOutStream.writeTo(outStream);
|
java.nio.file.Files.move(tempFile.toPath(), destFile.toPath());
|
||||||
} finally {
|
} catch (ex) {
|
||||||
if (outStream) outStream.close();
|
app.log(ex);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
@ -339,8 +357,10 @@ helma.Zip = function(file) {
|
||||||
/**
|
/**
|
||||||
* constructor body
|
* constructor body
|
||||||
*/
|
*/
|
||||||
var bOutStream = new java.io.ByteArrayOutputStream();
|
var tempFile = new java.io.File.createTempFile('zip-', '');
|
||||||
var zOutStream = new java.util.zip.ZipOutputStream(bOutStream);
|
var fOutStream = new java.io.FileOutputStream(tempFile);
|
||||||
|
var zOutStream = new java.util.zip.ZipOutputStream(fOutStream);
|
||||||
|
|
||||||
if (file) {
|
if (file) {
|
||||||
file = evalFile(file);
|
file = evalFile(file);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue