ReadOnlyIdGenerator( LongSupplier highId, FileSystemAbstraction fs, File filename ) { if ( fs != null && fs.fileExists( filename ) ) { try { this.highId = IdGeneratorImpl.readHighId( fs, filename ); defragCount = IdGeneratorImpl.readDefragCount( fs, filename ); } catch ( IOException e ) { throw new UnderlyingStorageException( "Failed to read id counts of the id file: " + filename, e ); } } else { this.highId = highId.getAsLong(); defragCount = 0; } }
@Test public void shouldReadHighIdUsingStaticMethod() throws Exception { // GIVEN long highId = 12345L; IdGeneratorImpl.createGenerator( fsr.get(), file, highId, false ); // WHEN long readHighId = IdGeneratorImpl.readHighId( fsr.get(), file ); // THEN assertEquals( highId, readHighId ); }
private void clearIdFiles( FileSystemAbstraction fileSystem, Path targetDirectory ) throws IOException { File dir = targetDirectory.toFile(); for ( File file : fileSystem.listFiles( dir ) ) { if ( !fileSystem.isDirectory( file ) && file.getName().endsWith( ".id" ) ) { long highId = IdGeneratorImpl.readHighId( fileSystem, file ); fileSystem.deleteFile( file ); IdGeneratorImpl.createGenerator( fileSystem, file, highId, true ); } } }
public void clearIdFiles( Path backupLocation ) throws IOException { IOException exception = null; File targetDirectory = backupLocation.toFile(); File[] files = fs.listFiles( targetDirectory ); for ( File file : files ) { if ( !fs.isDirectory( file ) && file.getName().endsWith( ".id" ) ) { try { long highId = IdGeneratorImpl.readHighId( fs, file ); fs.deleteFile( file ); IdGeneratorImpl.createGenerator( fs, file, highId, true ); } catch ( IOException e ) { exception = Exceptions.chain( exception, e ); } } } if ( exception != null ) { throw exception; } }
ReadOnlyIdGenerator( LongSupplier highId, FileSystemAbstraction fs, File filename ) { if ( fs != null && fs.fileExists( filename ) ) { try { this.highId = IdGeneratorImpl.readHighId( fs, filename ); defragCount = IdGeneratorImpl.readDefragCount( fs, filename ); } catch ( IOException e ) { throw new UnderlyingStorageException( "Failed to read id counts of the id file: " + filename, e ); } } else { this.highId = highId.getAsLong(); defragCount = 0; } }