TSDBReader implements Closeable { @Nullable public synchronized Either<TableDef, DataBlock> read() throws IOException { final long position = bis.getCount(); if (position >= size) { return null; } Object result; try { result = recordReader.read(null, decoder); } catch (IOException | RuntimeException ex) { if (CORUPTION_LENIENT) { return null; } else { throw new IOException("Error reading tsdb file at " + position + ", this= " + this, ex); } } if (result instanceof TableDef) { final TableDef td = (TableDef) result; long tdId = td.getId(); if (position != tdId) { throw new IOException("Table Id should be equal with file position " + position + ", " + tdId); } return Either.left(td); } else { return Either.right((DataBlock) result); } } TSDBReader(final File file, final int bufferSize);  TSDBReader(final File file, final int bufferSize, final long from); synchronized boolean reReadSize(); @Nullable synchronized Either<TableDef, DataBlock> read(); @Override synchronized void close(); synchronized long getSize(); Header getHeader(); void stopWatching(); synchronized Future<Void> bgWatch(
          final Handler<Either<TableDef, DataBlock>, E> handler,
          final EventSensitivity es); synchronized Future<Void> bgWatch(
          final Handler<Either<TableDef, DataBlock>, E> handler,
          final EventSensitivity es, final long timeout, final TimeUnit unit); synchronized Future<Void> bgWatch(
          final Handler<Either<TableDef, DataBlock>, E> handler,
          final EventSensitivity es, final long deadlineNanos); void watch(final Handler<Either<TableDef, DataBlock>, E> handler,
          final EventSensitivity es); void watch(final Handler<Either<TableDef, DataBlock>, E> handler,
          final EventSensitivity es, final long timeout, final TimeUnit unit); @SuppressFBWarnings("NOS_NON_OWNED_SYNCHRONIZATION") void watch(final Handler<Either<TableDef, DataBlock>, E> handler,
          final EventSensitivity es, final long deadlineNanos); synchronized void readAll(final Handler<Either<TableDef, DataBlock>, E> handler,
          final long deadlineNanos); synchronized void readAll(final Consumer<Either<TableDef, DataBlock>> consumer); @Override String toString();  }
@Test @SuppressFBWarnings({"RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", "RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE", "NP_LOAD_OF_KNOWN_NULL_VALUE", "CLI_CONSTANT_LIST_INDEX"}) @SuppressWarnings("checkstyle:EmptyBlock") public void testTsdb() throws IOException { File testFile = File.createTempFile("test", ".tsdb2"); long tableId; try (TSDBWriter writer = new TSDBWriter(testFile, 4, "test", false)) { } try (TSDBWriter writer = new TSDBWriter(testFile, 4, "test", false)) { tableId = writer.writeTableDef(tableDef); final long time = System.currentTimeMillis(); writer.writeDataRow(tableId, time, 0, 1, 2); writer.writeDataRow(tableId, time + 10, 1, 1, 2); writer.writeDataRow(tableId, time + 20, 2, 1, 2); writer.writeDataRow(tableId, time + 30, 3, 1, 2); writer.writeDataRow(tableId, time + 40, 4, 1, 2); } try (TSDBReader reader = new TSDBReader(testFile, 1024)) { Either<TableDef, DataBlock> read; while ((read = reader.read()) != null) { LOG.debug("TSDB block: {}", read); } } ListMultimap<String, TableDef> allTables = TSDBQuery.getAllTables(testFile); Assert.assertEquals(1, allTables.size()); Assert.assertTrue(allTables.containsKey(tableDef.getName())); TimeSeries timeSeries = TSDBQuery.getTimeSeries(testFile, new long[]{tableId}, 0, Long.MAX_VALUE); Assert.assertEquals(2L, timeSeries.getValues()[2][0]); }