@Test public void testClose() throws Exception { final FileBuffer buffer = new FileBuffer(); assertEquals(0L, buffer.length(), 0L); final byte[] chunk = RandomUtils.nextBytes(100); buffer.write(chunk, 0L); assertEquals(100L, buffer.length(), 0L); buffer.close(); assertEquals(0L, buffer.length(), 0L); buffer.write(chunk, 0L); assertEquals(100L, buffer.length(), 0L); }
@Override public synchronized void close() { this.length = 0L; if(temporary.exists()) { try { if(file != null) { file.close(); } } catch(IOException e) { log.error(String.format("Failure closing buffer %s", this)); } finally { try { temporary.delete(); file = null; } catch(AccessDeniedException | NotfoundException e) { log.warn(String.format("Failure removing temporary file %s for buffer %s. Schedule for delete on exit.", temporary, this)); Paths.get(temporary.getAbsolute()).toFile().deleteOnExit(); } } } }
FileBuffer implements Buffer { @Override public synchronized void close() { this.length = 0L; if(temporary.exists()) { try { if(file != null) { file.close(); } } catch(IOException e) { log.error(String.format("Failure closing buffer %s", this)); } finally { try { temporary.delete(); file = null; } catch(AccessDeniedException | NotfoundException e) { log.warn(String.format("Failure removing temporary file %s for buffer %s. Schedule for delete on exit.", temporary, this)); Paths.get(temporary.getAbsolute()).toFile().deleteOnExit(); } } } } }
FileBuffer implements Buffer { @Override public synchronized void close() { this.length = 0L; if(temporary.exists()) { try { if(file != null) { file.close(); } } catch(IOException e) { log.error(String.format("Failure closing buffer %s", this)); } finally { try { temporary.delete(); file = null; } catch(AccessDeniedException | NotfoundException e) { log.warn(String.format("Failure removing temporary file %s for buffer %s. Schedule for delete on exit.", temporary, this)); Paths.get(temporary.getAbsolute()).toFile().deleteOnExit(); } } } } FileBuffer();  FileBuffer(final Local temporary); }
FileBuffer implements Buffer { @Override public synchronized void close() { this.length = 0L; if(temporary.exists()) { try { if(file != null) { file.close(); } } catch(IOException e) { log.error(String.format("Failure closing buffer %s", this)); } finally { try { temporary.delete(); file = null; } catch(AccessDeniedException | NotfoundException e) { log.warn(String.format("Failure removing temporary file %s for buffer %s. Schedule for delete on exit.", temporary, this)); Paths.get(temporary.getAbsolute()).toFile().deleteOnExit(); } } } } FileBuffer();  FileBuffer(final Local temporary); @Override synchronized int write(final byte[] chunk, final Long offset); @Override synchronized int read(final byte[] chunk, final Long offset); @Override synchronized Long length(); @Override void truncate(final Long length); @Override synchronized void close(); @Override String toString(); }
FileBuffer implements Buffer { @Override public synchronized void close() { this.length = 0L; if(temporary.exists()) { try { if(file != null) { file.close(); } } catch(IOException e) { log.error(String.format("Failure closing buffer %s", this)); } finally { try { temporary.delete(); file = null; } catch(AccessDeniedException | NotfoundException e) { log.warn(String.format("Failure removing temporary file %s for buffer %s. Schedule for delete on exit.", temporary, this)); Paths.get(temporary.getAbsolute()).toFile().deleteOnExit(); } } } } FileBuffer();  FileBuffer(final Local temporary); @Override synchronized int write(final byte[] chunk, final Long offset); @Override synchronized int read(final byte[] chunk, final Long offset); @Override synchronized Long length(); @Override void truncate(final Long length); @Override synchronized void close(); @Override String toString();  }