/** * Closes the current RandomAccessOutputStream to the zip file. * * @throws IOException if an error occurred */ private void closeWrite() throws IOException { if(raos!=null) { try { raos.close(); } finally { raos = null; } } }
@Override public void close() throws IOException { try { flush(); } catch(IOException e) { // Try closing the stream anyway } raos.close(); } }
/** * Opens the zip file for random write access. * * @throws IOException if an error occured while opening the zip file for random read access. * @throws UnsupportedFileOperationException if a required operation is not supported by the underlying filesystem. */ private void openWrite() throws IOException, UnsupportedFileOperationException { if(raos!=null) { LOGGER.info("Warning: an existing RandomAccessOutputStream was found, closing it now"); raos.close(); } // Create a buffered output stream to improve write performance, as headers are written by small chunks raos = new BufferedRandomOutputStream(file.getRandomAccessOutputStream(), WRITE_BUFFER_SIZE); }
/** * This method is overridden to release the internal buffer when this stream is closed. */ @Override public synchronized void close() throws IOException { if(buffer!=null) { // buffer is null if close() was already called try { flush(); } catch(IOException e) { // Continue anyway } // Release the buffer BufferPool.releaseByteArray(buffer); buffer = null; } raos.close(); }
/** * Validates that FileMonitor properly reports {@link FileMonitor#SIZE_ATTRIBUTE} changes when a file's size changes. * * @throws IOException should not normally happen */ @Test public void testSizeAttribute() throws IOException { setUp(SIZE_ATTRIBUTE); RandomAccessOutputStream raos = file.getRandomAccessOutputStream(); try { raos.setLength(10); assert hasAttributeChanged(SIZE_ATTRIBUTE); raos.setLength(0); } finally { if(raos!=null) raos.close(); } }