aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeil Fuller <nfuller@google.com>2023-11-21 18:39:17 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-11-21 18:39:17 +0000
commit2bfb3bb72797d57346425f9103f3fa65cc1b827d (patch)
tree72b70c45b03c53bc951528d86d2590256dcbfa48
parent7a63a189c8d52f2310497dc8b9b0559f34e4062b (diff)
parent3ab018db5fdb9db41c920dde5b8c18f93fbb24f9 (diff)
downloadGeoTZ-2bfb3bb72797d57346425f9103f3fa65cc1b827d.tar.gz
Move generic classes to com.android.storage am: a6d5c9e89b am: 3ab018db5f
Original change: https://android-review.googlesource.com/c/platform/packages/modules/GeoTZ/+/2841633 Change-Id: Iceeb91ed03bf9498d4dbdd28be7103898677f19a Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--README.md11
-rw-r--r--s2storage/Android.bp27
-rw-r--r--s2storage/README.md183
-rw-r--r--s2storage/src/readonly/java/com/android/storage/block/read/Block.java (renamed from s2storage/src/readonly/java/com/android/timezone/location/storage/block/read/Block.java)4
-rw-r--r--s2storage/src/readonly/java/com/android/storage/block/read/BlockData.java (renamed from s2storage/src/readonly/java/com/android/timezone/location/storage/block/read/BlockData.java)7
-rw-r--r--s2storage/src/readonly/java/com/android/storage/block/read/BlockFileReader.java (renamed from s2storage/src/readonly/java/com/android/timezone/location/storage/block/read/BlockFileReader.java)6
-rw-r--r--s2storage/src/readonly/java/com/android/storage/block/read/BlockInfo.java (renamed from s2storage/src/readonly/java/com/android/timezone/location/storage/block/read/BlockInfo.java)4
-rw-r--r--s2storage/src/readonly/java/com/android/storage/io/read/TypedInputStream.java (renamed from s2storage/src/readonly/java/com/android/timezone/location/storage/io/read/TypedInputStream.java)4
-rw-r--r--s2storage/src/readonly/java/com/android/storage/s2/S2CellOrdering.java (renamed from s2storage/src/readonly/java/com/android/timezone/location/storage/s2/S2CellOrdering.java)6
-rw-r--r--s2storage/src/readonly/java/com/android/storage/s2/S2LevelRange.java (renamed from s2storage/src/readonly/java/com/android/timezone/location/storage/s2/S2LevelRange.java)4
-rw-r--r--s2storage/src/readonly/java/com/android/storage/s2/S2Support.java (renamed from s2storage/src/readonly/java/com/android/timezone/location/storage/s2/S2Support.java)4
-rw-r--r--s2storage/src/readonly/java/com/android/storage/s2/SortedS2Ranges.java (renamed from s2storage/src/readonly/java/com/android/timezone/location/storage/s2/SortedS2Ranges.java)2
-rw-r--r--s2storage/src/readonly/java/com/android/storage/table/packed/read/BaseTypedPackedTable.java (renamed from s2storage/src/readonly/java/com/android/timezone/location/storage/table/packed/read/BaseTypedPackedTable.java)6
-rw-r--r--s2storage/src/readonly/java/com/android/storage/table/packed/read/IntValueTypedPackedTable.java (renamed from s2storage/src/readonly/java/com/android/timezone/location/storage/table/packed/read/IntValueTypedPackedTable.java)6
-rw-r--r--s2storage/src/readonly/java/com/android/storage/table/packed/read/PackedTableReader.java (renamed from s2storage/src/readonly/java/com/android/timezone/location/storage/table/packed/read/PackedTableReader.java)10
-rw-r--r--s2storage/src/readonly/java/com/android/storage/table/reader/IntValueTable.java (renamed from s2storage/src/readonly/java/com/android/timezone/location/storage/table/reader/IntValueTable.java)2
-rw-r--r--s2storage/src/readonly/java/com/android/storage/table/reader/LongValueTable.java (renamed from s2storage/src/readonly/java/com/android/timezone/location/storage/table/reader/LongValueTable.java)2
-rw-r--r--s2storage/src/readonly/java/com/android/storage/table/reader/Table.java (renamed from s2storage/src/readonly/java/com/android/timezone/location/storage/table/reader/Table.java)2
-rw-r--r--s2storage/src/readonly/java/com/android/storage/util/BitwiseUtils.java (renamed from s2storage/src/readonly/java/com/android/timezone/location/storage/util/BitwiseUtils.java)2
-rw-r--r--s2storage/src/readonly/java/com/android/storage/util/Conditions.java (renamed from s2storage/src/readonly/java/com/android/timezone/location/storage/util/Conditions.java)2
-rw-r--r--s2storage/src/readonly/java/com/android/storage/util/Visitor.java (renamed from s2storage/src/readonly/java/com/android/timezone/location/storage/util/Visitor.java)2
-rw-r--r--s2storage/src/test/java/com/android/storage/block/BlockFileTest.java (renamed from s2storage/src/test/java/com/android/timezone/location/storage/block/BlockFileTest.java)16
-rw-r--r--s2storage/src/test/java/com/android/storage/block/read/BlockDataTest.java (renamed from s2storage/src/test/java/com/android/timezone/location/storage/block/read/BlockDataTest.java)4
-rw-r--r--s2storage/src/test/java/com/android/storage/block/read/BlockInfoTest.java (renamed from s2storage/src/test/java/com/android/timezone/location/storage/block/read/BlockInfoTest.java)2
-rw-r--r--s2storage/src/test/java/com/android/storage/block/read/BlockMatcher.java (renamed from s2storage/src/test/java/com/android/timezone/location/storage/block/read/BlockMatcher.java)2
-rw-r--r--s2storage/src/test/java/com/android/storage/block/read/BlockTest.java (renamed from s2storage/src/test/java/com/android/timezone/location/storage/block/read/BlockTest.java)2
-rw-r--r--s2storage/src/test/java/com/android/storage/block/write/EmptyBlockWriterTest.java (renamed from s2storage/src/test/java/com/android/timezone/location/storage/block/write/EmptyBlockWriterTest.java)2
-rw-r--r--s2storage/src/test/java/com/android/storage/io/TypedStreamsTest.java (renamed from s2storage/src/test/java/com/android/timezone/location/storage/io/TypedStreamsTest.java)11
-rw-r--r--s2storage/src/test/java/com/android/storage/s2/S2CellOrderingTest.java (renamed from s2storage/src/test/java/com/android/timezone/location/storage/s2/S2CellOrderingTest.java)6
-rw-r--r--s2storage/src/test/java/com/android/storage/s2/S2LevelRangeTest.java (renamed from s2storage/src/test/java/com/android/timezone/location/storage/s2/S2LevelRangeTest.java)6
-rw-r--r--s2storage/src/test/java/com/android/storage/s2/S2SupportTest.java (renamed from s2storage/src/test/java/com/android/timezone/location/storage/s2/S2SupportTest.java)6
-rw-r--r--s2storage/src/test/java/com/android/storage/s2/SortedS2RangesTest.java (renamed from s2storage/src/test/java/com/android/timezone/location/storage/s2/SortedS2RangesTest.java)6
-rw-r--r--s2storage/src/test/java/com/android/storage/table/packed/IntValuePackedTableTest.java (renamed from s2storage/src/test/java/com/android/timezone/location/storage/table/packed/IntValuePackedTableTest.java)16
-rw-r--r--s2storage/src/test/java/com/android/storage/table/packed/PackedTableReaderWriterTest.java (renamed from s2storage/src/test/java/com/android/timezone/location/storage/table/packed/PackedTableReaderWriterTest.java)20
-rw-r--r--s2storage/src/test/java/com/android/storage/util/BitwiseUtilsTest.java (renamed from s2storage/src/test/java/com/android/timezone/location/storage/util/BitwiseUtilsTest.java)4
-rw-r--r--s2storage/src/test/java/com/android/storage/util/ConditionsTest.java (renamed from s2storage/src/test/java/com/android/timezone/location/storage/util/ConditionsTest.java)4
-rw-r--r--s2storage/src/testing/java/com/android/storage/testing/MoreAsserts.java (renamed from s2storage/src/test/java/com/android/timezone/location/storage/testing/MoreAsserts.java)4
-rw-r--r--s2storage/src/testing/java/com/android/storage/testing/TestSupport.java (renamed from s2storage/src/test/java/com/android/timezone/location/storage/testing/TestSupport.java)7
-rw-r--r--s2storage/src/write/java/com/android/storage/block/write/BlockFileWriter.java (renamed from s2storage/src/write/java/com/android/timezone/location/storage/block/write/BlockFileWriter.java)8
-rw-r--r--s2storage/src/write/java/com/android/storage/block/write/BlockWriter.java (renamed from s2storage/src/write/java/com/android/timezone/location/storage/block/write/BlockWriter.java)6
-rw-r--r--s2storage/src/write/java/com/android/storage/block/write/EmptyBlockWriter.java (renamed from s2storage/src/write/java/com/android/timezone/location/storage/block/write/EmptyBlockWriter.java)4
-rw-r--r--s2storage/src/write/java/com/android/storage/io/write/TypedOutputStream.java (renamed from s2storage/src/write/java/com/android/timezone/location/storage/io/write/TypedOutputStream.java)11
-rw-r--r--s2storage/src/write/java/com/android/storage/table/packed/write/PackedTableWriter.java (renamed from s2storage/src/write/java/com/android/timezone/location/storage/table/packed/write/PackedTableWriter.java)8
-rw-r--r--s2storage/tools/Android.bp40
-rw-r--r--s2storage/tools/src/java/com/android/storage/tools/block/DumpBlockFile.java (renamed from s2storage/tools/src/java/com/android/timezone/location/tools/block/DumpBlockFile.java)6
-rw-r--r--s2storage/tools/src/java/com/android/storage/tools/block/dump/BlockDumper.java (renamed from s2storage/tools/src/java/com/android/timezone/location/tools/block/dump/BlockDumper.java)4
-rw-r--r--s2storage/tools/src/java/com/android/storage/tools/block/dump/BlockFileDumper.java (renamed from s2storage/tools/src/java/com/android/timezone/location/tools/block/dump/BlockFileDumper.java)10
-rw-r--r--s2storage/tools/src/java/com/android/storage/tools/block/dump/BlockInfoDumper.java (renamed from s2storage/tools/src/java/com/android/timezone/location/tools/block/dump/BlockInfoDumper.java)4
-rw-r--r--s2storage/tools/src/java/com/android/storage/tools/block/dump/DumpUtils.java (renamed from s2storage/tools/src/java/com/android/timezone/location/tools/block/dump/DumpUtils.java)4
-rw-r--r--s2storage/tools/src/java/com/android/storage/tools/block/dump/SingleFileDumper.java (renamed from s2storage/tools/src/java/com/android/timezone/location/tools/block/dump/SingleFileDumper.java)6
-rw-r--r--tzs2storage/Android.bp65
-rw-r--r--tzs2storage/README.md208
-rw-r--r--tzs2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/BankedTzIdSets.java (renamed from s2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/BankedTzIdSets.java)0
-rw-r--r--tzs2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/SuffixTableRange.java (renamed from s2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/SuffixTableRange.java)6
-rw-r--r--tzs2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/SuffixTableSharedData.java (renamed from s2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/SuffixTableSharedData.java)6
-rw-r--r--tzs2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/TzS2Range.java (renamed from s2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/TzS2Range.java)8
-rw-r--r--tzs2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/TzS2RangeFileFormat.java (renamed from s2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/TzS2RangeFileFormat.java)20
-rw-r--r--tzs2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/read/HeaderBlock.java (renamed from s2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/read/HeaderBlock.java)4
-rw-r--r--tzs2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/read/PopulatedSuffixTableBlock.java (renamed from s2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/read/PopulatedSuffixTableBlock.java)10
-rw-r--r--tzs2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/read/SuffixTableBlock.java (renamed from s2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/read/SuffixTableBlock.java)12
-rw-r--r--tzs2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/read/SuffixTableExtraInfo.java (renamed from s2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/read/SuffixTableExtraInfo.java)6
-rw-r--r--tzs2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/read/TzS2RangeFileReader.java (renamed from s2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/read/TzS2RangeFileReader.java)12
-rw-r--r--tzs2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/read/UnpopulatedSuffixTableBlock.java (renamed from s2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/read/UnpopulatedSuffixTableBlock.java)0
-rw-r--r--tzs2storage/src/test/java/com/android/timezone/location/storage/tzs2range/BankedTzIdSetsTest.java (renamed from s2storage/src/test/java/com/android/timezone/location/storage/tzs2range/BankedTzIdSetsTest.java)4
-rw-r--r--tzs2storage/src/test/java/com/android/timezone/location/storage/tzs2range/HeaderBlockTest.java (renamed from s2storage/src/test/java/com/android/timezone/location/storage/tzs2range/HeaderBlockTest.java)4
-rw-r--r--tzs2storage/src/test/java/com/android/timezone/location/storage/tzs2range/SuffixTableBlockMatcher.java (renamed from s2storage/src/test/java/com/android/timezone/location/storage/tzs2range/SuffixTableBlockMatcher.java)0
-rw-r--r--tzs2storage/src/test/java/com/android/timezone/location/storage/tzs2range/SuffixTableBlockTest.java (renamed from s2storage/src/test/java/com/android/timezone/location/storage/tzs2range/SuffixTableBlockTest.java)4
-rw-r--r--tzs2storage/src/test/java/com/android/timezone/location/storage/tzs2range/SuffixTableExtraInfoTest.java (renamed from s2storage/src/test/java/com/android/timezone/location/storage/tzs2range/SuffixTableExtraInfoTest.java)4
-rw-r--r--tzs2storage/src/test/java/com/android/timezone/location/storage/tzs2range/SuffixTableRangeTest.java (renamed from s2storage/src/test/java/com/android/timezone/location/storage/tzs2range/SuffixTableRangeTest.java)6
-rw-r--r--tzs2storage/src/test/java/com/android/timezone/location/storage/tzs2range/SuffixTableSharedDataTest.java (renamed from s2storage/src/test/java/com/android/timezone/location/storage/tzs2range/SuffixTableSharedDataTest.java)0
-rw-r--r--tzs2storage/src/test/java/com/android/timezone/location/storage/tzs2range/TzS2RangeFileFormatTest.java (renamed from s2storage/src/test/java/com/android/timezone/location/storage/tzs2range/TzS2RangeFileFormatTest.java)4
-rw-r--r--tzs2storage/src/test/java/com/android/timezone/location/storage/tzs2range/TzS2RangeFileTest.java (renamed from s2storage/src/test/java/com/android/timezone/location/storage/tzs2range/TzS2RangeFileTest.java)6
-rw-r--r--tzs2storage/src/test/java/com/android/timezone/location/storage/tzs2range/TzS2RangeTest.java (renamed from s2storage/src/test/java/com/android/timezone/location/storage/tzs2range/TzS2RangeTest.java)8
-rw-r--r--tzs2storage/src/test/java/com/android/timezone/location/storage/tzs2range/write/BankedTzIdSetsPackerTest.java (renamed from s2storage/src/test/java/com/android/timezone/location/storage/tzs2range/write/BankedTzIdSetsPackerTest.java)8
-rw-r--r--tzs2storage/src/test/java/com/android/timezone/location/storage/tzs2range/write/PushBackIteratorTest.java (renamed from s2storage/src/test/java/com/android/timezone/location/storage/tzs2range/write/PushBackIteratorTest.java)4
-rw-r--r--tzs2storage/src/write/java/com/android/timezone/location/storage/tzs2range/write/BankedTzIdSetsPacker.java (renamed from s2storage/src/write/java/com/android/timezone/location/storage/tzs2range/write/BankedTzIdSetsPacker.java)0
-rw-r--r--tzs2storage/src/write/java/com/android/timezone/location/storage/tzs2range/write/HeaderBlockWriter.java (renamed from s2storage/src/write/java/com/android/timezone/location/storage/tzs2range/write/HeaderBlockWriter.java)6
-rw-r--r--tzs2storage/src/write/java/com/android/timezone/location/storage/tzs2range/write/PushBackIterator.java (renamed from s2storage/src/write/java/com/android/timezone/location/storage/tzs2range/write/PushBackIterator.java)0
-rw-r--r--tzs2storage/src/write/java/com/android/timezone/location/storage/tzs2range/write/SuffixTableSharedDataWriter.java (renamed from s2storage/src/write/java/com/android/timezone/location/storage/tzs2range/write/SuffixTableSharedDataWriter.java)4
-rw-r--r--tzs2storage/src/write/java/com/android/timezone/location/storage/tzs2range/write/SuffixTableWriter.java (renamed from s2storage/src/write/java/com/android/timezone/location/storage/tzs2range/write/SuffixTableWriter.java)16
-rw-r--r--tzs2storage/src/write/java/com/android/timezone/location/storage/tzs2range/write/TzS2RangeFileWriter.java (renamed from s2storage/src/write/java/com/android/timezone/location/storage/tzs2range/write/TzS2RangeFileWriter.java)8
-rw-r--r--tzs2storage/tools/Android.bp59
-rw-r--r--tzs2storage/tools/src/java/com/android/storage/tools/block/DumpBlockFile.java44
-rw-r--r--tzs2storage/tools/src/java/com/android/storage/tools/block/dump/BlockDumper.java36
-rw-r--r--tzs2storage/tools/src/java/com/android/storage/tools/block/dump/BlockFileDumper.java63
-rw-r--r--tzs2storage/tools/src/java/com/android/storage/tools/block/dump/BlockInfoDumper.java39
-rw-r--r--tzs2storage/tools/src/java/com/android/storage/tools/block/dump/DumpUtils.java113
-rw-r--r--tzs2storage/tools/src/java/com/android/storage/tools/block/dump/SingleFileDumper.java67
-rw-r--r--tzs2storage/tools/src/java/com/android/timezone/location/tools/tzs2/CreateTestTzS2File.java (renamed from s2storage/tools/src/java/com/android/timezone/location/tools/tzs2/CreateTestTzS2File.java)0
-rw-r--r--tzs2storage/tools/src/java/com/android/timezone/location/tools/tzs2/CreateTzS2File.java (renamed from s2storage/tools/src/java/com/android/timezone/location/tools/tzs2/CreateTzS2File.java)0
-rw-r--r--tzs2storage/tools/src/java/com/android/timezone/location/tools/tzs2/DumpTzS2File.java (renamed from s2storage/tools/src/java/com/android/timezone/location/tools/tzs2/DumpTzS2File.java)2
-rw-r--r--tzs2storage/tools/src/java/com/android/timezone/location/tools/tzs2/FileFormats.java (renamed from s2storage/tools/src/java/com/android/timezone/location/tools/tzs2/FileFormats.java)0
-rw-r--r--tzs2storage/tools/src/java/com/android/timezone/location/tools/tzs2/dump/HeaderBlockDumper.java (renamed from s2storage/tools/src/java/com/android/timezone/location/tools/tzs2/dump/HeaderBlockDumper.java)2
-rw-r--r--tzs2storage/tools/src/java/com/android/timezone/location/tools/tzs2/dump/SuffixTableBlockDumper.java (renamed from s2storage/tools/src/java/com/android/timezone/location/tools/tzs2/dump/SuffixTableBlockDumper.java)12
-rw-r--r--tzs2storage/tools/src/java/com/android/timezone/location/tools/tzs2/dump/TzS2RangeFileDumper.java (renamed from s2storage/tools/src/java/com/android/timezone/location/tools/tzs2/dump/TzS2RangeFileDumper.java)12
-rw-r--r--tzs2storage/tools/src/proto/geotz_protos.proto (renamed from s2storage/tools/src/proto/geotz_protos.proto)0
96 files changed, 975 insertions, 442 deletions
diff --git a/README.md b/README.md
index ed195ce..843353d 100644
--- a/README.md
+++ b/README.md
@@ -31,9 +31,14 @@ Directory structure
the associated license files.
`s2storage`
- - File reading / writing code and tools to support `tzs2.dat` generation on
- host, and the file's use on host and device. See `s2storage/README.md` for
- format details.
+ - Generic file reading / writing code and tools to support `tzs2.dat`
+ generation on host, and the file's use on host and device. See
+ `s2storage/README.md` for details.
+
+`tzs2storage`
+ - TZ-specific file reading / writing code and tools to support `tzs2.dat`
+ generation on host, and the file's use on host and device. See
+ `tzs2storage/README.md` for details.
`tzbb_data`
- Data / licenses from the external
diff --git a/s2storage/Android.bp b/s2storage/Android.bp
index 3f04ce4..ef525ce 100644
--- a/s2storage/Android.bp
+++ b/s2storage/Android.bp
@@ -17,8 +17,9 @@ package {
default_applicable_licenses: ["Android-Apache-2.0"],
}
+// Generic read-only storage classes
java_library {
- name: "geotz_s2storage_ro",
+ name: "s2storage_ro",
sdk_version: "31",
min_sdk_version: "31",
host_supported: true,
@@ -31,24 +32,36 @@ java_library {
],
}
-// Library for read/write access to TZ S2 data files.
+// Generic read/write storage classes
java_library_host {
- name: "geotz_s2storage_rw",
+ name: "s2storage_rw",
srcs: [
"src/write/java/**/*.java",
],
static_libs: [
- "geotz_s2storage_ro",
+ "s2storage_ro",
],
}
-// Tests for the TZ S2 storage code.
+// Generic read-only storage classes
+java_library_host {
+ name: "s2storage_testing",
+ srcs: [
+ "src/testing/java/**/*.java",
+ ],
+ libs: [
+ "junit",
+ ],
+}
+
+// Tests for the generic storage classes
java_test_host {
- name: "geotz_s2storage_tests",
+ name: "s2storage_tests",
srcs: ["src/test/java/**/*.java"],
static_libs: [
- "geotz_s2storage_rw",
+ "s2storage_rw",
+ "s2storage_testing",
"junit",
"mockito",
"objenesis",
diff --git a/s2storage/README.md b/s2storage/README.md
index 23f52bd..d1427bf 100644
--- a/s2storage/README.md
+++ b/s2storage/README.md
@@ -1,15 +1,24 @@
-This directory contains files related to storage of TZ S2 data files used for offline geolocation
-time zone detection.
+This directory contains files related to storage of read-only S2 data in blocks.
+The classes are generic.
+
+The data file format is intended to be language neutral (e.g. Java or C code could easily be
+written to read it with minimal dependencies), providing a good balance between file size,
+extensibility and memory usage at runtime.
High level file structure
=========================
- * `src/readonly/` - host + device code for reading TZ S2 data files
- * `src/write/` - host code for writing TZ S2 data files
+ * `src/readonly/` - host + device code for reading data files
+ * `src/write/` - host code for writing data files
* `src/test/` - host tests for readonly/ and write/ code
- * `tools/` - host tooling to support generation / debugging / testing of TZ S2 data
+ * `tools/` - host tooling to support generation / debugging / testing of data
files.
+Developed for Android, the code is also intended to work with host Java for easy
+testing and debugging. The code is split into "readonly" and "write" code, as
+the code that writes the files is expected to only be used on host during file
+generation, while the "readonly" would be used on both host and device.
+
Block file format information
=============================
@@ -35,167 +44,3 @@ table. Then they contain one or more fixed length `{key}`/`{value}` records of `
`{key}`. The table data is easily memory mapped and each record can be randomly accessed by
`{key}`.
-TZ S2 data file format information
-==================================
-
-The TZ S2 data file is a type of block file that uses packed tables. It overlays additional rules,
-block types, etc. on top of the general block file format.
-
-High level description
-----------------------
-
-The TZ S2 data file format is intended to be language neutral (e.g. Java or C code could easily be
-written to read it with minimal dependencies), providing a good balance between file size,
-extensibility and memory usage at runtime.
-
-It is designed to be flexible and parameterized / self describing: the header block contains format
-information needed to locate and interpret the data storage blocks.
-
-The file stores time zone geolocation data at a single S2 level. Logically, the data consists of:
-
-```
-{start S2 cell ID (inclusive)}, {end S2 cell ID (exclusive)}, {time zone IDs}
-```
-
-The main usecase of the file is to lookup the time zone ID(s) (if any) for a given S2 cell ID.
-
-General storage approach
-------------------------
-
-To keep the file size to a minimum, the format avoids storing 64-bit S2 cell IDs directly. Instead,
-the logical input data is mapped to a data structure that allows the individual S2 cell IDs to be
-stored using only a subset of the bits needed to store a full S2 cell ID.
-
-Each logical S2 range data described above is subdivided into ranges with a common S2 cell ID
-prefix. Any ranges in the source data that span a prefix are split into smaller ranges to preserve
-the "same prefix" property. All ranges with a common prefix can be stored in one "suffix table".
-
-The time zone ID strings are also only stored once and are referenced indirectly, avoiding repeated
-storage of common strings.
-
-TZ S2 data lookup
------------------
-
-Suffix table block IDs are calculated by taking the prefix of the S2 cell ID being sought and
-applying a fixed offset. The block info and block data for the cell's suffix table can be accessed
-directly using the block's ID.
-
-Specifically:
-
-The `{prefix}` is computed by extracting the first `{X}` bits of the S2 cell ID. The `{prefix}` is
-used to obtain the `{block ID}` of the block used to store the suffix table. The `{block ID}` is
-calculated by adding a fixed offset (obtained from the header block) to the cell ID `{prefix}`.
-
-The `{block ID}` is first used to look lookup the block info. If the length of the block with
-`{block ID}` is zero, the lookup stops at this point as it means there are no ranges for `{prefix}`.
-
-When the `{block ID}` block is non-zero length, the block is interpreted as a packed table
-(described above) which stores the suffix table's entries.
-
-The `{suffix}`, the final `{Y}` bits of the search S2 cell ID, is used to seek for a record
-containing the s2 range holding that cell ID, if any. The `{suffix}` will match either no records or
-only one record in the table.
-
-For more information on suffix table storage, see the Suffix Table Blocks section below.
-
-The Header Block
-----------------
-
-The header block is always required to be block zero and have the expected type
-ID (1).
-
-The header contains format information needed to address the suffix table blocks
-and the block format information needed to interpret those blocks. It also
-contains information shared by all blocks such as the TZ ID sets.
-
-TZ ID Sets storage
-------------------
-
-Sets of one or more time zone IDs are referenced by every range stored in the TZ S2 data file.
-
-Individual time zone IDs are strings like "America/Los_Angeles" that should only be stored once to
-conserve space.
-
-Further, the time zone IDs are referenced as sets, e.g. one cell range may reference
-"Europe/London", another may reference "Europe/Paris" and another may reference
-both "Europe/London" and "Europe/Paris".
-
-It is important to keep the number of bits used in each suffix table entry to a
-minimum because there are hundreds of thousands of ranges globally and hundreds
-of distinct sets. To do this we make use of "banking", which leverages
-properties of the data.
-
-For example:
-
-1. Several ranges with S2 cell IDs close together may reference the same set - e.g. there
-will be several range entries that reference "Europe/London".
-2. There is unlikely to a single S2 cell that needs to reference both "America/Los_Angeles" and
-"Europe/London", since the areas covered by those time zone IDs are geographically separate.
-
-Consequently:
-
-Every time zone ID string referenced in the file is assigned a numeric ID. The string is stored once
-in the file in the header block. All references to time zone IDs are made via the numeric ID.
-
-e.g.
-```
-1: Europe/London
-2: Europe/Paris
-3: ...
-```
-
-Every TZ S2 data file has one or more "set banks". Each bank contains an array of `{set of time zone
-IDs}`.
-
-A bank may contain many sets, which various combinations of TZ IDs:
-```
-1: {1} - meaning the set {"Europe/London"}
-2: {2} - meaning the set {"Europe/Paris"}
-3: {1,2} - meaning the set {"Europe/London", "Europe/Paris"}
-...
-```
-
-Via this indirection and banking, each range entry can address a set of time zone ID strings using
-only a numeric bank ID and a numeric set ID. The bank ID is the same for all entries in suffix
-table, so this means that it can be stored once per table and only the (small) `{TZ IDs set ID}`
-needs to be stored with each entry.
-
-Suffix Table Blocks
--------------------
-
-The suffix table block is a packed table with shared information and one or more entries.
-
-The shared information consists of:
-
-```
-{TZ IDs set bank} - the bank ID of the TZ IDs set bank used when looking up time zone set IDs
- referenced by all table entries.
-```
-
-Each record in the suffix table logically holds entries consisting of:
-```
-{start S2 cell ID (inclusive)}, {end S2 cell ID (exclusive)}, {time zone IDs}`
-```
-
-As with any packed table, each record in the packed table has a fixed width of `{R}` bits. The first
-`{M}` bits of every record are used to store the (ordered) `{key}`.
-
-The `{key}` for an entry contains only the `{suffix}` bits from the `{start S2 cell ID
-(inclusive)}`. To reconstruct the `{start S2 cell ID (inclusive)}` it's only necessary to know
-the `{prefix}` for the table and the `{key}`.
-
-The remaining (`{R-M}`) bits are used to store the ``{value}``. The ``{value}`` is further
-sub-divided into two: the `{end S2 cell ID offset}` and the `{TZ IDs set ID}`.
-
-The `{end S2 cell ID offset}` is a transformation of the `{end S2 cell ID (exclusive)}`. The `{end
-S2 cell ID}` can be calculated by adding the `{end S2 cell ID offset}` to the `{start S2 cell ID
-(inclusive)}`.
-
-When searching for an S2 cell ID, the prefix is used to locate the correct suffix table. The suffix
-bits from the S2 cell ID can be extracted. Since all data in the table is held at a single S2 level,
-the suffix bits can be used to binary search the suffix table entries by looking for an entry
-containing the suffix bits, i.e. by comparing the suffix bits against the `{key}` and `{key}` +
-`{end S2 cell ID offset}` value.
-
-If an entry is found, the `{TZ set ID}` indirectly leads to the `{time zone IDs}` for the range. For
-more information see TZ ID Sets storage above.
diff --git a/s2storage/src/readonly/java/com/android/timezone/location/storage/block/read/Block.java b/s2storage/src/readonly/java/com/android/storage/block/read/Block.java
index be9559a..930785d 100644
--- a/s2storage/src/readonly/java/com/android/timezone/location/storage/block/read/Block.java
+++ b/s2storage/src/readonly/java/com/android/storage/block/read/Block.java
@@ -14,9 +14,9 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.block.read;
+package com.android.storage.block.read;
-import com.android.timezone.location.storage.util.Visitor;
+import com.android.storage.util.Visitor;
import java.nio.ByteBuffer;
import java.util.Objects;
diff --git a/s2storage/src/readonly/java/com/android/timezone/location/storage/block/read/BlockData.java b/s2storage/src/readonly/java/com/android/storage/block/read/BlockData.java
index d7f96fb..f9ce802 100644
--- a/s2storage/src/readonly/java/com/android/timezone/location/storage/block/read/BlockData.java
+++ b/s2storage/src/readonly/java/com/android/storage/block/read/BlockData.java
@@ -14,9 +14,10 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.block.read;
+package com.android.storage.block.read;
-import com.android.timezone.location.storage.util.BitwiseUtils;
+import com.android.storage.io.read.TypedInputStream;
+import com.android.storage.util.BitwiseUtils;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
@@ -25,7 +26,7 @@ import java.util.Objects;
/**
* Provides typed, absolute position, random access to a block's data.
*
- * <p>See also {@link com.android.timezone.location.storage.io.read.TypedInputStream} for a streamed
+ * <p>See also {@link TypedInputStream} for a streamed
* equivalent.
*/
public final class BlockData {
diff --git a/s2storage/src/readonly/java/com/android/timezone/location/storage/block/read/BlockFileReader.java b/s2storage/src/readonly/java/com/android/storage/block/read/BlockFileReader.java
index 1a1d8d9..4395bfd 100644
--- a/s2storage/src/readonly/java/com/android/timezone/location/storage/block/read/BlockFileReader.java
+++ b/s2storage/src/readonly/java/com/android/storage/block/read/BlockFileReader.java
@@ -14,10 +14,10 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.block.read;
+package com.android.storage.block.read;
-import com.android.timezone.location.storage.io.read.TypedInputStream;
-import com.android.timezone.location.storage.util.Visitor;
+import com.android.storage.io.read.TypedInputStream;
+import com.android.storage.util.Visitor;
import java.io.File;
import java.io.FileInputStream;
diff --git a/s2storage/src/readonly/java/com/android/timezone/location/storage/block/read/BlockInfo.java b/s2storage/src/readonly/java/com/android/storage/block/read/BlockInfo.java
index 6c01994..811c835 100644
--- a/s2storage/src/readonly/java/com/android/timezone/location/storage/block/read/BlockInfo.java
+++ b/s2storage/src/readonly/java/com/android/storage/block/read/BlockInfo.java
@@ -14,9 +14,9 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.block.read;
+package com.android.storage.block.read;
-import com.android.timezone.location.storage.util.Visitor;
+import com.android.storage.util.Visitor;
import java.util.Arrays;
import java.util.Objects;
diff --git a/s2storage/src/readonly/java/com/android/timezone/location/storage/io/read/TypedInputStream.java b/s2storage/src/readonly/java/com/android/storage/io/read/TypedInputStream.java
index a4195e8..2e4684f 100644
--- a/s2storage/src/readonly/java/com/android/timezone/location/storage/io/read/TypedInputStream.java
+++ b/s2storage/src/readonly/java/com/android/storage/io/read/TypedInputStream.java
@@ -14,9 +14,9 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.io.read;
+package com.android.storage.io.read;
-import com.android.timezone.location.storage.block.read.BlockData;
+import com.android.storage.block.read.BlockData;
import java.io.BufferedInputStream;
import java.io.Closeable;
diff --git a/s2storage/src/readonly/java/com/android/timezone/location/storage/s2/S2CellOrdering.java b/s2storage/src/readonly/java/com/android/storage/s2/S2CellOrdering.java
index 38c1b05..8e1ecab 100644
--- a/s2storage/src/readonly/java/com/android/timezone/location/storage/s2/S2CellOrdering.java
+++ b/s2storage/src/readonly/java/com/android/storage/s2/S2CellOrdering.java
@@ -14,10 +14,10 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.s2;
+package com.android.storage.s2;
-import static com.android.timezone.location.storage.s2.S2Support.getMaxCellId;
-import static com.android.timezone.location.storage.s2.S2Support.getMinCellId;
+import static com.android.storage.s2.S2Support.getMaxCellId;
+import static com.android.storage.s2.S2Support.getMinCellId;
/** A class that provides a natural ordering for S2 cell IDs. */
public final class S2CellOrdering {
diff --git a/s2storage/src/readonly/java/com/android/timezone/location/storage/s2/S2LevelRange.java b/s2storage/src/readonly/java/com/android/storage/s2/S2LevelRange.java
index bea27d7..f4180b3 100644
--- a/s2storage/src/readonly/java/com/android/timezone/location/storage/s2/S2LevelRange.java
+++ b/s2storage/src/readonly/java/com/android/storage/s2/S2LevelRange.java
@@ -14,9 +14,9 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.s2;
+package com.android.storage.s2;
-import static com.android.timezone.location.storage.s2.S2Support.cellIdToString;
+import static com.android.storage.s2.S2Support.cellIdToString;
import java.util.Comparator;
import java.util.Objects;
diff --git a/s2storage/src/readonly/java/com/android/timezone/location/storage/s2/S2Support.java b/s2storage/src/readonly/java/com/android/storage/s2/S2Support.java
index 62c3144..f3b5036 100644
--- a/s2storage/src/readonly/java/com/android/timezone/location/storage/s2/S2Support.java
+++ b/s2storage/src/readonly/java/com/android/storage/s2/S2Support.java
@@ -14,9 +14,9 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.s2;
+package com.android.storage.s2;
-import com.android.timezone.location.storage.util.BitwiseUtils;
+import com.android.storage.util.BitwiseUtils;
/** A class that can perform basic S2 operations on cell IDs. */
public final class S2Support {
diff --git a/s2storage/src/readonly/java/com/android/timezone/location/storage/s2/SortedS2Ranges.java b/s2storage/src/readonly/java/com/android/storage/s2/SortedS2Ranges.java
index 4fecc25..8625705 100644
--- a/s2storage/src/readonly/java/com/android/timezone/location/storage/s2/SortedS2Ranges.java
+++ b/s2storage/src/readonly/java/com/android/storage/s2/SortedS2Ranges.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.s2;
+package com.android.storage.s2;
import java.util.ArrayList;
import java.util.Arrays;
diff --git a/s2storage/src/readonly/java/com/android/timezone/location/storage/table/packed/read/BaseTypedPackedTable.java b/s2storage/src/readonly/java/com/android/storage/table/packed/read/BaseTypedPackedTable.java
index bb011c2..b2aa2dc 100644
--- a/s2storage/src/readonly/java/com/android/timezone/location/storage/table/packed/read/BaseTypedPackedTable.java
+++ b/s2storage/src/readonly/java/com/android/storage/table/packed/read/BaseTypedPackedTable.java
@@ -14,10 +14,10 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.table.packed.read;
+package com.android.storage.table.packed.read;
-import com.android.timezone.location.storage.block.read.BlockData;
-import com.android.timezone.location.storage.table.reader.Table;
+import com.android.storage.block.read.BlockData;
+import com.android.storage.table.reader.Table;
import java.util.Objects;
diff --git a/s2storage/src/readonly/java/com/android/timezone/location/storage/table/packed/read/IntValueTypedPackedTable.java b/s2storage/src/readonly/java/com/android/storage/table/packed/read/IntValueTypedPackedTable.java
index 29bc338..b2be795 100644
--- a/s2storage/src/readonly/java/com/android/timezone/location/storage/table/packed/read/IntValueTypedPackedTable.java
+++ b/s2storage/src/readonly/java/com/android/storage/table/packed/read/IntValueTypedPackedTable.java
@@ -14,10 +14,10 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.table.packed.read;
+package com.android.storage.table.packed.read;
-import com.android.timezone.location.storage.block.read.BlockData;
-import com.android.timezone.location.storage.table.reader.IntValueTable;
+import com.android.storage.block.read.BlockData;
+import com.android.storage.table.reader.IntValueTable;
/**
* A key-ordered table implementation that holds values using a fixed-length entry. The combined
diff --git a/s2storage/src/readonly/java/com/android/timezone/location/storage/table/packed/read/PackedTableReader.java b/s2storage/src/readonly/java/com/android/storage/table/packed/read/PackedTableReader.java
index 39aa414..c6f9623 100644
--- a/s2storage/src/readonly/java/com/android/timezone/location/storage/table/packed/read/PackedTableReader.java
+++ b/s2storage/src/readonly/java/com/android/storage/table/packed/read/PackedTableReader.java
@@ -14,12 +14,12 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.table.packed.read;
+package com.android.storage.table.packed.read;
-import com.android.timezone.location.storage.block.read.BlockData;
-import com.android.timezone.location.storage.table.reader.IntValueTable.IntValueEntryMatcher;
-import com.android.timezone.location.storage.table.reader.LongValueTable.LongValueEntryMatcher;
-import com.android.timezone.location.storage.util.BitwiseUtils;
+import com.android.storage.block.read.BlockData;
+import com.android.storage.table.reader.IntValueTable.IntValueEntryMatcher;
+import com.android.storage.table.reader.LongValueTable.LongValueEntryMatcher;
+import com.android.storage.util.BitwiseUtils;
import java.util.Objects;
diff --git a/s2storage/src/readonly/java/com/android/timezone/location/storage/table/reader/IntValueTable.java b/s2storage/src/readonly/java/com/android/storage/table/reader/IntValueTable.java
index bd39510..f2a988e 100644
--- a/s2storage/src/readonly/java/com/android/timezone/location/storage/table/reader/IntValueTable.java
+++ b/s2storage/src/readonly/java/com/android/storage/table/reader/IntValueTable.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.table.reader;
+package com.android.storage.table.reader;
/**
* A type for tables where the value can be expressed as a Java int; i.e. not long, but perhaps
diff --git a/s2storage/src/readonly/java/com/android/timezone/location/storage/table/reader/LongValueTable.java b/s2storage/src/readonly/java/com/android/storage/table/reader/LongValueTable.java
index 2dd6739..923d2b0 100644
--- a/s2storage/src/readonly/java/com/android/timezone/location/storage/table/reader/LongValueTable.java
+++ b/s2storage/src/readonly/java/com/android/storage/table/reader/LongValueTable.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.table.reader;
+package com.android.storage.table.reader;
/**
* A type for tables where the value can be expressed as a Java long or perhaps smaller.
diff --git a/s2storage/src/readonly/java/com/android/timezone/location/storage/table/reader/Table.java b/s2storage/src/readonly/java/com/android/storage/table/reader/Table.java
index 6aa5fa1..2caf5d0 100644
--- a/s2storage/src/readonly/java/com/android/timezone/location/storage/table/reader/Table.java
+++ b/s2storage/src/readonly/java/com/android/storage/table/reader/Table.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.table.reader;
+package com.android.storage.table.reader;
/**
* A table containing entries with a signed, int key. A table can also have an array of shared data
diff --git a/s2storage/src/readonly/java/com/android/timezone/location/storage/util/BitwiseUtils.java b/s2storage/src/readonly/java/com/android/storage/util/BitwiseUtils.java
index 549cde9..2f0ab6e 100644
--- a/s2storage/src/readonly/java/com/android/timezone/location/storage/util/BitwiseUtils.java
+++ b/s2storage/src/readonly/java/com/android/storage/util/BitwiseUtils.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.util;
+package com.android.storage.util;
/** Utility functions for bit twiddling. */
public final class BitwiseUtils {
diff --git a/s2storage/src/readonly/java/com/android/timezone/location/storage/util/Conditions.java b/s2storage/src/readonly/java/com/android/storage/util/Conditions.java
index 7da1ea3..eb00d27 100644
--- a/s2storage/src/readonly/java/com/android/timezone/location/storage/util/Conditions.java
+++ b/s2storage/src/readonly/java/com/android/storage/util/Conditions.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.util;
+package com.android.storage.util;
/** Useful condition check methods. */
public final class Conditions {
diff --git a/s2storage/src/readonly/java/com/android/timezone/location/storage/util/Visitor.java b/s2storage/src/readonly/java/com/android/storage/util/Visitor.java
index f6fc622..7fab7b1 100644
--- a/s2storage/src/readonly/java/com/android/timezone/location/storage/util/Visitor.java
+++ b/s2storage/src/readonly/java/com/android/storage/util/Visitor.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.util;
+package com.android.storage.util;
/** A base class for visitor classes to extend. */
public interface Visitor {
diff --git a/s2storage/src/test/java/com/android/timezone/location/storage/block/BlockFileTest.java b/s2storage/src/test/java/com/android/storage/block/BlockFileTest.java
index c1135c2..831aa46 100644
--- a/s2storage/src/test/java/com/android/timezone/location/storage/block/BlockFileTest.java
+++ b/s2storage/src/test/java/com/android/storage/block/BlockFileTest.java
@@ -14,20 +14,20 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.block;
+package com.android.storage.block;
-import static com.android.timezone.location.storage.testing.MoreAsserts.assertThrows;
+import static com.android.storage.testing.MoreAsserts.assertThrows;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.argThat;
-import com.android.timezone.location.storage.block.read.Block;
-import com.android.timezone.location.storage.block.read.BlockData;
-import com.android.timezone.location.storage.block.read.BlockFileReader;
-import com.android.timezone.location.storage.block.read.BlockInfo;
-import com.android.timezone.location.storage.block.read.BlockMatcher;
-import com.android.timezone.location.storage.block.write.BlockFileWriter;
+import com.android.storage.block.read.Block;
+import com.android.storage.block.read.BlockData;
+import com.android.storage.block.read.BlockFileReader;
+import com.android.storage.block.read.BlockInfo;
+import com.android.storage.block.read.BlockMatcher;
+import com.android.storage.block.write.BlockFileWriter;
import org.junit.Test;
import org.mockito.InOrder;
diff --git a/s2storage/src/test/java/com/android/timezone/location/storage/block/read/BlockDataTest.java b/s2storage/src/test/java/com/android/storage/block/read/BlockDataTest.java
index 02f7e07..af56bae 100644
--- a/s2storage/src/test/java/com/android/timezone/location/storage/block/read/BlockDataTest.java
+++ b/s2storage/src/test/java/com/android/storage/block/read/BlockDataTest.java
@@ -14,13 +14,13 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.block.read;
+package com.android.storage.block.read;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
-import com.android.timezone.location.storage.io.write.TypedOutputStream;
+import com.android.storage.io.write.TypedOutputStream;
import org.junit.Test;
diff --git a/s2storage/src/test/java/com/android/timezone/location/storage/block/read/BlockInfoTest.java b/s2storage/src/test/java/com/android/storage/block/read/BlockInfoTest.java
index 64ab5a1..b6a98ee 100644
--- a/s2storage/src/test/java/com/android/timezone/location/storage/block/read/BlockInfoTest.java
+++ b/s2storage/src/test/java/com/android/storage/block/read/BlockInfoTest.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.block.read;
+package com.android.storage.block.read;
import static org.mockito.Mockito.mock;
diff --git a/s2storage/src/test/java/com/android/timezone/location/storage/block/read/BlockMatcher.java b/s2storage/src/test/java/com/android/storage/block/read/BlockMatcher.java
index 11083a5..a7c4476 100644
--- a/s2storage/src/test/java/com/android/timezone/location/storage/block/read/BlockMatcher.java
+++ b/s2storage/src/test/java/com/android/storage/block/read/BlockMatcher.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.block.read;
+package com.android.storage.block.read;
import org.mockito.ArgumentMatcher;
diff --git a/s2storage/src/test/java/com/android/timezone/location/storage/block/read/BlockTest.java b/s2storage/src/test/java/com/android/storage/block/read/BlockTest.java
index b6f2203..b79e1cb 100644
--- a/s2storage/src/test/java/com/android/timezone/location/storage/block/read/BlockTest.java
+++ b/s2storage/src/test/java/com/android/storage/block/read/BlockTest.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.block.read;
+package com.android.storage.block.read;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.mock;
diff --git a/s2storage/src/test/java/com/android/timezone/location/storage/block/write/EmptyBlockWriterTest.java b/s2storage/src/test/java/com/android/storage/block/write/EmptyBlockWriterTest.java
index 764fd6f..2b5622d 100644
--- a/s2storage/src/test/java/com/android/timezone/location/storage/block/write/EmptyBlockWriterTest.java
+++ b/s2storage/src/test/java/com/android/storage/block/write/EmptyBlockWriterTest.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.block.write;
+package com.android.storage.block.write;
import static org.junit.Assert.assertEquals;
diff --git a/s2storage/src/test/java/com/android/timezone/location/storage/io/TypedStreamsTest.java b/s2storage/src/test/java/com/android/storage/io/TypedStreamsTest.java
index a50928d..27b8a35 100644
--- a/s2storage/src/test/java/com/android/timezone/location/storage/io/TypedStreamsTest.java
+++ b/s2storage/src/test/java/com/android/storage/io/TypedStreamsTest.java
@@ -14,15 +14,15 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.io;
+package com.android.storage.io;
-import static com.android.timezone.location.storage.testing.MoreAsserts.assertThrows;
+import static com.android.storage.testing.MoreAsserts.assertThrows;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
-import com.android.timezone.location.storage.io.read.TypedInputStream;
-import com.android.timezone.location.storage.io.write.TypedOutputStream;
+import com.android.storage.io.read.TypedInputStream;
+import com.android.storage.io.write.TypedOutputStream;
import org.junit.Test;
@@ -31,8 +31,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
/**
- * Tests for {@link com.android.timezone.location.storage.io.read.TypedInputStream} and
- * {@link com.android.timezone.location.storage.io.write.TypedOutputStream}.
+ * Tests for {@link TypedInputStream} and {@link TypedOutputStream}.
*/
public class TypedStreamsTest {
diff --git a/s2storage/src/test/java/com/android/timezone/location/storage/s2/S2CellOrderingTest.java b/s2storage/src/test/java/com/android/storage/s2/S2CellOrderingTest.java
index a470c47..d8c382e 100644
--- a/s2storage/src/test/java/com/android/timezone/location/storage/s2/S2CellOrderingTest.java
+++ b/s2storage/src/test/java/com/android/storage/s2/S2CellOrderingTest.java
@@ -14,10 +14,10 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.s2;
+package com.android.storage.s2;
-import static com.android.timezone.location.storage.s2.S2CellOrdering.asUnsignedNumeric;
-import static com.android.timezone.location.storage.s2.S2Support.MAX_FACE_ID;
+import static com.android.storage.s2.S2CellOrdering.asUnsignedNumeric;
+import static com.android.storage.s2.S2Support.MAX_FACE_ID;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
diff --git a/s2storage/src/test/java/com/android/timezone/location/storage/s2/S2LevelRangeTest.java b/s2storage/src/test/java/com/android/storage/s2/S2LevelRangeTest.java
index b95e2a9..b8c49b3 100644
--- a/s2storage/src/test/java/com/android/timezone/location/storage/s2/S2LevelRangeTest.java
+++ b/s2storage/src/test/java/com/android/storage/s2/S2LevelRangeTest.java
@@ -14,10 +14,10 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.s2;
+package com.android.storage.s2;
-import static com.android.timezone.location.storage.s2.S2Support.cellId;
-import static com.android.timezone.location.storage.testing.MoreAsserts.assertThrows;
+import static com.android.storage.s2.S2Support.cellId;
+import static com.android.storage.testing.MoreAsserts.assertThrows;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
diff --git a/s2storage/src/test/java/com/android/timezone/location/storage/s2/S2SupportTest.java b/s2storage/src/test/java/com/android/storage/s2/S2SupportTest.java
index cf1f356..fe01e77 100644
--- a/s2storage/src/test/java/com/android/timezone/location/storage/s2/S2SupportTest.java
+++ b/s2storage/src/test/java/com/android/storage/s2/S2SupportTest.java
@@ -14,13 +14,13 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.s2;
+package com.android.storage.s2;
-import static com.android.timezone.location.storage.testing.MoreAsserts.assertThrows;
+import static com.android.storage.testing.MoreAsserts.assertThrows;
import static org.junit.Assert.assertEquals;
-import com.android.timezone.location.storage.util.BitwiseUtils;
+import com.android.storage.util.BitwiseUtils;
import org.junit.Test;
diff --git a/s2storage/src/test/java/com/android/timezone/location/storage/s2/SortedS2RangesTest.java b/s2storage/src/test/java/com/android/storage/s2/SortedS2RangesTest.java
index 0f8b159..3c5f273 100644
--- a/s2storage/src/test/java/com/android/timezone/location/storage/s2/SortedS2RangesTest.java
+++ b/s2storage/src/test/java/com/android/storage/s2/SortedS2RangesTest.java
@@ -14,10 +14,10 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.s2;
+package com.android.storage.s2;
-import static com.android.timezone.location.storage.s2.S2Support.cellId;
-import static com.android.timezone.location.storage.testing.MoreAsserts.assertThrows;
+import static com.android.storage.s2.S2Support.cellId;
+import static com.android.storage.testing.MoreAsserts.assertThrows;
import static org.junit.Assert.assertEquals;
diff --git a/s2storage/src/test/java/com/android/timezone/location/storage/table/packed/IntValuePackedTableTest.java b/s2storage/src/test/java/com/android/storage/table/packed/IntValuePackedTableTest.java
index 574c5ab..3935151 100644
--- a/s2storage/src/test/java/com/android/timezone/location/storage/table/packed/IntValuePackedTableTest.java
+++ b/s2storage/src/test/java/com/android/storage/table/packed/IntValuePackedTableTest.java
@@ -14,10 +14,10 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.table.packed;
+package com.android.storage.table.packed;
-import static com.android.timezone.location.storage.testing.MoreAsserts.assertThrows;
-import static com.android.timezone.location.storage.testing.TestSupport.setOf;
+import static com.android.storage.testing.MoreAsserts.assertThrows;
+import static com.android.storage.testing.TestSupport.setOf;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
@@ -25,11 +25,11 @@ import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import com.android.timezone.location.storage.block.read.BlockData;
-import com.android.timezone.location.storage.table.packed.read.IntValueTypedPackedTable;
-import com.android.timezone.location.storage.table.packed.write.PackedTableWriter;
-import com.android.timezone.location.storage.table.reader.IntValueTable;
-import com.android.timezone.location.storage.util.BitwiseUtils;
+import com.android.storage.block.read.BlockData;
+import com.android.storage.table.packed.read.IntValueTypedPackedTable;
+import com.android.storage.table.packed.write.PackedTableWriter;
+import com.android.storage.table.reader.IntValueTable;
+import com.android.storage.util.BitwiseUtils;
import org.junit.Test;
diff --git a/s2storage/src/test/java/com/android/timezone/location/storage/table/packed/PackedTableReaderWriterTest.java b/s2storage/src/test/java/com/android/storage/table/packed/PackedTableReaderWriterTest.java
index c73784d..f4c339e 100644
--- a/s2storage/src/test/java/com/android/timezone/location/storage/table/packed/PackedTableReaderWriterTest.java
+++ b/s2storage/src/test/java/com/android/storage/table/packed/PackedTableReaderWriterTest.java
@@ -14,23 +14,23 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.table.packed;
+package com.android.storage.table.packed;
-import static com.android.timezone.location.storage.testing.MoreAsserts.assertThrows;
-import static com.android.timezone.location.storage.testing.TestSupport.listOf;
-import static com.android.timezone.location.storage.testing.TestSupport.setOf;
+import static com.android.storage.testing.MoreAsserts.assertThrows;
+import static com.android.storage.testing.TestSupport.listOf;
+import static com.android.storage.testing.TestSupport.setOf;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import com.android.timezone.location.storage.block.read.BlockData;
-import com.android.timezone.location.storage.table.packed.read.PackedTableReader;
-import com.android.timezone.location.storage.table.packed.write.PackedTableWriter;
-import com.android.timezone.location.storage.table.reader.IntValueTable;
-import com.android.timezone.location.storage.table.reader.LongValueTable;
-import com.android.timezone.location.storage.util.BitwiseUtils;
+import com.android.storage.block.read.BlockData;
+import com.android.storage.table.packed.read.PackedTableReader;
+import com.android.storage.table.packed.write.PackedTableWriter;
+import com.android.storage.table.reader.IntValueTable;
+import com.android.storage.table.reader.LongValueTable;
+import com.android.storage.util.BitwiseUtils;
import org.junit.Test;
diff --git a/s2storage/src/test/java/com/android/timezone/location/storage/util/BitwiseUtilsTest.java b/s2storage/src/test/java/com/android/storage/util/BitwiseUtilsTest.java
index af6a65d..bf39ed6 100644
--- a/s2storage/src/test/java/com/android/timezone/location/storage/util/BitwiseUtilsTest.java
+++ b/s2storage/src/test/java/com/android/storage/util/BitwiseUtilsTest.java
@@ -14,9 +14,9 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.util;
+package com.android.storage.util;
-import static com.android.timezone.location.storage.testing.MoreAsserts.assertThrows;
+import static com.android.storage.testing.MoreAsserts.assertThrows;
import static org.junit.Assert.assertEquals;
diff --git a/s2storage/src/test/java/com/android/timezone/location/storage/util/ConditionsTest.java b/s2storage/src/test/java/com/android/storage/util/ConditionsTest.java
index e6102f2..a0d27bc 100644
--- a/s2storage/src/test/java/com/android/timezone/location/storage/util/ConditionsTest.java
+++ b/s2storage/src/test/java/com/android/storage/util/ConditionsTest.java
@@ -14,9 +14,9 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.util;
+package com.android.storage.util;
-import static com.android.timezone.location.storage.testing.MoreAsserts.assertThrows;
+import static com.android.storage.testing.MoreAsserts.assertThrows;
import org.junit.Test;
diff --git a/s2storage/src/test/java/com/android/timezone/location/storage/testing/MoreAsserts.java b/s2storage/src/testing/java/com/android/storage/testing/MoreAsserts.java
index baf063d..6dd8299 100644
--- a/s2storage/src/test/java/com/android/timezone/location/storage/testing/MoreAsserts.java
+++ b/s2storage/src/testing/java/com/android/storage/testing/MoreAsserts.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.testing;
+package com.android.storage.testing;
public final class MoreAsserts {
@@ -22,10 +22,12 @@ public final class MoreAsserts {
@FunctionalInterface
public interface ThrowingRunnable {
+ /** The logic to run. */
void run() throws Throwable;
}
// Remove once JUnit is updated to 4.13
+ /** Asserts the supplied {@link ThrowingRunnable} throws the specific throwable. */
public static <T extends Throwable> T assertThrows(
Class<T> expectedThrowable,
ThrowingRunnable runnable) {
diff --git a/s2storage/src/test/java/com/android/timezone/location/storage/testing/TestSupport.java b/s2storage/src/testing/java/com/android/storage/testing/TestSupport.java
index 59163e9..fc4d92f 100644
--- a/s2storage/src/test/java/com/android/timezone/location/storage/testing/TestSupport.java
+++ b/s2storage/src/testing/java/com/android/storage/testing/TestSupport.java
@@ -14,23 +14,26 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.testing;
+package com.android.storage.testing;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
-public class TestSupport {
+/** Methods to assist in writing readable tests. */
+public final class TestSupport {
private TestSupport() {
}
+ /** Returns a list from a varargs param. */
@SafeVarargs
public static <E> List<E> listOf(E... values) {
return Arrays.asList(values);
}
+ /** Returns a set from a varargs param. */
@SafeVarargs
public static <E> Set<E> setOf(E... values) {
return new HashSet<>(Arrays.asList(values));
diff --git a/s2storage/src/write/java/com/android/timezone/location/storage/block/write/BlockFileWriter.java b/s2storage/src/write/java/com/android/storage/block/write/BlockFileWriter.java
index 107a4a8..a510d5a 100644
--- a/s2storage/src/write/java/com/android/timezone/location/storage/block/write/BlockFileWriter.java
+++ b/s2storage/src/write/java/com/android/storage/block/write/BlockFileWriter.java
@@ -14,11 +14,11 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.block.write;
+package com.android.storage.block.write;
-import com.android.timezone.location.storage.block.read.BlockData;
-import com.android.timezone.location.storage.block.read.BlockInfo;
-import com.android.timezone.location.storage.io.write.TypedOutputStream;
+import com.android.storage.block.read.BlockData;
+import com.android.storage.block.read.BlockInfo;
+import com.android.storage.io.write.TypedOutputStream;
import java.io.File;
import java.io.FileInputStream;
diff --git a/s2storage/src/write/java/com/android/timezone/location/storage/block/write/BlockWriter.java b/s2storage/src/write/java/com/android/storage/block/write/BlockWriter.java
index 76894da..5769f7f 100644
--- a/s2storage/src/write/java/com/android/timezone/location/storage/block/write/BlockWriter.java
+++ b/s2storage/src/write/java/com/android/storage/block/write/BlockWriter.java
@@ -14,10 +14,10 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.block.write;
+package com.android.storage.block.write;
-import com.android.timezone.location.storage.block.read.BlockData;
-import com.android.timezone.location.storage.block.read.BlockInfo;
+import com.android.storage.block.read.BlockData;
+import com.android.storage.block.read.BlockInfo;
import java.io.IOException;
diff --git a/s2storage/src/write/java/com/android/timezone/location/storage/block/write/EmptyBlockWriter.java b/s2storage/src/write/java/com/android/storage/block/write/EmptyBlockWriter.java
index ad84221..1c16c63 100644
--- a/s2storage/src/write/java/com/android/timezone/location/storage/block/write/EmptyBlockWriter.java
+++ b/s2storage/src/write/java/com/android/storage/block/write/EmptyBlockWriter.java
@@ -14,9 +14,9 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.block.write;
+package com.android.storage.block.write;
-import com.android.timezone.location.storage.block.read.BlockData;
+import com.android.storage.block.read.BlockData;
import java.nio.ByteBuffer;
diff --git a/s2storage/src/write/java/com/android/timezone/location/storage/io/write/TypedOutputStream.java b/s2storage/src/write/java/com/android/storage/io/write/TypedOutputStream.java
index 36e658c..4e46e9e 100644
--- a/s2storage/src/write/java/com/android/timezone/location/storage/io/write/TypedOutputStream.java
+++ b/s2storage/src/write/java/com/android/storage/io/write/TypedOutputStream.java
@@ -14,9 +14,11 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.io.write;
+package com.android.storage.io.write;
-import com.android.timezone.location.storage.util.BitwiseUtils;
+import com.android.storage.block.read.BlockData;
+import com.android.storage.io.read.TypedInputStream;
+import com.android.storage.util.BitwiseUtils;
import java.io.BufferedOutputStream;
import java.io.Closeable;
@@ -26,9 +28,8 @@ import java.io.IOException;
import java.io.OutputStream;
/**
- * A stream-based writer of typed data that can be read back by
- * {@link com.android.timezone.location.storage.block.read.BlockData} and
- * {@link com.android.timezone.location.storage.io.read.TypedInputStream}
+ * A stream-based writer of typed data that can be read back by {@link BlockData} and {@link
+ * TypedInputStream}
*/
public final class TypedOutputStream implements Flushable, Closeable {
diff --git a/s2storage/src/write/java/com/android/timezone/location/storage/table/packed/write/PackedTableWriter.java b/s2storage/src/write/java/com/android/storage/table/packed/write/PackedTableWriter.java
index f29d31e..617430c 100644
--- a/s2storage/src/write/java/com/android/timezone/location/storage/table/packed/write/PackedTableWriter.java
+++ b/s2storage/src/write/java/com/android/storage/table/packed/write/PackedTableWriter.java
@@ -14,11 +14,11 @@
* limitations under the License.
*/
-package com.android.timezone.location.storage.table.packed.write;
+package com.android.storage.table.packed.write;
-import com.android.timezone.location.storage.io.write.TypedOutputStream;
-import com.android.timezone.location.storage.table.packed.read.PackedTableReader;
-import com.android.timezone.location.storage.util.BitwiseUtils;
+import com.android.storage.io.write.TypedOutputStream;
+import com.android.storage.table.packed.read.PackedTableReader;
+import com.android.storage.util.BitwiseUtils;
import java.io.IOException;
import java.io.OutputStream;
diff --git a/s2storage/tools/Android.bp b/s2storage/tools/Android.bp
index 79e6884..f26cfd5 100644
--- a/s2storage/tools/Android.bp
+++ b/s2storage/tools/Android.bp
@@ -17,51 +17,21 @@ package {
}
java_library_host {
- name: "geotz_s2storage_tools",
+ name: "s2storage_tools",
srcs: [
"src/java/**/*.java",
],
static_libs: [
- "geotz_host_common",
- "geotz_s2storage_tools_protos",
- "geotz_s2storage_rw",
+ "s2storage_rw",
"jcommander",
- "libprotobuf-java-full",
- ],
-}
-
-java_library_host {
- name: "geotz_s2storage_tools_protos",
- srcs: ["src/proto/**/*.proto"],
- proto: {
- type: "full",
- include_dirs: ["external/protobuf/src"],
- },
-}
-
-// A tool to dump a tzs2 file as text for debugging.
-java_binary_host {
- name: "geotz_dumptzs2file",
- main_class: "com.android.timezone.location.tools.tzs2.DumpTzS2File",
- static_libs: [
- "geotz_s2storage_tools",
],
}
// A tool to dump a block file as text for debugging.
java_binary_host {
- name: "geotz_dumpblockfile",
- main_class: "com.android.timezone.location.tools.block.DumpBlockFile",
- static_libs: [
- "geotz_s2storage_tools",
- ],
-}
-
-// A tool to create a tzs2 file from protos.
-java_binary_host {
- name: "geotz_createtzs2file",
- main_class: "com.android.timezone.location.tools.tzs2.CreateTzS2File",
+ name: "s2storage_dumpblockfile",
+ main_class: "com.android.storage.tools.block.DumpBlockFile",
static_libs: [
- "geotz_s2storage_tools",
+ "s2storage_tools",
],
}
diff --git a/s2storage/tools/src/java/com/android/timezone/location/tools/block/DumpBlockFile.java b/s2storage/tools/src/java/com/android/storage/tools/block/DumpBlockFile.java
index 64f813a..e35469e 100644
--- a/s2storage/tools/src/java/com/android/timezone/location/tools/block/DumpBlockFile.java
+++ b/s2storage/tools/src/java/com/android/storage/tools/block/DumpBlockFile.java
@@ -14,10 +14,10 @@
* limitations under the License.
*/
-package com.android.timezone.location.tools.block;
+package com.android.storage.tools.block;
-import com.android.timezone.location.storage.block.read.BlockFileReader;
-import com.android.timezone.location.tools.block.dump.BlockFileDumper;
+import com.android.storage.block.read.BlockFileReader;
+import com.android.storage.tools.block.dump.BlockFileDumper;
import java.io.File;
diff --git a/s2storage/tools/src/java/com/android/timezone/location/tools/block/dump/BlockDumper.java b/s2storage/tools/src/java/com/android/storage/tools/block/dump/BlockDumper.java
index df09e4f..980694a 100644
--- a/s2storage/tools/src/java/com/android/timezone/location/tools/block/dump/BlockDumper.java
+++ b/s2storage/tools/src/java/com/android/storage/tools/block/dump/BlockDumper.java
@@ -14,9 +14,9 @@
* limitations under the License.
*/
-package com.android.timezone.location.tools.block.dump;
+package com.android.storage.tools.block.dump;
-import com.android.timezone.location.storage.block.read.Block;
+import com.android.storage.block.read.Block;
import java.io.File;
diff --git a/s2storage/tools/src/java/com/android/timezone/location/tools/block/dump/BlockFileDumper.java b/s2storage/tools/src/java/com/android/storage/tools/block/dump/BlockFileDumper.java
index 20365c5..a206273 100644
--- a/s2storage/tools/src/java/com/android/timezone/location/tools/block/dump/BlockFileDumper.java
+++ b/s2storage/tools/src/java/com/android/storage/tools/block/dump/BlockFileDumper.java
@@ -14,13 +14,13 @@
* limitations under the License.
*/
-package com.android.timezone.location.tools.block.dump;
+package com.android.storage.tools.block.dump;
-import static com.android.timezone.location.tools.block.dump.DumpUtils.createPrintWriter;
+import static com.android.storage.tools.block.dump.DumpUtils.createPrintWriter;
-import com.android.timezone.location.storage.block.read.Block;
-import com.android.timezone.location.storage.block.read.BlockFileReader.BlockFileVisitor;
-import com.android.timezone.location.storage.block.read.BlockInfo;
+import com.android.storage.block.read.Block;
+import com.android.storage.block.read.BlockFileReader.BlockFileVisitor;
+import com.android.storage.block.read.BlockInfo;
import java.io.File;
import java.io.PrintWriter;
diff --git a/s2storage/tools/src/java/com/android/timezone/location/tools/block/dump/BlockInfoDumper.java b/s2storage/tools/src/java/com/android/storage/tools/block/dump/BlockInfoDumper.java
index 79513bb..4168438 100644
--- a/s2storage/tools/src/java/com/android/timezone/location/tools/block/dump/BlockInfoDumper.java
+++ b/s2storage/tools/src/java/com/android/storage/tools/block/dump/BlockInfoDumper.java
@@ -14,9 +14,9 @@
* limitations under the License.
*/
-package com.android.timezone.location.tools.block.dump;
+package com.android.storage.tools.block.dump;
-import com.android.timezone.location.storage.block.read.BlockInfo;
+import com.android.storage.block.read.BlockInfo;
import java.io.File;
import java.util.Arrays;
diff --git a/s2storage/tools/src/java/com/android/timezone/location/tools/block/dump/DumpUtils.java b/s2storage/tools/src/java/com/android/storage/tools/block/dump/DumpUtils.java
index 2ee6033..f2f1ba9 100644
--- a/s2storage/tools/src/java/com/android/timezone/location/tools/block/dump/DumpUtils.java
+++ b/s2storage/tools/src/java/com/android/storage/tools/block/dump/DumpUtils.java
@@ -14,9 +14,9 @@
* limitations under the License.
*/
-package com.android.timezone.location.tools.block.dump;
+package com.android.storage.tools.block.dump;
-import com.android.timezone.location.storage.util.Visitor;
+import com.android.storage.util.Visitor;
import java.io.File;
import java.io.FileOutputStream;
diff --git a/s2storage/tools/src/java/com/android/timezone/location/tools/block/dump/SingleFileDumper.java b/s2storage/tools/src/java/com/android/storage/tools/block/dump/SingleFileDumper.java
index c80f949..992b830 100644
--- a/s2storage/tools/src/java/com/android/timezone/location/tools/block/dump/SingleFileDumper.java
+++ b/s2storage/tools/src/java/com/android/storage/tools/block/dump/SingleFileDumper.java
@@ -14,11 +14,11 @@
* limitations under the License.
*/
-package com.android.timezone.location.tools.block.dump;
+package com.android.storage.tools.block.dump;
-import static com.android.timezone.location.tools.block.dump.DumpUtils.createPrintWriter;
+import static com.android.storage.tools.block.dump.DumpUtils.createPrintWriter;
-import com.android.timezone.location.storage.util.Visitor;
+import com.android.storage.util.Visitor;
import java.io.File;
import java.io.PrintWriter;
diff --git a/tzs2storage/Android.bp b/tzs2storage/Android.bp
new file mode 100644
index 0000000..1fb3587
--- /dev/null
+++ b/tzs2storage/Android.bp
@@ -0,0 +1,65 @@
+// Copyright (C) 2020 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// Library for read-only access to TZ S2 data files.
+package {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+// GeoTZ read-only classes (including generic classes)
+java_library {
+ name: "geotz_s2storage_ro",
+ sdk_version: "31",
+ min_sdk_version: "31",
+ host_supported: true,
+ srcs: [
+ "src/readonly/java/com/android/timezone/**/*.java",
+ ],
+ static_libs: [
+ "s2storage_ro",
+ ],
+ apex_available: [
+ "//apex_available:platform",
+ "com.android.geotz",
+ ],
+}
+
+// Library for read/write access to TZ S2 data files.
+java_library_host {
+ name: "geotz_s2storage_rw",
+ srcs: [
+ "src/write/java/**/*.java",
+ ],
+ static_libs: [
+ "geotz_s2storage_ro",
+ "s2storage_rw",
+ ],
+}
+
+// Tests for the TZ S2 storage code.
+java_test_host {
+ name: "geotz_s2storage_tests",
+
+ srcs: ["src/test/java/**/*.java"],
+ static_libs: [
+ "s2storage_testing",
+ "geotz_s2storage_rw",
+ "junit",
+ "mockito",
+ "objenesis",
+ ],
+ test_options: {
+ unit_test: true,
+ },
+}
diff --git a/tzs2storage/README.md b/tzs2storage/README.md
new file mode 100644
index 0000000..b2899a9
--- /dev/null
+++ b/tzs2storage/README.md
@@ -0,0 +1,208 @@
+This directory contains files related to storage of TZ S2 data files used for offline geolocation
+time zone detection.
+
+High level file structure
+=========================
+
+ * `src/readonly/` - host + device code for reading TZ S2 data files
+ * `src/write/` - host code for writing TZ S2 data files
+ * `src/test/` - host tests for readonly/ and write/ code
+ * `tools/` - host tooling to support generation / debugging / testing of TZ S2 data
+ files.
+
+Format overview
+===============
+
+The TZ S2 data file format builds on top of a generic "block file format" where
+most of the blocks are "packed tables". See the README.md associated with the
+com.android.storage classes for more information.
+
+Block file format information
+=============================
+
+A "block file" is a general-purpose file format containing a small amount of header information,
+blocks of data, and metadata about those blocks. All types are big-endian / network byte ordered.
+
+Blocks are assigned contiguous IDs which are numbered from zero.
+
+1. The file header has a type-identifying magic, and a version.
+2. Next are the block infos, which hold metadata about all blocks in the file such as their ID,
+a type ID, (optional) arbitrary "extra" bytes, and size / offset information for the block.
+3. Lastly, come the blocks of data themselves. Blocks can be zero-length, in which case they take up
+no space in the file.
+
+Packed tables
+=============
+
+Packed tables are a way of arranging block data to store tables of key-ordered key / value pairs in
+a compact way. Each entry in the table takes up a fixed number of bytes.
+
+Packed tables may contain some (optional) shared information that applies to all records in the
+table. Then they contain one or more fixed length `{key}`/`{value}` records of `{R}` bits sorted by
+`{key}`. The table data is easily memory mapped and each record can be randomly accessed by
+`{key}`.
+
+TZ S2 data file format information
+==================================
+
+The TZ S2 data file is a type of block file that uses packed tables. It overlays additional rules,
+block types, etc. on top of the general block file format.
+
+High level description
+----------------------
+
+The TZ S2 data file format is intended to be language neutral (e.g. Java or C code could easily be
+written to read it with minimal dependencies), providing a good balance between file size,
+extensibility and memory usage at runtime.
+
+It is designed to be flexible and parameterized / self describing: the header block contains format
+information needed to locate and interpret the data storage blocks.
+
+The file stores time zone geolocation data at a single S2 level. Logically, the data consists of:
+
+```
+{start S2 cell ID (inclusive)}, {end S2 cell ID (exclusive)}, {time zone IDs}
+```
+
+The main usecase of the file is to lookup the time zone ID(s) (if any) for a given S2 cell ID.
+
+General storage approach
+------------------------
+
+To keep the file size to a minimum, the format avoids storing 64-bit S2 cell IDs directly. Instead,
+the logical input data is mapped to a data structure that allows the individual S2 cell IDs to be
+stored using only a subset of the bits needed to store a full S2 cell ID.
+
+Each logical S2 range data described above is subdivided into ranges with a common S2 cell ID
+prefix. Any ranges in the source data that span a prefix are split into smaller ranges to preserve
+the "same prefix" property. All ranges with a common prefix can be stored in one "suffix table".
+
+The time zone ID strings are also only stored once and are referenced indirectly, avoiding repeated
+storage of common strings.
+
+TZ S2 data lookup
+-----------------
+
+Suffix table block IDs are calculated by taking the prefix of the S2 cell ID being sought and
+applying a fixed offset. The block info and block data for the cell's suffix table can be accessed
+directly using the block's ID.
+
+Specifically:
+
+The `{prefix}` is computed by extracting the first `{X}` bits of the S2 cell ID. The `{prefix}` is
+used to obtain the `{block ID}` of the block used to store the suffix table. The `{block ID}` is
+calculated by adding a fixed offset (obtained from the header block) to the cell ID `{prefix}`.
+
+The `{block ID}` is first used to look lookup the block info. If the length of the block with
+`{block ID}` is zero, the lookup stops at this point as it means there are no ranges for `{prefix}`.
+
+When the `{block ID}` block is non-zero length, the block is interpreted as a packed table
+(described above) which stores the suffix table's entries.
+
+The `{suffix}`, the final `{Y}` bits of the search S2 cell ID, is used to seek for a record
+containing the s2 range holding that cell ID, if any. The `{suffix}` will match either no records or
+only one record in the table.
+
+For more information on suffix table storage, see the Suffix Table Blocks section below.
+
+The Header Block
+----------------
+
+The header block is always required to be block zero and have the expected type
+ID (1).
+
+The header contains format information needed to address the suffix table blocks
+and the block format information needed to interpret those blocks. It also
+contains information shared by all blocks such as the TZ ID sets.
+
+TZ ID Sets storage
+------------------
+
+Sets of one or more time zone IDs are referenced by every range stored in the TZ S2 data file.
+
+Individual time zone IDs are strings like "America/Los_Angeles" that should only be stored once to
+conserve space.
+
+Further, the time zone IDs are referenced as sets, e.g. one cell range may reference
+"Europe/London", another may reference "Europe/Paris" and another may reference
+both "Europe/London" and "Europe/Paris".
+
+It is important to keep the number of bits used in each suffix table entry to a
+minimum because there are hundreds of thousands of ranges globally and hundreds
+of distinct sets. To do this we make use of "banking", which leverages
+properties of the data.
+
+For example:
+
+1. Several ranges with S2 cell IDs close together may reference the same set - e.g. there
+will be several range entries that reference "Europe/London".
+2. There is unlikely to a single S2 cell that needs to reference both "America/Los_Angeles" and
+"Europe/London", since the areas covered by those time zone IDs are geographically separate.
+
+Consequently:
+
+Every time zone ID string referenced in the file is assigned a numeric ID. The string is stored once
+in the file in the header block. All references to time zone IDs are made via the numeric ID.
+
+e.g.
+```
+1: Europe/London
+2: Europe/Paris
+3: ...
+```
+
+Every TZ S2 data file has one or more "set banks". Each bank contains an array of `{set of time zone
+IDs}`.
+
+A bank may contain many sets, which various combinations of TZ IDs:
+```
+1: {1} - meaning the set {"Europe/London"}
+2: {2} - meaning the set {"Europe/Paris"}
+3: {1,2} - meaning the set {"Europe/London", "Europe/Paris"}
+...
+```
+
+Via this indirection and banking, each range entry can address a set of time zone ID strings using
+only a numeric bank ID and a numeric set ID. The bank ID is the same for all entries in suffix
+table, so this means that it can be stored once per table and only the (small) `{TZ IDs set ID}`
+needs to be stored with each entry.
+
+Suffix Table Blocks
+-------------------
+
+The suffix table block is a packed table with shared information and one or more entries.
+
+The shared information consists of:
+
+```
+{TZ IDs set bank} - the bank ID of the TZ IDs set bank used when looking up time zone set IDs
+ referenced by all table entries.
+```
+
+Each record in the suffix table logically holds entries consisting of:
+```
+{start S2 cell ID (inclusive)}, {end S2 cell ID (exclusive)}, {time zone IDs}`
+```
+
+As with any packed table, each record in the packed table has a fixed width of `{R}` bits. The first
+`{M}` bits of every record are used to store the (ordered) `{key}`.
+
+The `{key}` for an entry contains only the `{suffix}` bits from the `{start S2 cell ID
+(inclusive)}`. To reconstruct the `{start S2 cell ID (inclusive)}` it's only necessary to know
+the `{prefix}` for the table and the `{key}`.
+
+The remaining (`{R-M}`) bits are used to store the ``{value}``. The ``{value}`` is further
+sub-divided into two: the `{end S2 cell ID offset}` and the `{TZ IDs set ID}`.
+
+The `{end S2 cell ID offset}` is a transformation of the `{end S2 cell ID (exclusive)}`. The `{end
+S2 cell ID}` can be calculated by adding the `{end S2 cell ID offset}` to the `{start S2 cell ID
+(inclusive)}`.
+
+When searching for an S2 cell ID, the prefix is used to locate the correct suffix table. The suffix
+bits from the S2 cell ID can be extracted. Since all data in the table is held at a single S2 level,
+the suffix bits can be used to binary search the suffix table entries by looking for an entry
+containing the suffix bits, i.e. by comparing the suffix bits against the `{key}` and `{key}` +
+`{end S2 cell ID offset}` value.
+
+If an entry is found, the `{TZ set ID}` indirectly leads to the `{time zone IDs}` for the range. For
+more information see TZ ID Sets storage above.
diff --git a/s2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/BankedTzIdSets.java b/tzs2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/BankedTzIdSets.java
index 6046e36..6046e36 100644
--- a/s2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/BankedTzIdSets.java
+++ b/tzs2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/BankedTzIdSets.java
diff --git a/s2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/SuffixTableRange.java b/tzs2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/SuffixTableRange.java
index 82ebe4e..b5970cf 100644
--- a/s2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/SuffixTableRange.java
+++ b/tzs2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/SuffixTableRange.java
@@ -16,10 +16,10 @@
package com.android.timezone.location.storage.tzs2range;
-import static com.android.timezone.location.storage.s2.S2Support.cellIdToString;
+import static com.android.storage.s2.S2Support.cellIdToString;
-import com.android.timezone.location.storage.s2.S2CellOrdering;
-import com.android.timezone.location.storage.s2.S2LevelRange;
+import com.android.storage.s2.S2CellOrdering;
+import com.android.storage.s2.S2LevelRange;
import java.util.Objects;
diff --git a/s2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/SuffixTableSharedData.java b/tzs2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/SuffixTableSharedData.java
index 1f03b2a..d87c34c 100644
--- a/s2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/SuffixTableSharedData.java
+++ b/tzs2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/SuffixTableSharedData.java
@@ -16,8 +16,8 @@
package com.android.timezone.location.storage.tzs2range;
-import com.android.timezone.location.storage.io.read.TypedInputStream;
-import com.android.timezone.location.storage.table.reader.Table;
+import com.android.storage.io.read.TypedInputStream;
+import com.android.storage.table.reader.Table;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -89,7 +89,7 @@ public final class SuffixTableSharedData {
*/
public static SuffixTableSharedData fromBytes(byte[] bytes) {
try (ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
- TypedInputStream tis = new TypedInputStream(bis)) {
+ TypedInputStream tis = new TypedInputStream(bis)) {
int tablePrefixValue = tis.readInt();
int tzIdSetBank = tis.readInt();
if (tzIdSetBank < 0) {
diff --git a/s2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/TzS2Range.java b/tzs2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/TzS2Range.java
index 9fc752e..39cd841 100644
--- a/s2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/TzS2Range.java
+++ b/tzs2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/TzS2Range.java
@@ -16,11 +16,11 @@
package com.android.timezone.location.storage.tzs2range;
-import static com.android.timezone.location.storage.s2.S2Support.cellIdToString;
+import static com.android.storage.s2.S2Support.cellIdToString;
-import com.android.timezone.location.storage.s2.S2CellOrdering;
-import com.android.timezone.location.storage.s2.S2LevelRange;
-import com.android.timezone.location.storage.s2.S2Support;
+import com.android.storage.s2.S2CellOrdering;
+import com.android.storage.s2.S2LevelRange;
+import com.android.storage.s2.S2Support;
import java.util.ArrayList;
import java.util.Collections;
diff --git a/s2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/TzS2RangeFileFormat.java b/tzs2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/TzS2RangeFileFormat.java
index 2671512..15ba7ec 100644
--- a/s2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/TzS2RangeFileFormat.java
+++ b/tzs2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/TzS2RangeFileFormat.java
@@ -16,22 +16,22 @@
package com.android.timezone.location.storage.tzs2range;
-import static com.android.timezone.location.storage.s2.S2Support.FACE_BIT_COUNT;
-import static com.android.timezone.location.storage.s2.S2Support.MAX_FACE_ID;
-import static com.android.timezone.location.storage.s2.S2Support.MAX_S2_LEVEL;
+import static com.android.storage.s2.S2Support.FACE_BIT_COUNT;
+import static com.android.storage.s2.S2Support.MAX_FACE_ID;
+import static com.android.storage.s2.S2Support.MAX_S2_LEVEL;
-import com.android.timezone.location.storage.s2.S2Support;
-import com.android.timezone.location.storage.util.BitwiseUtils;
-import com.android.timezone.location.storage.util.Conditions;
+import com.android.storage.block.read.BlockFileReader;
+import com.android.storage.s2.S2Support;
+import com.android.storage.util.BitwiseUtils;
+import com.android.storage.util.Conditions;
import java.util.Objects;
/**
* Holds information about the format of a tz s2 data file, which is a type of block file (see
- * {@link com.android.timezone.location.storage.block.read.BlockFileReader}).
- * Some information is hardcode and some is parameterized using information read from the file's
- * header block. This class contains useful methods for validation, interpretation and storage of
- * data in a file with the specified format.
+ * {@link BlockFileReader}). Some information is hardcoded and some is parameterized using
+ * information read from the file's header block. This class contains useful methods for
+ * validation, interpretation and storage of data in a file with the specified format.
*/
public final class TzS2RangeFileFormat {
diff --git a/s2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/read/HeaderBlock.java b/tzs2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/read/HeaderBlock.java
index 0331391..e43ce61 100644
--- a/s2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/read/HeaderBlock.java
+++ b/tzs2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/read/HeaderBlock.java
@@ -16,10 +16,10 @@
package com.android.timezone.location.storage.tzs2range.read;
-import com.android.timezone.location.storage.block.read.BlockData;
+import com.android.storage.block.read.BlockData;
+import com.android.storage.util.Visitor;
import com.android.timezone.location.storage.tzs2range.BankedTzIdSets;
import com.android.timezone.location.storage.tzs2range.TzS2RangeFileFormat;
-import com.android.timezone.location.storage.util.Visitor;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
diff --git a/s2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/read/PopulatedSuffixTableBlock.java b/tzs2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/read/PopulatedSuffixTableBlock.java
index d701d83..a6bc33d 100644
--- a/s2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/read/PopulatedSuffixTableBlock.java
+++ b/tzs2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/read/PopulatedSuffixTableBlock.java
@@ -16,12 +16,12 @@
package com.android.timezone.location.storage.tzs2range.read;
-import static com.android.timezone.location.storage.s2.S2Support.MAX_FACE_ID;
-import static com.android.timezone.location.storage.s2.S2Support.cellIdToString;
-import static com.android.timezone.location.storage.util.Conditions.checkStateInRange;
+import static com.android.storage.s2.S2Support.MAX_FACE_ID;
+import static com.android.storage.s2.S2Support.cellIdToString;
+import static com.android.storage.util.Conditions.checkStateInRange;
-import com.android.timezone.location.storage.table.packed.read.IntValueTypedPackedTable;
-import com.android.timezone.location.storage.table.reader.IntValueTable;
+import com.android.storage.table.packed.read.IntValueTypedPackedTable;
+import com.android.storage.table.reader.IntValueTable;
import com.android.timezone.location.storage.tzs2range.SuffixTableRange;
import com.android.timezone.location.storage.tzs2range.SuffixTableSharedData;
import com.android.timezone.location.storage.tzs2range.TzS2RangeFileFormat;
diff --git a/s2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/read/SuffixTableBlock.java b/tzs2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/read/SuffixTableBlock.java
index 0a1bc30..f50d036 100644
--- a/s2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/read/SuffixTableBlock.java
+++ b/tzs2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/read/SuffixTableBlock.java
@@ -16,15 +16,15 @@
package com.android.timezone.location.storage.tzs2range.read;
-import static com.android.timezone.location.storage.s2.S2Support.cellIdToString;
-import static com.android.timezone.location.storage.s2.S2Support.getS2Level;
+import static com.android.storage.s2.S2Support.cellIdToString;
+import static com.android.storage.s2.S2Support.getS2Level;
-import com.android.timezone.location.storage.block.read.BlockData;
-import com.android.timezone.location.storage.table.packed.read.IntValueTypedPackedTable;
+import com.android.storage.block.read.BlockData;
+import com.android.storage.table.packed.read.IntValueTypedPackedTable;
+import com.android.storage.util.BitwiseUtils;
+import com.android.storage.util.Visitor;
import com.android.timezone.location.storage.tzs2range.SuffixTableRange;
import com.android.timezone.location.storage.tzs2range.TzS2RangeFileFormat;
-import com.android.timezone.location.storage.util.BitwiseUtils;
-import com.android.timezone.location.storage.util.Visitor;
import java.util.Objects;
diff --git a/s2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/read/SuffixTableExtraInfo.java b/tzs2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/read/SuffixTableExtraInfo.java
index de7d89e..38f184d 100644
--- a/s2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/read/SuffixTableExtraInfo.java
+++ b/tzs2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/read/SuffixTableExtraInfo.java
@@ -16,10 +16,10 @@
package com.android.timezone.location.storage.tzs2range.read;
-import com.android.timezone.location.storage.block.read.BlockInfo;
-import com.android.timezone.location.storage.io.read.TypedInputStream;
+import com.android.storage.block.read.BlockInfo;
+import com.android.storage.io.read.TypedInputStream;
+import com.android.storage.util.Conditions;
import com.android.timezone.location.storage.tzs2range.TzS2RangeFileFormat;
-import com.android.timezone.location.storage.util.Conditions;
import java.io.ByteArrayInputStream;
import java.io.IOException;
diff --git a/s2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/read/TzS2RangeFileReader.java b/tzs2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/read/TzS2RangeFileReader.java
index 421c9f5..d6ecda2 100644
--- a/s2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/read/TzS2RangeFileReader.java
+++ b/tzs2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/read/TzS2RangeFileReader.java
@@ -16,16 +16,16 @@
package com.android.timezone.location.storage.tzs2range.read;
-import com.android.timezone.location.storage.block.read.Block;
-import com.android.timezone.location.storage.block.read.BlockFileReader;
-import com.android.timezone.location.storage.block.read.BlockInfo;
-import com.android.timezone.location.storage.s2.S2Support;
+import com.android.storage.block.read.Block;
+import com.android.storage.block.read.BlockFileReader;
+import com.android.storage.block.read.BlockInfo;
+import com.android.storage.s2.S2Support;
+import com.android.storage.util.Conditions;
+import com.android.storage.util.Visitor;
import com.android.timezone.location.storage.tzs2range.BankedTzIdSets;
import com.android.timezone.location.storage.tzs2range.SuffixTableRange;
import com.android.timezone.location.storage.tzs2range.TzS2Range;
import com.android.timezone.location.storage.tzs2range.TzS2RangeFileFormat;
-import com.android.timezone.location.storage.util.Conditions;
-import com.android.timezone.location.storage.util.Visitor;
import java.io.File;
import java.io.IOException;
diff --git a/s2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/read/UnpopulatedSuffixTableBlock.java b/tzs2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/read/UnpopulatedSuffixTableBlock.java
index ce3b168..ce3b168 100644
--- a/s2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/read/UnpopulatedSuffixTableBlock.java
+++ b/tzs2storage/src/readonly/java/com/android/timezone/location/storage/tzs2range/read/UnpopulatedSuffixTableBlock.java
diff --git a/s2storage/src/test/java/com/android/timezone/location/storage/tzs2range/BankedTzIdSetsTest.java b/tzs2storage/src/test/java/com/android/timezone/location/storage/tzs2range/BankedTzIdSetsTest.java
index 5dc2838..a389e6b 100644
--- a/s2storage/src/test/java/com/android/timezone/location/storage/tzs2range/BankedTzIdSetsTest.java
+++ b/tzs2storage/src/test/java/com/android/timezone/location/storage/tzs2range/BankedTzIdSetsTest.java
@@ -16,8 +16,8 @@
package com.android.timezone.location.storage.tzs2range;
-import static com.android.timezone.location.storage.testing.MoreAsserts.assertThrows;
-import static com.android.timezone.location.storage.testing.TestSupport.listOf;
+import static com.android.storage.testing.MoreAsserts.assertThrows;
+import static com.android.storage.testing.TestSupport.listOf;
import static org.junit.Assert.assertEquals;
diff --git a/s2storage/src/test/java/com/android/timezone/location/storage/tzs2range/HeaderBlockTest.java b/tzs2storage/src/test/java/com/android/timezone/location/storage/tzs2range/HeaderBlockTest.java
index 02af01f..edb369d 100644
--- a/s2storage/src/test/java/com/android/timezone/location/storage/tzs2range/HeaderBlockTest.java
+++ b/tzs2storage/src/test/java/com/android/timezone/location/storage/tzs2range/HeaderBlockTest.java
@@ -16,12 +16,12 @@
package com.android.timezone.location.storage.tzs2range;
-import static com.android.timezone.location.storage.testing.TestSupport.listOf;
+import static com.android.storage.testing.TestSupport.listOf;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
-import com.android.timezone.location.storage.block.write.BlockWriter;
+import com.android.storage.block.write.BlockWriter;
import com.android.timezone.location.storage.tzs2range.read.HeaderBlock;
import com.android.timezone.location.storage.tzs2range.write.BankedTzIdSetsPacker;
import com.android.timezone.location.storage.tzs2range.write.HeaderBlockWriter;
diff --git a/s2storage/src/test/java/com/android/timezone/location/storage/tzs2range/SuffixTableBlockMatcher.java b/tzs2storage/src/test/java/com/android/timezone/location/storage/tzs2range/SuffixTableBlockMatcher.java
index a33c7c5..a33c7c5 100644
--- a/s2storage/src/test/java/com/android/timezone/location/storage/tzs2range/SuffixTableBlockMatcher.java
+++ b/tzs2storage/src/test/java/com/android/timezone/location/storage/tzs2range/SuffixTableBlockMatcher.java
diff --git a/s2storage/src/test/java/com/android/timezone/location/storage/tzs2range/SuffixTableBlockTest.java b/tzs2storage/src/test/java/com/android/timezone/location/storage/tzs2range/SuffixTableBlockTest.java
index ffedad9..40c0f72 100644
--- a/s2storage/src/test/java/com/android/timezone/location/storage/tzs2range/SuffixTableBlockTest.java
+++ b/tzs2storage/src/test/java/com/android/timezone/location/storage/tzs2range/SuffixTableBlockTest.java
@@ -16,7 +16,7 @@
package com.android.timezone.location.storage.tzs2range;
-import static com.android.timezone.location.storage.testing.MoreAsserts.assertThrows;
+import static com.android.storage.testing.MoreAsserts.assertThrows;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
@@ -24,7 +24,7 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.argThat;
-import com.android.timezone.location.storage.block.write.BlockWriter;
+import com.android.storage.block.write.BlockWriter;
import com.android.timezone.location.storage.tzs2range.read.SuffixTableBlock;
import com.android.timezone.location.storage.tzs2range.write.SuffixTableWriter;
diff --git a/s2storage/src/test/java/com/android/timezone/location/storage/tzs2range/SuffixTableExtraInfoTest.java b/tzs2storage/src/test/java/com/android/timezone/location/storage/tzs2range/SuffixTableExtraInfoTest.java
index 354c290..a791450 100644
--- a/s2storage/src/test/java/com/android/timezone/location/storage/tzs2range/SuffixTableExtraInfoTest.java
+++ b/tzs2storage/src/test/java/com/android/timezone/location/storage/tzs2range/SuffixTableExtraInfoTest.java
@@ -18,8 +18,8 @@ package com.android.timezone.location.storage.tzs2range;
import static org.junit.Assert.assertEquals;
-import com.android.timezone.location.storage.block.read.BlockInfo;
-import com.android.timezone.location.storage.block.write.BlockWriter;
+import com.android.storage.block.read.BlockInfo;
+import com.android.storage.block.write.BlockWriter;
import com.android.timezone.location.storage.tzs2range.read.SuffixTableExtraInfo;
import com.android.timezone.location.storage.tzs2range.write.SuffixTableWriter;
diff --git a/s2storage/src/test/java/com/android/timezone/location/storage/tzs2range/SuffixTableRangeTest.java b/tzs2storage/src/test/java/com/android/timezone/location/storage/tzs2range/SuffixTableRangeTest.java
index a51b344..0c72d84 100644
--- a/s2storage/src/test/java/com/android/timezone/location/storage/tzs2range/SuffixTableRangeTest.java
+++ b/tzs2storage/src/test/java/com/android/timezone/location/storage/tzs2range/SuffixTableRangeTest.java
@@ -16,13 +16,13 @@
package com.android.timezone.location.storage.tzs2range;
-import static com.android.timezone.location.storage.s2.S2Support.cellId;
-import static com.android.timezone.location.storage.testing.MoreAsserts.assertThrows;
+import static com.android.storage.s2.S2Support.cellId;
+import static com.android.storage.testing.MoreAsserts.assertThrows;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
-import com.android.timezone.location.storage.s2.S2Support;
+import com.android.storage.s2.S2Support;
import org.junit.Test;
diff --git a/s2storage/src/test/java/com/android/timezone/location/storage/tzs2range/SuffixTableSharedDataTest.java b/tzs2storage/src/test/java/com/android/timezone/location/storage/tzs2range/SuffixTableSharedDataTest.java
index 6164a76..6164a76 100644
--- a/s2storage/src/test/java/com/android/timezone/location/storage/tzs2range/SuffixTableSharedDataTest.java
+++ b/tzs2storage/src/test/java/com/android/timezone/location/storage/tzs2range/SuffixTableSharedDataTest.java
diff --git a/s2storage/src/test/java/com/android/timezone/location/storage/tzs2range/TzS2RangeFileFormatTest.java b/tzs2storage/src/test/java/com/android/timezone/location/storage/tzs2range/TzS2RangeFileFormatTest.java
index 7bfb741..1939a2e 100644
--- a/s2storage/src/test/java/com/android/timezone/location/storage/tzs2range/TzS2RangeFileFormatTest.java
+++ b/tzs2storage/src/test/java/com/android/timezone/location/storage/tzs2range/TzS2RangeFileFormatTest.java
@@ -16,8 +16,8 @@
package com.android.timezone.location.storage.tzs2range;
-import static com.android.timezone.location.storage.s2.S2Support.cellId;
-import static com.android.timezone.location.storage.testing.MoreAsserts.assertThrows;
+import static com.android.storage.s2.S2Support.cellId;
+import static com.android.storage.testing.MoreAsserts.assertThrows;
import static org.junit.Assert.assertEquals;
diff --git a/s2storage/src/test/java/com/android/timezone/location/storage/tzs2range/TzS2RangeFileTest.java b/tzs2storage/src/test/java/com/android/timezone/location/storage/tzs2range/TzS2RangeFileTest.java
index 1cfe41e..0e7eac1 100644
--- a/s2storage/src/test/java/com/android/timezone/location/storage/tzs2range/TzS2RangeFileTest.java
+++ b/tzs2storage/src/test/java/com/android/timezone/location/storage/tzs2range/TzS2RangeFileTest.java
@@ -16,14 +16,14 @@
package com.android.timezone.location.storage.tzs2range;
-import static com.android.timezone.location.storage.s2.S2Support.FACE_BIT_COUNT;
-import static com.android.timezone.location.storage.testing.TestSupport.listOf;
+import static com.android.storage.s2.S2Support.FACE_BIT_COUNT;
+import static com.android.storage.testing.TestSupport.listOf;
import static org.junit.Assert.assertEquals;
+import com.android.storage.util.BitwiseUtils;
import com.android.timezone.location.storage.tzs2range.read.TzS2RangeFileReader;
import com.android.timezone.location.storage.tzs2range.write.TzS2RangeFileWriter;
-import com.android.timezone.location.storage.util.BitwiseUtils;
import org.junit.Test;
diff --git a/s2storage/src/test/java/com/android/timezone/location/storage/tzs2range/TzS2RangeTest.java b/tzs2storage/src/test/java/com/android/timezone/location/storage/tzs2range/TzS2RangeTest.java
index 2d27d04..b4e94d9 100644
--- a/s2storage/src/test/java/com/android/timezone/location/storage/tzs2range/TzS2RangeTest.java
+++ b/tzs2storage/src/test/java/com/android/timezone/location/storage/tzs2range/TzS2RangeTest.java
@@ -16,14 +16,14 @@
package com.android.timezone.location.storage.tzs2range;
-import static com.android.timezone.location.storage.s2.S2Support.cellId;
-import static com.android.timezone.location.storage.testing.MoreAsserts.assertThrows;
-import static com.android.timezone.location.storage.testing.TestSupport.listOf;
+import static com.android.storage.s2.S2Support.cellId;
+import static com.android.storage.testing.MoreAsserts.assertThrows;
+import static com.android.storage.testing.TestSupport.listOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
-import com.android.timezone.location.storage.s2.S2Support;
+import com.android.storage.s2.S2Support;
import org.junit.Test;
diff --git a/s2storage/src/test/java/com/android/timezone/location/storage/tzs2range/write/BankedTzIdSetsPackerTest.java b/tzs2storage/src/test/java/com/android/timezone/location/storage/tzs2range/write/BankedTzIdSetsPackerTest.java
index 1825336..066405a 100644
--- a/s2storage/src/test/java/com/android/timezone/location/storage/tzs2range/write/BankedTzIdSetsPackerTest.java
+++ b/tzs2storage/src/test/java/com/android/timezone/location/storage/tzs2range/write/BankedTzIdSetsPackerTest.java
@@ -16,10 +16,10 @@
package com.android.timezone.location.storage.tzs2range.write;
-import static com.android.timezone.location.storage.s2.S2Support.cellId;
-import static com.android.timezone.location.storage.testing.MoreAsserts.assertThrows;
-import static com.android.timezone.location.storage.testing.TestSupport.listOf;
-import static com.android.timezone.location.storage.testing.TestSupport.setOf;
+import static com.android.storage.s2.S2Support.cellId;
+import static com.android.storage.testing.MoreAsserts.assertThrows;
+import static com.android.storage.testing.TestSupport.listOf;
+import static com.android.storage.testing.TestSupport.setOf;
import static org.junit.Assert.assertEquals;
diff --git a/s2storage/src/test/java/com/android/timezone/location/storage/tzs2range/write/PushBackIteratorTest.java b/tzs2storage/src/test/java/com/android/timezone/location/storage/tzs2range/write/PushBackIteratorTest.java
index 8d4ca50..0182ee7 100644
--- a/s2storage/src/test/java/com/android/timezone/location/storage/tzs2range/write/PushBackIteratorTest.java
+++ b/tzs2storage/src/test/java/com/android/timezone/location/storage/tzs2range/write/PushBackIteratorTest.java
@@ -16,8 +16,8 @@
package com.android.timezone.location.storage.tzs2range.write;
-import static com.android.timezone.location.storage.testing.MoreAsserts.assertThrows;
-import static com.android.timezone.location.storage.testing.TestSupport.listOf;
+import static com.android.storage.testing.MoreAsserts.assertThrows;
+import static com.android.storage.testing.TestSupport.listOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
diff --git a/s2storage/src/write/java/com/android/timezone/location/storage/tzs2range/write/BankedTzIdSetsPacker.java b/tzs2storage/src/write/java/com/android/timezone/location/storage/tzs2range/write/BankedTzIdSetsPacker.java
index e4a7666..e4a7666 100644
--- a/s2storage/src/write/java/com/android/timezone/location/storage/tzs2range/write/BankedTzIdSetsPacker.java
+++ b/tzs2storage/src/write/java/com/android/timezone/location/storage/tzs2range/write/BankedTzIdSetsPacker.java
diff --git a/s2storage/src/write/java/com/android/timezone/location/storage/tzs2range/write/HeaderBlockWriter.java b/tzs2storage/src/write/java/com/android/timezone/location/storage/tzs2range/write/HeaderBlockWriter.java
index e9ee43c..3e8099f 100644
--- a/s2storage/src/write/java/com/android/timezone/location/storage/tzs2range/write/HeaderBlockWriter.java
+++ b/tzs2storage/src/write/java/com/android/timezone/location/storage/tzs2range/write/HeaderBlockWriter.java
@@ -16,9 +16,9 @@
package com.android.timezone.location.storage.tzs2range.write;
-import com.android.timezone.location.storage.block.read.BlockData;
-import com.android.timezone.location.storage.block.write.BlockWriter;
-import com.android.timezone.location.storage.io.write.TypedOutputStream;
+import com.android.storage.block.read.BlockData;
+import com.android.storage.block.write.BlockWriter;
+import com.android.storage.io.write.TypedOutputStream;
import com.android.timezone.location.storage.tzs2range.BankedTzIdSets;
import com.android.timezone.location.storage.tzs2range.TzS2RangeFileFormat;
diff --git a/s2storage/src/write/java/com/android/timezone/location/storage/tzs2range/write/PushBackIterator.java b/tzs2storage/src/write/java/com/android/timezone/location/storage/tzs2range/write/PushBackIterator.java
index 122cab4..122cab4 100644
--- a/s2storage/src/write/java/com/android/timezone/location/storage/tzs2range/write/PushBackIterator.java
+++ b/tzs2storage/src/write/java/com/android/timezone/location/storage/tzs2range/write/PushBackIterator.java
diff --git a/s2storage/src/write/java/com/android/timezone/location/storage/tzs2range/write/SuffixTableSharedDataWriter.java b/tzs2storage/src/write/java/com/android/timezone/location/storage/tzs2range/write/SuffixTableSharedDataWriter.java
index 8094dd3..a3e7a50 100644
--- a/s2storage/src/write/java/com/android/timezone/location/storage/tzs2range/write/SuffixTableSharedDataWriter.java
+++ b/tzs2storage/src/write/java/com/android/timezone/location/storage/tzs2range/write/SuffixTableSharedDataWriter.java
@@ -16,7 +16,7 @@
package com.android.timezone.location.storage.tzs2range.write;
-import com.android.timezone.location.storage.io.write.TypedOutputStream;
+import com.android.storage.io.write.TypedOutputStream;
import com.android.timezone.location.storage.tzs2range.SuffixTableSharedData;
import java.io.ByteArrayOutputStream;
@@ -34,7 +34,7 @@ public final class SuffixTableSharedDataWriter {
/** Returns the byte[] for the supplied {@link SuffixTableSharedData} */
public static byte[] toBytes(SuffixTableSharedData suffixTableSharedData) {
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
- TypedOutputStream tos = new TypedOutputStream(baos)) {
+ TypedOutputStream tos = new TypedOutputStream(baos)) {
tos.writeInt(suffixTableSharedData.getTablePrefix());
tos.writeInt(suffixTableSharedData.getTzIdSetBank());
tos.flush();
diff --git a/s2storage/src/write/java/com/android/timezone/location/storage/tzs2range/write/SuffixTableWriter.java b/tzs2storage/src/write/java/com/android/timezone/location/storage/tzs2range/write/SuffixTableWriter.java
index e6d2a65..a8cdf8c 100644
--- a/s2storage/src/write/java/com/android/timezone/location/storage/tzs2range/write/SuffixTableWriter.java
+++ b/tzs2storage/src/write/java/com/android/timezone/location/storage/tzs2range/write/SuffixTableWriter.java
@@ -16,14 +16,14 @@
package com.android.timezone.location.storage.tzs2range.write;
-import static com.android.timezone.location.storage.s2.S2Support.cellIdToString;
-
-import com.android.timezone.location.storage.block.read.BlockData;
-import com.android.timezone.location.storage.block.write.BlockWriter;
-import com.android.timezone.location.storage.block.write.EmptyBlockWriter;
-import com.android.timezone.location.storage.io.write.TypedOutputStream;
-import com.android.timezone.location.storage.s2.S2Support;
-import com.android.timezone.location.storage.table.packed.write.PackedTableWriter;
+import static com.android.storage.s2.S2Support.cellIdToString;
+
+import com.android.storage.block.read.BlockData;
+import com.android.storage.block.write.BlockWriter;
+import com.android.storage.block.write.EmptyBlockWriter;
+import com.android.storage.io.write.TypedOutputStream;
+import com.android.storage.s2.S2Support;
+import com.android.storage.table.packed.write.PackedTableWriter;
import com.android.timezone.location.storage.tzs2range.SuffixTableRange;
import com.android.timezone.location.storage.tzs2range.SuffixTableSharedData;
import com.android.timezone.location.storage.tzs2range.TzS2RangeFileFormat;
diff --git a/s2storage/src/write/java/com/android/timezone/location/storage/tzs2range/write/TzS2RangeFileWriter.java b/tzs2storage/src/write/java/com/android/timezone/location/storage/tzs2range/write/TzS2RangeFileWriter.java
index 47d6f93..50d46b4 100644
--- a/s2storage/src/write/java/com/android/timezone/location/storage/tzs2range/write/TzS2RangeFileWriter.java
+++ b/tzs2storage/src/write/java/com/android/timezone/location/storage/tzs2range/write/TzS2RangeFileWriter.java
@@ -16,10 +16,10 @@
package com.android.timezone.location.storage.tzs2range.write;
-import com.android.timezone.location.storage.block.write.BlockFileWriter;
-import com.android.timezone.location.storage.block.write.BlockWriter;
-import com.android.timezone.location.storage.block.write.EmptyBlockWriter;
-import com.android.timezone.location.storage.s2.S2Support;
+import com.android.storage.block.write.BlockFileWriter;
+import com.android.storage.block.write.BlockWriter;
+import com.android.storage.block.write.EmptyBlockWriter;
+import com.android.storage.s2.S2Support;
import com.android.timezone.location.storage.tzs2range.SuffixTableRange;
import com.android.timezone.location.storage.tzs2range.SuffixTableSharedData;
import com.android.timezone.location.storage.tzs2range.TzS2Range;
diff --git a/tzs2storage/tools/Android.bp b/tzs2storage/tools/Android.bp
new file mode 100644
index 0000000..e39ecd0
--- /dev/null
+++ b/tzs2storage/tools/Android.bp
@@ -0,0 +1,59 @@
+// Copyright (C) 2020 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+java_library_host {
+ name: "geotz_s2storage_tools",
+ srcs: [
+ "src/java/com/android/timezone/**/*.java",
+ ],
+ static_libs: [
+ "geotz_host_common",
+ "geotz_s2storage_tools_protos",
+ "geotz_s2storage_rw",
+ "jcommander",
+ "libprotobuf-java-full",
+ "s2storage_tools",
+ ],
+}
+
+java_library_host {
+ name: "geotz_s2storage_tools_protos",
+ srcs: ["src/proto/**/*.proto"],
+ proto: {
+ type: "full",
+ include_dirs: ["external/protobuf/src"],
+ },
+}
+
+// A tool to dump a tzs2 file as text for debugging.
+java_binary_host {
+ name: "geotz_dumptzs2file",
+ main_class: "com.android.timezone.location.tools.tzs2.DumpTzS2File",
+ static_libs: [
+ "geotz_s2storage_tools",
+ ],
+}
+
+// A tool to create a tzs2 file from protos.
+java_binary_host {
+ name: "geotz_createtzs2file",
+ main_class: "com.android.timezone.location.tools.tzs2.CreateTzS2File",
+ static_libs: [
+ "geotz_s2storage_tools",
+ ],
+}
diff --git a/tzs2storage/tools/src/java/com/android/storage/tools/block/DumpBlockFile.java b/tzs2storage/tools/src/java/com/android/storage/tools/block/DumpBlockFile.java
new file mode 100644
index 0000000..e35469e
--- /dev/null
+++ b/tzs2storage/tools/src/java/com/android/storage/tools/block/DumpBlockFile.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.storage.tools.block;
+
+import com.android.storage.block.read.BlockFileReader;
+import com.android.storage.tools.block.dump.BlockFileDumper;
+
+import java.io.File;
+
+/** Dumps low-level information about a block file in text form for debugging / analysis. */
+public final class DumpBlockFile {
+
+ /**
+ * Usage:
+ * DumpBlockFile <[input] block file name> <[output] directory name>
+ */
+ public static void main(String[] args) throws Exception {
+ String blockFileName = args[0];
+ String outputDirName = args[1];
+ boolean memoryMapBlocks = false;
+
+ File outputDir = new File(outputDirName);
+ outputDir.mkdirs();
+
+ File blockFile = new File(blockFileName);
+ try (BlockFileReader reader = BlockFileReader.open(memoryMapBlocks, blockFile)) {
+ reader.visit(new BlockFileDumper(outputDir));
+ }
+ }
+}
diff --git a/tzs2storage/tools/src/java/com/android/storage/tools/block/dump/BlockDumper.java b/tzs2storage/tools/src/java/com/android/storage/tools/block/dump/BlockDumper.java
new file mode 100644
index 0000000..980694a
--- /dev/null
+++ b/tzs2storage/tools/src/java/com/android/storage/tools/block/dump/BlockDumper.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.storage.tools.block.dump;
+
+import com.android.storage.block.read.Block;
+
+import java.io.File;
+
+/** A {@link Block.BlockVisitor} that dumps information to a file. */
+public final class BlockDumper extends SingleFileDumper implements Block.BlockVisitor {
+
+ public BlockDumper(File blockFile) {
+ super(blockFile);
+ }
+
+ @Override
+ public void visit(Block block) {
+ println("id=" + block.getId());
+ println("type=" + block.getType());
+ println("block size=" + block.getData().getSize());
+ }
+}
diff --git a/tzs2storage/tools/src/java/com/android/storage/tools/block/dump/BlockFileDumper.java b/tzs2storage/tools/src/java/com/android/storage/tools/block/dump/BlockFileDumper.java
new file mode 100644
index 0000000..a206273
--- /dev/null
+++ b/tzs2storage/tools/src/java/com/android/storage/tools/block/dump/BlockFileDumper.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.storage.tools.block.dump;
+
+import static com.android.storage.tools.block.dump.DumpUtils.createPrintWriter;
+
+import com.android.storage.block.read.Block;
+import com.android.storage.block.read.BlockFileReader.BlockFileVisitor;
+import com.android.storage.block.read.BlockInfo;
+
+import java.io.File;
+import java.io.PrintWriter;
+
+/** A {@link BlockFileVisitor} that dumps information to multiple files. */
+public final class BlockFileDumper implements BlockFileVisitor {
+
+ private final File mOutputDir;
+
+ private int mBlockCount;
+
+ public BlockFileDumper(File outputDir) {
+ mOutputDir = outputDir;
+ }
+
+ @Override
+ public void visitFileHeader(char magic, int version, int blockCount) throws VisitException {
+ File fileHeaderFile = new File(mOutputDir, "fileheader.txt");
+ try (PrintWriter writer = createPrintWriter(fileHeaderFile)) {
+ writer.println("Magic=" + Integer.toHexString(magic));
+ writer.println("Version=" + version);
+ writer.println("Block count=" + blockCount);
+ }
+ mBlockCount = blockCount;
+ }
+
+ @Override
+ public void visitBlockInfo(BlockInfo blockInfo) throws VisitException {
+ File blockInfoFile = DumpUtils.generateDumpFile(
+ mOutputDir, "blockinfo_", blockInfo.getId(), mBlockCount);
+ blockInfo.visit(new BlockInfoDumper(blockInfoFile));
+ }
+
+ @Override
+ public void visitBlock(Block block) throws VisitException {
+ File blockFile =
+ DumpUtils.generateDumpFile(mOutputDir, "block_", block.getId(), mBlockCount);
+ block.visit(new BlockDumper(blockFile));
+ }
+}
diff --git a/tzs2storage/tools/src/java/com/android/storage/tools/block/dump/BlockInfoDumper.java b/tzs2storage/tools/src/java/com/android/storage/tools/block/dump/BlockInfoDumper.java
new file mode 100644
index 0000000..4168438
--- /dev/null
+++ b/tzs2storage/tools/src/java/com/android/storage/tools/block/dump/BlockInfoDumper.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.storage.tools.block.dump;
+
+import com.android.storage.block.read.BlockInfo;
+
+import java.io.File;
+import java.util.Arrays;
+
+/** A {@link BlockInfo.BlockInfoVisitor} that dumps information to a file. */
+public final class BlockInfoDumper extends SingleFileDumper implements BlockInfo.BlockInfoVisitor {
+
+ public BlockInfoDumper(File file) {
+ super(file);
+ }
+
+ @Override
+ public void visit(BlockInfo blockInfo) throws VisitException {
+ println("id=" + blockInfo.getId());
+ println("type=" + blockInfo.getType());
+ println("extraBytes=" + Arrays.toString(blockInfo.getExtraBytes()));
+ println("blockStateByteOffset=" + blockInfo.getBlockStartByteOffset());
+ println("blockSizeBytes=" + blockInfo.getBlockSizeBytes());
+ }
+}
diff --git a/tzs2storage/tools/src/java/com/android/storage/tools/block/dump/DumpUtils.java b/tzs2storage/tools/src/java/com/android/storage/tools/block/dump/DumpUtils.java
new file mode 100644
index 0000000..f2f1ba9
--- /dev/null
+++ b/tzs2storage/tools/src/java/com/android/storage/tools/block/dump/DumpUtils.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.storage.tools.block.dump;
+
+import com.android.storage.util.Visitor;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.nio.charset.StandardCharsets;
+
+/** Helper methods for dumping data to files. */
+public final class DumpUtils {
+
+ private DumpUtils() {
+ }
+
+ /**
+ * Creates a {@link PrintWriter} that will write to the specified {@link File}.
+ */
+ public static PrintWriter createPrintWriter(File file) throws Visitor.VisitException {
+ try {
+ OutputStreamWriter utf8Writer = new OutputStreamWriter(
+ new FileOutputStream(file), StandardCharsets.UTF_8);
+ return new PrintWriter(utf8Writer);
+ } catch (IOException e) {
+ throw new Visitor.VisitException(e);
+ }
+ }
+
+ /**
+ * Creates a file in the specified directory with a name generated from the other parameters.
+ */
+ public static File generateDumpFile(File dir, String filePrefix, int blockId, int maxBlockId) {
+ final String fileSuffix = ".txt";
+
+ int blockIdLength = hexStringLength(maxBlockId);
+ StringBuilder sb = new StringBuilder(
+ filePrefix.length() + blockIdLength + fileSuffix.length());
+ sb.append(filePrefix);
+
+ String blockIdHex = zeroPadHex(blockIdLength, blockId);
+ sb.append(blockIdHex);
+ sb.append(fileSuffix);
+ return new File(dir, sb.toString());
+ }
+
+ /**
+ * Returns the number of characters needed to represent the specified value as hex.
+ */
+ public static int hexStringLength(int value) {
+ int bitsNeeded = Integer.SIZE - Integer.numberOfLeadingZeros(value);
+ return (bitsNeeded + 3) / 4;
+ }
+
+ /**
+ * Returns the number of characters needed to represent the specified value as a binary text
+ * string.
+ */
+ public static int binaryStringLength(int value) {
+ return Integer.SIZE - Integer.numberOfLeadingZeros(value);
+ }
+
+ /**
+ * Zero-pad the supplied value as hex to the specified length.
+ */
+ public static String zeroPadHex(int length, int value) {
+ String hexString = Integer.toHexString(value);
+ int unpaddedLength = hexString.length();
+ if (unpaddedLength >= length) {
+ return hexString;
+ }
+ return zeroPad(length, hexString);
+ }
+
+ /**
+ * Zero-pad the supplied value as binary to the specified length.
+ */
+ public static String zeroPadBinary(int length, int value) {
+ String binaryString = Integer.toBinaryString(value);
+ int unpaddedLength = binaryString.length();
+ if (unpaddedLength >= length) {
+ return binaryString;
+ }
+ return zeroPad(length, binaryString);
+ }
+
+ private static String zeroPad(int length, String unpaddedValue) {
+ StringBuilder sb = new StringBuilder(length);
+ int zeroPadding = length - unpaddedValue.length();
+ for (int i = 0; i < zeroPadding; i++) {
+ sb.append('0');
+ }
+ sb.append(unpaddedValue);
+ return sb.toString();
+ }
+}
diff --git a/tzs2storage/tools/src/java/com/android/storage/tools/block/dump/SingleFileDumper.java b/tzs2storage/tools/src/java/com/android/storage/tools/block/dump/SingleFileDumper.java
new file mode 100644
index 0000000..992b830
--- /dev/null
+++ b/tzs2storage/tools/src/java/com/android/storage/tools/block/dump/SingleFileDumper.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.storage.tools.block.dump;
+
+import static com.android.storage.tools.block.dump.DumpUtils.createPrintWriter;
+
+import com.android.storage.util.Visitor;
+
+import java.io.File;
+import java.io.PrintWriter;
+import java.util.Objects;
+
+/**
+ * A class that can be used as a base class for a visitor that dumps information to a single file,
+ * or as a helper for one.
+ */
+public class SingleFileDumper implements Visitor {
+
+ private final File mFile;
+
+ protected PrintWriter mWriter;
+
+ /**
+ * Creates a dumper that will dump to the specified file.
+ */
+ public SingleFileDumper(File file) {
+ mFile = Objects.requireNonNull(file);
+ }
+
+ @Override
+ public void begin() throws Visitor.VisitException {
+ mWriter = createPrintWriter(mFile);
+ }
+
+ /**
+ * Prints the string to the file with a trailing newline.
+ */
+ public void println(String string) {
+ mWriter.println(string);
+ }
+
+ /**
+ * Prints an empty line to the file.
+ */
+ public void println() {
+ mWriter.println();
+ }
+
+ @Override
+ public void end() throws Visitor.VisitException {
+ mWriter.close();
+ }
+}
diff --git a/s2storage/tools/src/java/com/android/timezone/location/tools/tzs2/CreateTestTzS2File.java b/tzs2storage/tools/src/java/com/android/timezone/location/tools/tzs2/CreateTestTzS2File.java
index f0a319b..f0a319b 100644
--- a/s2storage/tools/src/java/com/android/timezone/location/tools/tzs2/CreateTestTzS2File.java
+++ b/tzs2storage/tools/src/java/com/android/timezone/location/tools/tzs2/CreateTestTzS2File.java
diff --git a/s2storage/tools/src/java/com/android/timezone/location/tools/tzs2/CreateTzS2File.java b/tzs2storage/tools/src/java/com/android/timezone/location/tools/tzs2/CreateTzS2File.java
index 5007e7c..5007e7c 100644
--- a/s2storage/tools/src/java/com/android/timezone/location/tools/tzs2/CreateTzS2File.java
+++ b/tzs2storage/tools/src/java/com/android/timezone/location/tools/tzs2/CreateTzS2File.java
diff --git a/s2storage/tools/src/java/com/android/timezone/location/tools/tzs2/DumpTzS2File.java b/tzs2storage/tools/src/java/com/android/timezone/location/tools/tzs2/DumpTzS2File.java
index 00aff03..ed66ebe 100644
--- a/s2storage/tools/src/java/com/android/timezone/location/tools/tzs2/DumpTzS2File.java
+++ b/tzs2storage/tools/src/java/com/android/timezone/location/tools/tzs2/DumpTzS2File.java
@@ -16,8 +16,8 @@
package com.android.timezone.location.tools.tzs2;
+import com.android.storage.tools.block.DumpBlockFile;
import com.android.timezone.location.storage.tzs2range.read.TzS2RangeFileReader;
-import com.android.timezone.location.tools.block.DumpBlockFile;
import com.android.timezone.location.tools.tzs2.dump.TzS2RangeFileDumper;
import java.io.File;
diff --git a/s2storage/tools/src/java/com/android/timezone/location/tools/tzs2/FileFormats.java b/tzs2storage/tools/src/java/com/android/timezone/location/tools/tzs2/FileFormats.java
index 41a82ae..41a82ae 100644
--- a/s2storage/tools/src/java/com/android/timezone/location/tools/tzs2/FileFormats.java
+++ b/tzs2storage/tools/src/java/com/android/timezone/location/tools/tzs2/FileFormats.java
diff --git a/s2storage/tools/src/java/com/android/timezone/location/tools/tzs2/dump/HeaderBlockDumper.java b/tzs2storage/tools/src/java/com/android/timezone/location/tools/tzs2/dump/HeaderBlockDumper.java
index 240b727..5bf0a04 100644
--- a/s2storage/tools/src/java/com/android/timezone/location/tools/tzs2/dump/HeaderBlockDumper.java
+++ b/tzs2storage/tools/src/java/com/android/timezone/location/tools/tzs2/dump/HeaderBlockDumper.java
@@ -16,10 +16,10 @@
package com.android.timezone.location.tools.tzs2.dump;
+import com.android.storage.tools.block.dump.SingleFileDumper;
import com.android.timezone.location.storage.tzs2range.BankedTzIdSets;
import com.android.timezone.location.storage.tzs2range.TzS2RangeFileFormat;
import com.android.timezone.location.storage.tzs2range.read.HeaderBlock;
-import com.android.timezone.location.tools.block.dump.SingleFileDumper;
import java.io.File;
import java.util.List;
diff --git a/s2storage/tools/src/java/com/android/timezone/location/tools/tzs2/dump/SuffixTableBlockDumper.java b/tzs2storage/tools/src/java/com/android/timezone/location/tools/tzs2/dump/SuffixTableBlockDumper.java
index 96e0587..e46af07 100644
--- a/s2storage/tools/src/java/com/android/timezone/location/tools/tzs2/dump/SuffixTableBlockDumper.java
+++ b/tzs2storage/tools/src/java/com/android/timezone/location/tools/tzs2/dump/SuffixTableBlockDumper.java
@@ -16,12 +16,12 @@
package com.android.timezone.location.tools.tzs2.dump;
-import static com.android.timezone.location.tools.block.dump.DumpUtils.binaryStringLength;
-import static com.android.timezone.location.tools.block.dump.DumpUtils.createPrintWriter;
-import static com.android.timezone.location.tools.block.dump.DumpUtils.generateDumpFile;
-import static com.android.timezone.location.tools.block.dump.DumpUtils.hexStringLength;
-import static com.android.timezone.location.tools.block.dump.DumpUtils.zeroPadBinary;
-import static com.android.timezone.location.tools.block.dump.DumpUtils.zeroPadHex;
+import static com.android.storage.tools.block.dump.DumpUtils.binaryStringLength;
+import static com.android.storage.tools.block.dump.DumpUtils.createPrintWriter;
+import static com.android.storage.tools.block.dump.DumpUtils.generateDumpFile;
+import static com.android.storage.tools.block.dump.DumpUtils.hexStringLength;
+import static com.android.storage.tools.block.dump.DumpUtils.zeroPadBinary;
+import static com.android.storage.tools.block.dump.DumpUtils.zeroPadHex;
import com.android.timezone.location.storage.tzs2range.read.SuffixTableBlock;
diff --git a/s2storage/tools/src/java/com/android/timezone/location/tools/tzs2/dump/TzS2RangeFileDumper.java b/tzs2storage/tools/src/java/com/android/timezone/location/tools/tzs2/dump/TzS2RangeFileDumper.java
index 2c8689c..55a2dad 100644
--- a/s2storage/tools/src/java/com/android/timezone/location/tools/tzs2/dump/TzS2RangeFileDumper.java
+++ b/tzs2storage/tools/src/java/com/android/timezone/location/tools/tzs2/dump/TzS2RangeFileDumper.java
@@ -16,18 +16,18 @@
package com.android.timezone.location.tools.tzs2.dump;
-import static com.android.timezone.location.tools.block.dump.DumpUtils.binaryStringLength;
-import static com.android.timezone.location.tools.block.dump.DumpUtils.hexStringLength;
-import static com.android.timezone.location.tools.block.dump.DumpUtils.zeroPadBinary;
-import static com.android.timezone.location.tools.block.dump.DumpUtils.zeroPadHex;
+import static com.android.storage.tools.block.dump.DumpUtils.binaryStringLength;
+import static com.android.storage.tools.block.dump.DumpUtils.hexStringLength;
+import static com.android.storage.tools.block.dump.DumpUtils.zeroPadBinary;
+import static com.android.storage.tools.block.dump.DumpUtils.zeroPadHex;
+import com.android.storage.tools.block.dump.SingleFileDumper;
+import com.android.storage.util.Visitor;
import com.android.timezone.location.storage.tzs2range.TzS2RangeFileFormat;
import com.android.timezone.location.storage.tzs2range.read.HeaderBlock;
import com.android.timezone.location.storage.tzs2range.read.SuffixTableBlock;
import com.android.timezone.location.storage.tzs2range.read.SuffixTableExtraInfo;
import com.android.timezone.location.storage.tzs2range.read.TzS2RangeFileReader;
-import com.android.timezone.location.storage.util.Visitor;
-import com.android.timezone.location.tools.block.dump.SingleFileDumper;
import java.io.File;
diff --git a/s2storage/tools/src/proto/geotz_protos.proto b/tzs2storage/tools/src/proto/geotz_protos.proto
index f5831c4..f5831c4 100644
--- a/s2storage/tools/src/proto/geotz_protos.proto
+++ b/tzs2storage/tools/src/proto/geotz_protos.proto