Answer my own question.

private static boolean isH2DbFile(final File file) {
if (!file.exists() || (file.length() < 1024)) {
return false;
}
try (final RandomAccessFile in = new RandomAccessFile(file, "r")) {
final byte[] headerBytes = new byte[20];
in.read(headerBytes);
final String header = new String(headerBytes);
if ((header.indexOf("H:2,blockSize:") == 0) // v1.4.x, no encryption
|| (header.indexOf("-- H2 0.5/B --") == 0) // v1.3.x
|| (header.indexOf("H2encryp") == 0) // v1.4.x, encrypted.
) {
in.close();
return true;
}
} catch (final Exception e) {
e.printStackTrace();
}
return false;
}


在 2016年11月8日星期二 UTC+8下午2:49:52,Trig Chen写道:
>
> Hi all,
>
> I used FilePathWrapper to remap H2 database file *.h2.db to *.xxx. 
> So come to the problem: Is there any API in H2  packages to determine 
> whether a file is H2 database?
>
> Best regards, 
> Trig Chen
>
>

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.

Reply via email to