Search in sources :

Example 11 with TupleFileReader

use of org.bboxdb.tools.TupleFileReader in project bboxdb by jnidzwetzki.

the class TestTupleBuilder method testTupleFile4.

/**
 * Test the tuple file builder - Read 5 of 3 lines
 * @throws IOException
 */
@Test
public void testTupleFile4() throws IOException {
    final File tempFile = File.createTempFile("temp", ".txt");
    tempFile.deleteOnExit();
    // The reference tuple
    final TupleBuilder tupleBuilder = TupleBuilderFactory.getBuilderForFormat(TupleBuilderFactory.Name.GEOJSON);
    final Tuple tuple = tupleBuilder.buildTuple("1", GEO_JSON_LINE);
    final BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
    writer.write(GEO_JSON_LINE);
    writer.write("\n");
    writer.write(GEO_JSON_LINE);
    writer.write("\n");
    writer.write(GEO_JSON_LINE);
    writer.write("\n");
    writer.close();
    final TupleFileReader tupleFile = new TupleFileReader(tempFile.getAbsolutePath(), TupleBuilderFactory.Name.GEOJSON);
    final AtomicInteger seenTuples = new AtomicInteger(0);
    tupleFile.addTupleListener(t -> {
        Assert.assertEquals(tuple.getBoundingBox(), t.getBoundingBox());
        Assert.assertArrayEquals(tuple.getDataBytes(), t.getDataBytes());
        seenTuples.incrementAndGet();
    });
    tupleFile.processFile(3);
    Assert.assertEquals(3, seenTuples.get());
}
Also used : TupleBuilder(org.bboxdb.tools.converter.tuple.TupleBuilder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FileWriter(java.io.FileWriter) TupleFileReader(org.bboxdb.tools.TupleFileReader) File(java.io.File) Tuple(org.bboxdb.storage.entity.Tuple) BufferedWriter(java.io.BufferedWriter) Test(org.junit.Test)

Aggregations

TupleFileReader (org.bboxdb.tools.TupleFileReader)11 IOException (java.io.IOException)6 BoundingBox (org.bboxdb.commons.math.BoundingBox)5 File (java.io.File)4 ArrayList (java.util.ArrayList)4 Tuple (org.bboxdb.storage.entity.Tuple)4 Test (org.junit.Test)4 BufferedWriter (java.io.BufferedWriter)3 FileWriter (java.io.FileWriter)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 TupleBuilder (org.bboxdb.tools.converter.tuple.TupleBuilder)3 Arrays (java.util.Arrays)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Objects (java.util.Objects)2 Collectors (java.util.stream.Collectors)2 BBoxDBException (org.bboxdb.misc.BBoxDBException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1