public void close() throws IOException { RAFolderOutputStream outputStream = null; DataOutputStream data = null; try { // serialize meta data into .metedata file File file = new File(folderName + "/" + METEDATA); outputStream = new RAFolderOutputStream(null, file); data = new DataOutputStream(outputStream); IOUtil.writeMap(data, this.properties); } finally { if (data != null) { data.close(); } if (outputStream != null) { outputStream.close(); } } IOException exception = null; synchronized (outputStreams) { ArrayList<RAFolderOutputStream> outputs = new ArrayList<RAFolderOutputStream>(outputStreams); for (RAFolderOutputStream output : outputs) { try { output.close(); } catch (IOException ex) { logger.log(Level.SEVERE, ex.getMessage(), ex); if (exception != null) { exception = ex; } } } outputStreams.clear(); } synchronized (inputStreams) { ArrayList<RAFolderInputStream> inputs = new ArrayList<RAFolderInputStream>(inputStreams); for (RAFolderInputStream input : inputs) { try { input.close(); } catch (IOException ex) { logger.log(Level.SEVERE, ex.getMessage(), ex); if (exception != null) { exception = ex; } } } inputStreams.clear(); } if (exception != null) { throw exception; } // ArchiveUtil.archive( folderName, null, fileName ); }
public boolean removeEntry(String name) throws IOException { String path = ArchiveUtil.generateFullPath(folderName, name); try { File fd = new File(path); return ArchiveUtil.removeFileAndFolder(fd); } finally { synchronized (outputStreams) { ArrayList<RAFolderOutputStream> outputs = new ArrayList<RAFolderOutputStream>(outputStreams); for (RAFolderOutputStream output : outputs) { try { if (path.equals(output.getName())) { output.close(); } } catch (IOException ex) { logger.log(Level.SEVERE, ex.getMessage(), ex); throw ex; } } } } }