MCPcopy Create free account
hub / github.com/M66B/FairEmail / readVersion

Method readVersion

app/src/main/java/androidx/room/DBUtil.java:158–176  ·  view source on GitHub ↗

Reads the user version number out of the database header from the given file. @param databaseFile the database file. @return the database version @throws IOException if something goes wrong reading the file, such as bad database header or missing permissions. @see <a href="https://www.sqlite.org/f

(@NonNull File databaseFile)

Source from the content-addressed store, hash-verified

156 * Number</a>.
157 */
158 public static int readVersion(@NonNull File databaseFile) throws IOException {
159 FileChannel input = null;
160 try {
161 ByteBuffer buffer = ByteBuffer.allocate(4);
162 input = new FileInputStream(databaseFile).getChannel();
163 input.tryLock(60, 4, true);
164 input.position(60);
165 int read = input.read(buffer);
166 if (read != 4) {
167 throw new IOException("Bad database header, unable to read 4 bytes at offset 60");
168 }
169 buffer.rewind();
170 return buffer.getInt(); // ByteBuffer is big-endian by default
171 } finally {
172 if (input != null) {
173 input.close();
174 }
175 }
176 }
177
178 /**
179 * CancellationSignal is only available from API 16 on. This function will create a new

Callers 2

verifyDatabaseFileMethod · 0.95

Calls 5

allocateMethod · 0.80
getChannelMethod · 0.45
readMethod · 0.45
getIntMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected