@Override protected FileBasedSource<String> createForSubrangeOfFile( MatchResult.Metadata metadata, long start, long end) { return new TextSource(metadata, start, end, delimiter); }
@Test public void testProgressEmptyFile() throws IOException { try (BoundedSource.BoundedReader<String> reader = prepareSource(new byte[0]).createReader(PipelineOptionsFactory.create())) { // Check preconditions before starting. assertEquals(0.0, reader.getFractionConsumed(), 1e-6); assertEquals(0, reader.getSplitPointsConsumed()); assertEquals( BoundedSource.BoundedReader.SPLIT_POINTS_UNKNOWN, reader.getSplitPointsRemaining()); // Assert empty assertFalse(reader.start()); // Check postconditions after finishing assertEquals(1.0, reader.getFractionConsumed(), 1e-6); assertEquals(0, reader.getSplitPointsConsumed()); assertEquals(0, reader.getSplitPointsRemaining()); } }
try (BoundedSource.BoundedReader<String> reader = prepareSource(file.getBytes(Charsets.UTF_8)) .createReader(PipelineOptionsFactory.create())) {
@Override public FileBasedSource<String> apply(String input) { return new TextSource( StaticValueProvider.of(input), EmptyMatchTreatment.DISALLOW, delimiter); } }
private static TextSource prepareSource( TemporaryFolder temporaryFolder, byte[] data, byte[] delimiter) throws IOException { Path path = temporaryFolder.newFile().toPath(); Files.write(path, data); return new TextSource( ValueProvider.StaticValueProvider.of(path.toString()), EmptyMatchTreatment.DISALLOW, delimiter); }
protected FileBasedSource<String> getSource() { return CompressedSource.from( new TextSource( getFilepattern(), getMatchConfiguration().getEmptyMatchTreatment(), getDelimiter())) .withCompression(getCompression()); }