@Override public StoreChannel truncate( long size ) throws IOException { return delegateChannel.truncate( size ); }
@Override public StoreChannel truncate( long size ) throws IOException { delegate.truncate( size ); return this; }
@Override public StoreChannel truncate( long size ) throws IOException { return delegate.truncate( offset( size ) ); }
private void truncate( long position ) { try { channel.truncate( position ); } catch ( IOException e ) { throw new UnderlyingStorageException( "Failed to truncate", e ); } }
@Override public LimitedFileChannel truncate( long l ) throws IOException { return new LimitedFileChannel( inner.truncate( l ), fs ); }
private void truncateAndRetryIfInterrupted( int attemptsLeft ) throws IOException { setCurrentFileSize( 0 ); try { channel( tokenFilePageId ).truncate( 0 ); } catch ( ClosedChannelException e ) { tryReopen( tokenFilePageId, e ); if ( attemptsLeft < 1 ) { throw new IOException( "IO failed due to interruption", e ); } boolean interrupted = Thread.interrupted(); truncateAndRetryIfInterrupted( attemptsLeft - 1 ); if ( interrupted ) { Thread.currentThread().interrupt(); } } }
@Override public StoreFileChannel truncate( long size ) throws IOException { adversary.injectFailure( IOException.class ); return (StoreFileChannel) delegate.truncate( size ); }
channel.truncate( 0 ); ByteBuffer buffer = ByteBuffer.allocate( HEADER_SIZE ); buffer.put( CLEAN_GENERATOR ).putLong( highId ).flip();
@Test void truncate() throws Exception { long size = 256; channel.truncate( size ); verify( actual ).truncate( size + offset ); }
@Test( expected = ClosedByInterruptException.class ) public void ch_truncate() throws IOException { chan( true ).truncate( 0 ); }
channel.truncate( writePosition );
private File[] buildFileNames() throws IOException { String s = "abcdefghijklmnopqrstuvwxyz"; File[] files = new File[s.length()]; TestDirectory testDirectory = TestDirectory.testDirectory( RandomPageCacheTestHarness.class, fs ); File base = testDirectory.prepareDirectoryForTest( "random-pagecache-test-harness" ); for ( int i = 0; i < s.length(); i++ ) { files[i] = new File( base, s.substring( i, i + 1 ) ).getCanonicalFile(); fs.mkdirs( files[i].getParentFile() ); StoreChannel channel = fs.open( files[i], OpenMode.READ_WRITE ); channel.truncate( 0 ); channel.close(); } return files; }
private void copyFile( File from, FileSystemAbstraction fromFs, File to, ByteBuffer buffer ) throws IOException { try ( StoreChannel source = fromFs.open( from, OpenMode.READ ); StoreChannel sink = this.open( to, OpenMode.READ_WRITE ) ) { sink.truncate( 0 ); for ( int available; (available = (int) (source.size() - source.position())) > 0; ) { buffer.clear(); buffer.limit( min( available, buffer.capacity() ) ); source.read( buffer ); buffer.flip(); sink.write( buffer ); } } }
private void removeLastCheckpointRecordFromLastLogFile() throws IOException { LogPosition checkpointPosition = null; LogFile transactionLogFile = logFiles.getLogFile(); VersionAwareLogEntryReader<ReadableLogChannel> entryReader = new VersionAwareLogEntryReader<>(); LogPosition startPosition = LogPosition.start( logFiles.getHighestLogVersion() ); try ( ReadableLogChannel reader = transactionLogFile.getReader( startPosition ) ) { LogEntry logEntry; do { logEntry = entryReader.readLogEntry( reader ); if ( logEntry instanceof CheckPoint ) { checkpointPosition = ((CheckPoint) logEntry).getLogPosition(); } } while ( logEntry != null ); } if ( checkpointPosition != null ) { try ( StoreChannel storeChannel = fileSystemRule.open( logFiles.getHighestLogFile(), OpenMode.READ_WRITE ) ) { storeChannel.truncate( checkpointPosition.getByteOffset() ); } } }
channel.truncate( 16 * 4 );
@Override public StoreChannel truncate( long size ) throws IOException { return delegateChannel.truncate( size ); }
@Override public StoreChannel truncate( long size ) throws IOException { return delegate.truncate( offset( size ) ); }
@Override public LimitedFileChannel truncate( long l ) throws IOException { return new LimitedFileChannel( inner.truncate( l ), fs ); }
private void truncate( long position ) { try { channel.truncate( position ); } catch ( IOException e ) { throw new UnderlyingStorageException( "Failed to truncate", e ); } }
private void truncateAndRetryIfInterrupted( int attemptsLeft ) throws IOException { setCurrentFileSize( 0 ); try { channel( tokenFilePageId ).truncate( 0 ); } catch ( ClosedChannelException e ) { tryReopen( tokenFilePageId, e ); if ( attemptsLeft < 1 ) { throw new IOException( "IO failed due to interruption", e ); } boolean interrupted = Thread.interrupted(); truncateAndRetryIfInterrupted( attemptsLeft - 1 ); if ( interrupted ) { Thread.currentThread().interrupt(); } } }