0

I'm saving captured fingerprint image into my SQLite db as a byte array cos it really small size wise like this.

byte[] template = new byte[....];

Then i log and get a value like [B@41d25378. That's what's sent it my sqlite db in a blob column.

The problem now is that when i retrieve this value from my db,

byte[] photo = cursor.getBlob(cursor.getColumnIndex("fingerprint"));

i log the value and its totally different [B@420447f8 but this is what i want [B@41d25378. As such, i'm unable to match finger print as what is being returned is different. How can i get the same byte[] value back.

I've tried using strings too but can figure out a way to get an exact match back. Thanks in Advance...

Mueyiwa Moses Ikomi
  • 1,069
  • 2
  • 12
  • 26

2 Answers2

0

The strings [B@420447f8 and [B@41d25378 are values returned by the toString() methods called on Java byte[] objects, which use the Object.toString() (and subsequently Object.hashCode()) without overriding it. They don't represent the value of elements of the arrays in any kind!

In light of this, they are different because they are not the same instance, as the toString() uses hashCode() for the suffix of the returned string.

Also, a note: IT HAS NOTHING TO DO WITH MEMORY ADDRESSES! In Java, the term "memory address" is not applicable. (apart from JVM implementation details, like allocation and GC, etc.).

You are also wrong with this:

Then i log and get a value like [B@41d25378. That's what's sent it my sqlite db in a blob column.

No, that is still just the toString() output, and not the byte array content. No matter what, a meaningful fingerprint needs to be longer than 11 bytes...

You should probably compare the two arrays (Arrays.compare(arr1,arr2)), or log a part of them, like the first few byte values, and their length to make sure they are the same.

ppeterka
  • 20,583
  • 6
  • 63
  • 78
  • This how i match the arrays, if(FPMatch.getInstance().MatchTemplate(model, GlobalData.getInstance().userList.get(i).bytes1)>60){ .. do stuff } . When i save to say shared preference, i get the samething time back and my match is 100% for sure. But when i return from the db, my math is 0 as i seams the structure's changed. Is there an alternative to using blob. That might just be the problem – Mueyiwa Moses Ikomi Oct 30 '16 at 21:14
  • It might be an issue on how you _store_ the blob. If you add your code where you store and reclaim the content, at least that problem could be ruled out... If you log the length of the array, what do you get? For the FP matching: that code seems to be OK, though I'm not an expert in this field. – ppeterka Oct 30 '16 at 21:19
  • i just tried converting to b64 and back, not getting the same value out – Mueyiwa Moses Ikomi Oct 30 '16 at 21:31
  • You mean the `B[@......` as values? – ppeterka Oct 30 '16 at 21:39
  • Yeah... still different... think it's an sqlite thing – Mueyiwa Moses Ikomi Oct 30 '16 at 22:16
-1

Probably You log just addresses of byte[], so its should be different for different objects. It's normal. For your task (save/load image to/from SQLite) try to use this code.

Community
  • 1
  • 1
Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79