protected StoreFileChannel getStoreFileChannel( FileChannel channel ) { return new StoreFileChannel( channel ); }
@Override public StoreChannel open( File fileName, OpenMode openMode ) throws IOException { return new StoreFileChannel( FileUtils.open( path( fileName ), openMode ) ); }
@Test void shouldHandlePartialWrites() throws Exception { // Given FileChannel mockChannel = mock(FileChannel.class); when(mockChannel.write( any(ByteBuffer.class), anyLong() )).thenReturn( 4 ); ByteBuffer buffer = ByteBuffer.wrap( "Hello, world!".getBytes( StandardCharsets.UTF_8 ) ); StoreFileChannel channel = new StoreFileChannel( mockChannel ); // When channel.writeAll( buffer, 20 ); // Then verify( mockChannel ).write( buffer, 20 ); verify( mockChannel ).write( buffer, 24 ); verify( mockChannel ).write( buffer, 28 ); verify( mockChannel ).write( buffer, 32 ); verifyNoMoreInteractions( mockChannel ); } }
@Override public synchronized StoreChannel create( File fileName ) throws IOException { File parentFile = fileName.getParentFile(); if ( parentFile != null /*means that this is the 'default location'*/ && !fileExists( parentFile ) ) { throw new FileNotFoundException( "'" + fileName + "' (The system cannot find the path specified)" ); } EphemeralFileData data = files.computeIfAbsent( canonicalFile( fileName ), key -> new EphemeralFileData( clock ) ); return new StoreFileChannel( new EphemeralFileChannel( data, new FileStillOpenException( fileName.getPath() ) ) ); }
@Override public synchronized StoreChannel open( File fileName, OpenMode openMode ) throws IOException { EphemeralFileData data = files.get( canonicalFile( fileName ) ); if ( data != null ) { return new StoreFileChannel( new EphemeralFileChannel( data, new FileStillOpenException( fileName.getPath() ) ) ); } return create( fileName ); }
protected StoreFileChannel getStoreFileChannel( FileChannel channel ) { return new StoreFileChannel( channel ); }
@Override public StoreChannel open( File fileName, OpenMode openMode ) throws IOException { return new StoreFileChannel( FileUtils.open( path( fileName ), openMode ) ); }