file - How to avoid individual casting to byte during initialization of byte array in Java -


i using byte array store text file outside of filesystem.

it looks this:

private static final byte[] cdrives = new byte[] {         (byte)0xe0, 0x4f, (byte)0xd0, 0x20, (byte)0xea, 0x3a, 0x69, 0x10,         (byte)0xa2, (byte)0xd8, 0x08, 0x00, 0x2b, 0x30, 0x30, (byte)0x9d,         (byte)0xba, (byte)0x8a, 0x0d, 0x45, 0x25, (byte)0xad, (byte)0xd0, 0x11,         (byte)0x98, (byte)0xa8, 0x08, 0x00, 0x36, 0x1b, 0x11, 0x03,         (byte)0x80, 0x53, 0x1c, (byte)0x87, (byte)0xa0, 0x42, 0x69, 0x10,         (byte)0xa2, (byte)0xea, 0x08, 0x00, 0x2b, 0x30, 0x30, (byte)0x9d         ...         ...         ...         }; 

is there way avoid casting (byte) better visual interpretation?

i don't mind using other data type, need able build inputstream out of , fastest way if possible. (for example storing text file string variable not best way...)

well 1 simple approach use base64 - perform conversion on class initialization, take performance hit once:

private static final byte[] cdrives = base64.decode("yourbase64here"); 

or if it's genuinely text, perform encoding once in similar way:

private static final byte[] cdrives =     "your constant text here".getbytes(standardcharsets.utf_8); 

again, performance hit occurs once, , can use bytes multiple times. surprised if cost of encoding text bytes @ class initialization time genuinely bottleneck you.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -