I have some data files that I use to initialize HashMaps in my Android program, and save the updated HashMaps during the program. These files are currently kept in the assets folder.
The only way to read and write a HashMap (that I am aware of) in regular java program is to use ObjectOutpuStream and ObjectInpuStream, however, it seems that currently these data files can only be accessed as InputStream object using getAssets().open(filepath), and I have no idea how to convert InputStream object to read and write HashMaps, any suggestion on this?
Is there any alternative ways to achieve this? (other than storing the data files in internal or external storage)
Related
So the existing code base where I work uses a regular Java File("a/directory/path") object for a massive amount of logic. Now my team wants me to use a file stored in the Azure Blob instead. I can get the file from the blob using the CloudBlobItem() java api. But this object is different than a regular java File() object. And I would have to change a bunch of stuff in the logic. Is there any blob item which can be casted to a regular File() object?
Short answer: No.
You're comparing two completely different things. Azure blobs are not files. You'd need to stream them down to where your code is running. Maybe to a file stream. Maybe write to disk. And then work with the file. You cannot just use an Azure blob like any other file I/O.
Note: If you're using Azure File Storage (which is an SMB share), then you do treat everything in that file store like you'd treat local storage. But it sounds like you're just using normal block blobs for your storage.
I have a file which I need to upload to a service, and parse into relevant data. The parser and the uploader both require an InputStream. Ought I to open the file twice? I could save the file to a String, but having many of these files in memory is concerning.
EDIT: Thought I should make it clear that the parsing and uploading are entirely separate processes.
Since you are parsing it already it would be most efficient to load the file into a string. Parse it into indexes to the string, you will save memory and can just upload the string whenever you want to. This would be the most effective way, with memory but maybe not processing time.
A reply to one of the comments above.
Separate processes does not mean different threads or processes, just they do not need each other to operate.
I'm making two Java applications one to collect data, another to use it. The one collecting will be importing a file from the other which will include data and images and will be decrypted.
I'm unsure what filetype to use. So far all of the data is in XML and works great but I need the images and was hoping not to have to rely on giving all the images in a folder with a path reference.
Ideas?
well, I think that the best way is to create your own format (.myformat or .data). This file will be in fact a Zip file that contains your XML file and images.
There is no perfect example writen in java as far as I know. However, here are some examples :
Not in java
The best example is, as #Bolo said, the odt format. Indeed, OpenOffice writes the doc in an xml file, and the images too. All that is wrapped in an odt file.
The .exe file is an other example. The C files and the resources are put in a single file. try to open it with 7-zip, you'll see.
The Skyrim plugins are .esp file that contain the dds, the scripts, the niffs (textures)...
In java
The minecraft texture packs are a zip file that contains a .mcmeta file (the infos) and the textures (.png)
Jar files are like exe.
If both programs are in java you could also go with serialization, which is basically saving an object as a file (suffix will be .ser I think) and then being able to retrieve it. You should google it, even if it won't help right now it is quite good to know about it.
I'd suggest using JSON. Gson is a decent library.
You can embed images as byte arrays.
Save the serialized string in a file with a preferred extension, read it from the second application, de-serialize, and reconstruct images.
You can convert binary image data to text with Base64 encoding and this way you can embed your images in XML. [1]: http://en.wikipedia.org/wiki/Base64
I am trying to save some documents/Images and files in sqlite database. The documents contain different types of pdf,.doc etc files and different format images. Now once I stored it in the blob format, I want to do a backup of the database to sdCard. I however want this backup to be readable only by app for securing the data inside.
Now the question is , for storing different types of files, Do I have to use some sort of other database and for securing. what should I do?
Best Regards
Android's built-in SQLite does not support encryption.
Try instead a library like SQLCipher.
One solution is to use blob and to store the raw data of the file as a column in the db as you are currently doing.
Other solution which I think is better to store the files on the Internal Storage and just store the file paths in the database. Internal storage is private for your application so no one will have access to the files, so your security concerns are taken care of.
see here for how to do this:
Creating folder in internal Memory to save files and retrieve them later
But be aware that can using too much internal storage can make people's phones run out of internal storage and they might decide to delete your app.
Basically, I want to be able execute a byte stream as a file, without writing said bytes to a file.
I want to do this in a windows environment.
You could say I want a to create a file, copy the stream to the file, and open the file as an executable, but I want the file to have no physical manifestation on the disk.
Thanks
This is not possible to do using the standard Java API. You will have to rely on some OS specific native implementations, either that do the whole thing for you, or that allow you to create some sort of RAM-disk on which you can place your temporary data and execute it.
Possibly related:
write file in memory with java.nio?
Supposing you bytestream is the one of a standard exe, and you don't want to call a whole virtualisation environnement, the short answer is no because internal adresses in the code wouldn't map.
Here's a more detailled answer :
process.start() embedded exe without extracting to file first c#