private StoreChannel openLogFileChannel( File file, OpenMode mode ) throws IOException { return fileSystem.open( file, mode ); }
@Override public StoreChannel open( File fileName, OpenMode openMode ) throws IOException { return fs.open( fileName, openMode ); }
public static LogHeader readLogHeader( FileSystemAbstraction fileSystem, File file, boolean strict ) throws IOException { try ( StoreChannel channel = fileSystem.open( file, OpenMode.READ ) ) { return readLogHeader( ByteBuffer.allocate( LOG_HEADER_SIZE ), channel, strict, file ); } }
static long readHighId( FileSystemAbstraction fileSystem, File file ) throws IOException { try ( StoreChannel channel = fileSystem.open( file, OpenMode.READ ) ) { return readAndValidate( channel, file ); } }
public static void writeLogHeader( FileSystemAbstraction fileSystem, File file, long logVersion, long previousLastCommittedTxId ) throws IOException { try ( StoreChannel channel = fileSystem.open( file, OpenMode.READ_WRITE ) ) { writeLogHeader( channel, logVersion, previousLastCommittedTxId ); } }
@Override public StoreChannel open( File fileName, OpenMode openMode ) throws IOException { return delegate.open( fileName, openMode ); }
private StoreChannel chan( boolean channelShouldBeClosed ) throws IOException { this.channelShouldBeClosed = channelShouldBeClosed; channel = fs.open( file, OpenMode.READ_WRITE ); return channel; }
private PhysicalFlushableChannel instantiateChannel() throws IOException { return new PhysicalFlushableChannel( fs.open( file, OpenMode.READ_WRITE ) ); }
private void create( File file, FileSystemAbstraction fileSystem, long indexVersion ) throws IOException { if ( fileSystem.fileExists( file ) && fileSystem.getFileSize( file ) > 0 ) { throw new IllegalArgumentException( file + " already exist" ); } try ( StoreChannel fileChannel = fileSystem.open( file, OpenMode.READ_WRITE ) ) { write( fileChannel, System.currentTimeMillis(), random.nextLong(), 0, 1, indexVersion ); } }
static long readDefragCount( FileSystemAbstraction fileSystem, File file ) throws IOException { try ( StoreChannel channel = fileSystem.open( file, OpenMode.READ ) ) { return FreeIdKeeper.countFreeIds( new OffsetChannel( channel, HEADER_SIZE ) ); } }
@Override public StoreChannel open( File fileName, OpenMode openMode ) throws IOException { return chooseFileSystem( fileName ).open( fileName, openMode ); }
protected void verifyRecordsInFile( File file, int recordCount ) throws IOException { try ( StoreChannel channel = fs.open( file, OpenMode.READ ) ) { verifyRecordsInFile( channel, recordCount ); } }
protected void generateFileWithRecords( File file, int recordCount, int recordSize ) throws IOException { try ( StoreChannel channel = fs.open( file, OpenMode.READ_WRITE ) ) { generateFileWithRecords( channel, recordCount, recordSize ); } }
private String readFailure( File failureFile ) throws IOException { try ( StoreChannel channel = fs.open( failureFile, OpenMode.READ ) ) { byte[] data = new byte[(int) channel.size()]; channel.readAll( ByteBuffer.wrap( data ) ); return UTF8.decode( withoutZeros( data ) ); } }
private boolean isFailed( File failureFile ) throws IOException { try ( StoreChannel channel = fs.open( failureFile, OpenMode.READ ) ) { byte[] data = new byte[(int) channel.size()]; channel.readAll( ByteBuffer.wrap( data ) ); channel.close(); return !allZero( data ); } }
private ByteBuffer readIntoBuffer( String fileName ) throws IOException { ByteBuffer buffer = ByteBuffer.allocate( 16 ); try ( StoreChannel channel = fs.open( file( fileName ), OpenMode.READ ) ) { channel.readAll( buffer ); } buffer.flip(); return buffer; }
@Override public StoreChannel open( File fileName, OpenMode openMode ) throws IOException { adversary.injectFailure( FileNotFoundException.class, IOException.class, SecurityException.class ); return AdversarialFileChannel.wrap( (StoreFileChannel) delegate.open( fileName, openMode ), adversary ); }
@Test public void shouldReturnOldChannelWhenThereIsNoNextChannel() throws IOException { // given final ReaderLogVersionBridge bridge = new ReaderLogVersionBridge( logFiles ); when( channel.getVersion() ).thenReturn( version ); when( fs.open( any( File.class ), eq( OpenMode.READ ) ) ).thenThrow( new FileNotFoundException() ); // when final LogVersionedStoreChannel result = bridge.next( channel ); // then assertEquals( channel, result ); verify( channel, never() ).close(); }
static void changeVersionNumber( FileSystemAbstraction fileSystem, File storeFile, String versionString ) throws IOException { byte[] versionBytes = UTF8.encode( versionString ); try ( StoreChannel fileChannel = fileSystem.open( storeFile, OpenMode.READ_WRITE ) ) { fileChannel.position( fileSystem.getFileSize( storeFile ) - versionBytes.length ); fileChannel.write( ByteBuffer.wrap( versionBytes ) ); } }
public static List<LogEntry> logEntries( FileSystemAbstraction fileSystem, String logPath ) throws IOException { File logFile = new File( logPath ); StoreChannel fileChannel = fileSystem.open( logFile, OpenMode.READ ); // Always a header LogHeader header = readLogHeader( ByteBuffer.allocate( LOG_HEADER_SIZE ), fileChannel, true, logFile ); // Read all log entries PhysicalLogVersionedStoreChannel versionedStoreChannel = new PhysicalLogVersionedStoreChannel( fileChannel, header.logVersion, header.logFormatVersion ); ReadableLogChannel logChannel = new ReadAheadLogChannel( versionedStoreChannel ); LogEntryCursor logEntryCursor = new LogEntryCursor( new VersionAwareLogEntryReader<>(), logChannel ); return Iterables.asList( new IOCursorAsResourceIterable<>( logEntryCursor ) ); }