| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
package org.crosswire.jsword.examples; |
| 21 | |
|
| 22 | |
import java.util.List; |
| 23 | |
|
| 24 | |
import org.crosswire.jsword.book.Book; |
| 25 | |
import org.crosswire.jsword.book.BookData; |
| 26 | |
import org.crosswire.jsword.book.BookException; |
| 27 | |
import org.crosswire.jsword.book.BookFilter; |
| 28 | |
import org.crosswire.jsword.book.Books; |
| 29 | |
import org.crosswire.jsword.passage.Key; |
| 30 | |
import org.slf4j.Logger; |
| 31 | |
import org.slf4j.LoggerFactory; |
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
public final class ReadEverything { |
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | 0 | private ReadEverything() { |
| 44 | 0 | } |
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
public static void main(String[] args) { |
| 51 | |
|
| 52 | |
|
| 53 | 0 | log.warn("*** Reading all installed Bibles"); |
| 54 | 0 | BookFilter filter = null; |
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | 0 | List<Book> books = getBooks(filter); |
| 61 | 0 | for (Book book : books) { |
| 62 | 0 | if (book.isLocked()) { |
| 63 | 0 | log.warn("****** Skipping: [{}] {} ({})", book.getInitials(), book.getName(), book.getBookCategory()); |
| 64 | 0 | continue; |
| 65 | |
} |
| 66 | 0 | log.warn("****** Reading: [{}] {} ({})", book.getInitials(), book.getName(), book.getBookCategory()); |
| 67 | 0 | Key set = book.getGlobalKeyList(); |
| 68 | 0 | testReadMultiple(book, set); |
| 69 | 0 | } |
| 70 | 0 | } |
| 71 | |
|
| 72 | |
private static List<Book> getBooks(BookFilter filter) { |
| 73 | 0 | if (filter == null) { |
| 74 | 0 | return Books.installed().getBooks(); |
| 75 | |
} |
| 76 | 0 | return Books.installed().getBooks(filter); |
| 77 | |
} |
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
private static void testReadMultiple(Book book, Key set) { |
| 83 | |
|
| 84 | 0 | long start = System.currentTimeMillis(); |
| 85 | 0 | int entries = 0; |
| 86 | 0 | count = 0; |
| 87 | 0 | boolean first = true; |
| 88 | 0 | for (Key key : set) { |
| 89 | |
|
| 90 | 0 | if (first) { |
| 91 | 0 | first = false; |
| 92 | 0 | if (key.getName().length() == 0) { |
| 93 | 0 | continue; |
| 94 | |
} |
| 95 | |
} |
| 96 | 0 | testReadSingle(book, key, entries); |
| 97 | |
|
| 98 | 0 | entries++; |
| 99 | |
} |
| 100 | |
|
| 101 | 0 | long end = System.currentTimeMillis(); |
| 102 | 0 | float time = (end - start) / 1000F; |
| 103 | |
|
| 104 | 0 | if (count > 0) { |
| 105 | 0 | log.info("Tested: book={} entries={} time={}s errors={} ({}ms per entry)", book.getInitials(), Integer.toString(entries), Float.toString(time), Integer.toString(count), Float.toString(1000 * time / entries)); |
| 106 | |
} else { |
| 107 | 0 | log.info("Tested: book={} entries={} time={}s ({}ms per entry)", book.getInitials(), Integer.toString(entries), Float.toString(time), Float.toString(1000 * time / entries)); |
| 108 | |
} |
| 109 | 0 | } |
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
private static void testReadSingle(Book book, Key key, int entry) { |
| 115 | 0 | Throwable oops = null; |
| 116 | |
try { |
| 117 | 0 | log.debug("reading: {}/{}:{}", book.getInitials(), Integer.toString(entry), key.getName()); |
| 118 | |
|
| 119 | 0 | BookData data = new BookData(book, key); |
| 120 | 0 | if (data.getOsisFragment() == null) { |
| 121 | 0 | log.warn("No output from: {},{}", book.getInitials(), key.getOsisID()); |
| 122 | |
} |
| 123 | |
|
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | 0 | } catch (BookException ex) { |
| 128 | 0 | oops = ex; |
| 129 | 0 | } |
| 130 | 0 | if (oops != null) { |
| 131 | 0 | ++count; |
| 132 | 0 | if (count < 5) { |
| 133 | 0 | log.error("Unexpected error reading: {}, {}, {}, {}", book.getInitials(), Integer.toString(entry), key.getOsisID(), key.getClass().getName(), oops); |
| 134 | |
} |
| 135 | |
} |
| 136 | 0 | } |
| 137 | |
|
| 138 | |
private static int count; |
| 139 | |
|
| 140 | |
|
| 141 | |
|
| 142 | |
|
| 143 | 0 | private static final Logger log = LoggerFactory.getLogger(ReadEverything.class); |
| 144 | |
} |