/** * Creates a reader that reads from beginning of file * * @param file file to read * @return * @throws IOException */ private FileReader createFileReader(Path file) throws IOException { if (readerType.equalsIgnoreCase(Configs.SEQ)) { return new SequenceFileReader(this.hdfs, file, conf); } if (readerType.equalsIgnoreCase(Configs.TEXT)) { return new TextFileReader(this.hdfs, file, conf); } try { Class<?> clsType = Class.forName(readerType); Constructor<?> constructor = clsType.getConstructor(FileSystem.class, Path.class, Map.class); return (FileReader) constructor.newInstance(this.hdfs, file, conf); } catch (Exception e) { LOG.error(e.getMessage(), e); throw new RuntimeException("Unable to instantiate " + readerType + " reader", e); } }
/** * Creates a reader that starts reading from 'offset' * * @param file the file to read * @param offset the offset string should be understandable by the reader type being used * @return * @throws IOException */ private FileReader createFileReader(Path file, String offset) throws IOException { if (readerType.equalsIgnoreCase(Configs.SEQ)) { return new SequenceFileReader(this.hdfs, file, conf, offset); } if (readerType.equalsIgnoreCase(Configs.TEXT)) { return new TextFileReader(this.hdfs, file, conf, offset); } try { Class<?> clsType = Class.forName(readerType); Constructor<?> constructor = clsType.getConstructor(FileSystem.class, Path.class, Map.class, String.class); return (FileReader) constructor.newInstance(this.hdfs, file, conf, offset); } catch (Exception e) { LOG.error(e.getMessage(), e); throw new RuntimeException("Unable to instantiate " + readerType, e); } }
TextFileReader reader = new TextFileReader(fs, file, null); FileOffset pos0 = tracker.getCommitPosition(); Assert.assertNull(pos0);
/** * Creates a reader that reads from beginning of file * * @param file file to read * @return * @throws IOException */ private FileReader createFileReader(Path file) throws IOException { if (readerType.equalsIgnoreCase(Configs.SEQ)) { return new SequenceFileReader(this.hdfs, file, conf); } if (readerType.equalsIgnoreCase(Configs.TEXT)) { return new TextFileReader(this.hdfs, file, conf); } try { Class<?> clsType = Class.forName(readerType); Constructor<?> constructor = clsType.getConstructor(FileSystem.class, Path.class, Map.class); return (FileReader) constructor.newInstance(this.hdfs, file, conf); } catch (Exception e) { LOG.error(e.getMessage(), e); throw new RuntimeException("Unable to instantiate " + readerType + " reader", e); } }
/** * Creates a reader that starts reading from 'offset' * * @param file the file to read * @param offset the offset string should be understandable by the reader type being used * @return * @throws IOException */ private FileReader createFileReader(Path file, String offset) throws IOException { if (readerType.equalsIgnoreCase(Configs.SEQ)) { return new SequenceFileReader(this.hdfs, file, conf, offset); } if (readerType.equalsIgnoreCase(Configs.TEXT)) { return new TextFileReader(this.hdfs, file, conf, offset); } try { Class<?> clsType = Class.forName(readerType); Constructor<?> constructor = clsType.getConstructor(FileSystem.class, Path.class, Map.class, String.class); return (FileReader) constructor.newInstance(this.hdfs, file, conf, offset); } catch (Exception e) { LOG.error(e.getMessage(), e); throw new RuntimeException("Unable to instantiate " + readerType, e); } }
public class ViewController implements Initializable { @FXML private TextField urlTextField; @FXML private TextArea linesTextArea; private static final Logger LOG = Logger.getLogger(ViewController.class.getName()); private Future<List<String>> future; private ExecutorService executorService = Executors.newSingleThreadExecutor(); private TextFileReader reader = new TextFileReader(); public void initialize(URL url, ResourceBundle rb) { } @FXML @SuppressWarnings("NestedAssignment") public void showFileLines() throws InterruptedException, ExecutionException { future = executorService.submit(new Callable<List<String>>() { public List<String> call() throws Exception { return reader.read(new File(ViewController.this.urlTextField.getText())); } }); List<String> lines = future.get(); executorService.shutdownNow(); linesTextArea.clear(); for (String line : lines ) { linesTextArea.appendText(line + "\n"); } } }