* "path", then nulls out "files".
*/
public void save() throws Exception
{
String tmpPath = null;
ZipOutputStream zos = null;
try
{
assert (out != null) || (path != null) : "Must supply either an output stream or a location";
if (out != null)
{
zos = new ZipOutputStream(out);
}
else if (path != null)
{
tmpPath = path + ".tmp";
zos = new ZipOutputStream( new BufferedOutputStream( new FileOutputStream( FileUtil.openFile(tmpPath, true) )));
}
for (Map.Entry<String, VirtualFile> mapEntry : files.entrySet())
{
VirtualFile f = mapEntry.getValue();
ZipEntry entry = new ZipEntry(mapEntry.getKey());
entry.setTime(f.getLastModified());
zos.putNextEntry( entry );
BufferedInputStream in = new BufferedInputStream(f.getInputStream());
FileUtil.streamOutput(in, zos);
zos.closeEntry();
}
zos.close();
zos = null;
if ((out == null) && (path != null))
{
File tmpFile = new File(tmpPath);
File file = new File(path);
if (!FileUtils.renameFile( tmpFile, file ))
{
throw new SwcException.SwcNotRenamed( tmpFile.getAbsolutePath(), file.getAbsolutePath() );
}
}
files = null;
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
try
{
if (out != null)
{
out.close();
out = null;
}
}
catch(IOException ioe)
{
// ignore
}
try
{
if (zos != null)
zos.close();
}
catch(IOException ioe)
{
// ignore
}