简体   繁体   中英

how to make a searchable String ID with a byte[] using java and hibernate

i am working on a RFID project, in which i should identify vehicles with their RFID tag. the RFID Tags contain 14 bytes of data. my first clue was to convert each byte of the array to string something like this :

public String convertByteToString(byte[] tag)
{
    String stringRfid ="";
    for(int i=0; i<14; i++)
      stringRfid = stringRfid + tag[i];
    return stringRfid;
}

i don't know if this is a humble solution or what. some say and i quote it "storing raw byte[] in BLOB - the safest and most storage-effective way." would you please give me tip what is the fastest and easiest and also efficient way to do this?

I would transform the byte array to a base64-encoded readable string, and store this string in the database. It would only increase the size with a 4/3 ratio (so around 20 bytes instead of 14), and would store readable, indexable and printable ascii strings in the database.

Guava and apache commons-codec both have a free base64 encoder/decoder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM