@Test public void testTruncate() 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.truncate(1L); assertEquals(1L, buffer.length(), 0L); final byte[] read = new byte[1]; assertEquals(1, buffer.read(read, 0L)); assertEquals(chunk[0], read[0]); assertEquals(1L, buffer.length(), 0L); }
@Override public void truncate(final Long length) { this.length = length; if(temporary.exists()) { try { final RandomAccessFile file = random(); if(length < file.length()) { file.setLength(length); } } catch(IOException e) { log.warn(String.format("Failure truncating file %s to %d", temporary, length)); } } }
FileBuffer implements Buffer { @Override public void truncate(final Long length) { this.length = length; if(temporary.exists()) { try { final RandomAccessFile file = random(); if(length < file.length()) { file.setLength(length); } } catch(IOException e) { log.warn(String.format("Failure truncating file %s to %d", temporary, length)); } } } }
FileBuffer implements Buffer { @Override public void truncate(final Long length) { this.length = length; if(temporary.exists()) { try { final RandomAccessFile file = random(); if(length < file.length()) { file.setLength(length); } } catch(IOException e) { log.warn(String.format("Failure truncating file %s to %d", temporary, length)); } } } FileBuffer();  FileBuffer(final Local temporary); }
FileBuffer implements Buffer { @Override public void truncate(final Long length) { this.length = length; if(temporary.exists()) { try { final RandomAccessFile file = random(); if(length < file.length()) { file.setLength(length); } } catch(IOException e) { log.warn(String.format("Failure truncating file %s to %d", temporary, length)); } } } 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 void truncate(final Long length) { this.length = length; if(temporary.exists()) { try { final RandomAccessFile file = random(); if(length < file.length()) { file.setLength(length); } } catch(IOException e) { log.warn(String.format("Failure truncating file %s to %d", temporary, length)); } } } 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();  }