public static List<String> readFromFile( FileSystemAbstraction fs, File file ) throws IOException { ArrayList<String> lines = new ArrayList<>(); try ( BufferedReader r = new BufferedReader( fs.openAsReader( file, UTF_8 ) ) ) { while ( true ) { String line = r.readLine(); if ( line == null ) { break; } lines.add( line ); } } return lines; }
@Override public Reader openAsReader( File fileName, Charset charset ) throws IOException { return fs.openAsReader( fileName, charset ); }
@Override public Reader openAsReader( File fileName, Charset charset ) throws IOException { return delegate.openAsReader( fileName, charset ); }
private static long[] readTxLogCounters( FileSystemAbstraction fs, File file, int numberOfCounters ) throws IOException { try ( BufferedReader reader = new BufferedReader( fs.openAsReader( file, StandardCharsets.UTF_8 ) ) ) { String line = reader.readLine(); String[] split = StringUtils.split( line, TX_LOG_COUNTERS_SEPARATOR ); if ( split.length != numberOfCounters ) { throw new IllegalArgumentException( "Unexpected number of tx counters '" + numberOfCounters + "', file contains: '" + line + "'" ); } long[] counters = new long[numberOfCounters]; for ( int i = 0; i < split.length; i++ ) { counters[i] = Long.parseLong( split[i] ); } return counters; } }
private static void loadPersistedSettings( Properties settings, PartitionedIndexStorage indexStorage, FileSystemAbstraction fs ) { File settingsFile = new File( indexStorage.getIndexFolder(), INDEX_CONFIG_FILE ); if ( fs.fileExists( settingsFile ) ) { try ( Reader reader = fs.openAsReader( settingsFile, StandardCharsets.UTF_8 ) ) { settings.load( reader ); } catch ( IOException e ) { throw new UncheckedIOException( "Failed to read persisted fulltext index properties: " + settingsFile, e ); } } }
private static Pair<String, String> readFromFile( FileSystemAbstraction fs, File file, MigrationStatus expectedSate ) { try ( BufferedReader reader = new BufferedReader( fs.openAsReader( file, StandardCharsets.UTF_8 ) ) ) { String state = reader.readLine().trim(); if ( expectedSate != null && !expectedSate.name().equals( state ) ) { throw new IllegalStateException( "Not in the expected state, expected=" + expectedSate.name() + ", actual=" + state ); } String info = reader.readLine().trim(); return Pair.of( state, info ); } catch ( FileNotFoundException e ) { return null; } catch ( IOException e ) { throw new RuntimeException( e ); } }
@Override public Reader openAsReader( File fileName, Charset charset ) throws IOException { return chooseFileSystem( fileName ).openAsReader( fileName, charset ); }
@Override public Reader openAsReader( File fileName, Charset charset ) throws IOException { adversary.injectFailure( UnsupportedEncodingException.class, FileNotFoundException.class, SecurityException.class ); return new AdversarialReader( delegate.openAsReader( fileName, charset ), adversary ); }
public static List<String> readFromFile( FileSystemAbstraction fs, File file ) throws IOException { ArrayList<String> lines = new ArrayList<>(); try ( BufferedReader r = new BufferedReader( fs.openAsReader( file, UTF_8 ) ) ) { while ( true ) { String line = r.readLine(); if ( line == null ) { break; } lines.add( line ); } } return lines; }
private static long[] readTxLogCounters( FileSystemAbstraction fs, File file, int numberOfCounters ) throws IOException { try ( BufferedReader reader = new BufferedReader( fs.openAsReader( file, StandardCharsets.UTF_8 ) ) ) { String line = reader.readLine(); String[] split = StringUtils.split( line, TX_LOG_COUNTERS_SEPARATOR ); if ( split.length != numberOfCounters ) { throw new IllegalArgumentException( "Unexpected number of tx counters '" + numberOfCounters + "', file contains: '" + line + "'" ); } long[] counters = new long[numberOfCounters]; for ( int i = 0; i < split.length; i++ ) { counters[i] = Long.parseLong( split[i] ); } return counters; } }
private static Pair<String, String> readFromFile( FileSystemAbstraction fs, File file, MigrationStatus expectedSate ) { try ( BufferedReader reader = new BufferedReader( fs.openAsReader( file, StandardCharsets.UTF_8 ) ) ) { String state = reader.readLine().trim(); if ( expectedSate != null && !expectedSate.name().equals( state ) ) { throw new IllegalStateException( "Not in the expected state, expected=" + expectedSate.name() + ", actual=" + state ); } String info = reader.readLine().trim(); return Pair.of( state, info ); } catch ( FileNotFoundException e ) { return null; } catch ( IOException e ) { throw new RuntimeException( e ); } }