B4J Question Add a TXT file inside a Library.

Star-Dust

Expert
Licensed User
Longtime User
I have a library that uses a TXT file. If I insert it in Dirasets when I fill out the library there is no longer inside and it is not reachable.
So I put the text file inside a string variable. Now the file is big, of over 500 lines and it becomes complicated to insert it a string. There is a way to make a text file (the file cannot be external or on the internet must be uploaded inside an UN Library, it must necessarily be inside the library)
 

emexes

Expert
Licensed User
Longtime User
If the text file is an array of Ints or Floats, it'll probably halve in size with an Array As Type inline definition, plus not require parsing. Bonus!
 
Upvote 0

emexes

Expert
Licensed User
Longtime User
You can put in the library Files folder.

I was just about to try that out, so thanks for saving me the effort.

But a similar thought was, if it is a plain language text file that compresses nicely, to Gzip and Base64 it and store it as a string. Plus it'd probably compress up another 20% by the B4XLIB Zipping.
 
Upvote 0

emexes

Expert
Licensed User
Longtime User
not needed

Gzip and Base64 was a way of embedding more than 64k inline into code, or of reducing the size of embedded files if they are expanded into normal files.

But if the OP is reading directly from a compressed file within a JAR or similar, then that is much simpler, for both the OP and presumably anybody else who's interested in the file.
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
If I'm not mistaken for Android, I inserted the file in the jar with a program like Winzip and to call it back to Java I used this command

Java:
Inputstream IS = This.Getclass (). GetresourceioSSTREAM (Filename);
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
More information - are you writing the library in Java?
The library is written in B4J, but needs to load an internal text file that is codified.
It is not possible to use B4X because otherwise it is possible to see how to decode it in an easy way.
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Can you show us a half-dozen lines?
Now the content is not important, how much to be able to incorporate a file into the jar. In principle it could be a file of any kind
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

emexes

Expert
Licensed User
Longtime User
the content is not important

It is relevant to how you might represent it in code, eg if it was like:

LargeCities.csv:
"City","Country","Population","Latitude","Longitude"
"Tokyo","Japan","37000000",35.6762,139.6503
"Delhi","India","32000000",28.6139,77.2090
"Shanghai","China","24870000",31.2304,121.4737
"São Paulo","Brazil","12330000",23.5505,-46.6333
"Mexico City","Mexico","9200000",19.4326,-99.1332
"Cairo","Egypt","9500000",30.0444,31.2357
"New York City","United States","8400000",40.7128,-74.0060
"Moscow","Russia","12500000",55.7558,37.6173
"Lagos","Nigeria","14800000",6.5244,3.3792
"London","United Kingdom","8900000",51.5074,-0.1278

then I'm thinking that could be translated to code with inline data quite simply, and in a manner that doesn't subsequently require parsing too.
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
It is relevant to how you might represent it in code, eg if it was like:

LargeCities.csv:
"City","Country","Population","Latitude","Longitude"
"Tokyo","Japan","37000000",35.6762,139.6503
"Delhi","India","32000000",28.6139,77.2090
"Shanghai","China","24870000",31.2304,121.4737
"São Paulo","Brazil","12330000",23.5505,-46.6333
"Mexico City","Mexico","9200000",19.4326,-99.1332
"Cairo","Egypt","9500000",30.0444,31.2357
"New York City","United States","8400000",40.7128,-74.0060
"Moscow","Russia","12500000",55.7558,37.6173
"Lagos","Nigeria","14800000",6.5244,3.3792
"London","United Kingdom","8900000",51.5074,-0.1278

then I'm thinking that could be translated to code with inline data quite simply, and in a manner that doesn't subsequently require parsing too.
It is not a text that can be translated into command lines.
 
Upvote 0

emexes

Expert
Licensed User
Longtime User
It is not a text that can be translated into command lines.
Ye of little faith!!!

But ok, if it is so secret that you can't post a sample of what it looks like, then fair enough. There are other good solutions in this thread. I'm interested to know which path you chose.

You could obfuscate the file by Gzipping it to a Byte Array and then adding 123 to every say 42nd byte. Then in your program at the other end, get those bytes from wherever you've stored them within your program, back into a Byte Array, subtract 123 from every 42nd byte, unGzip it, and you've got your original text back.

I imagine your text file would Gzip down to less than half its size, unless it's truly random.

I'm pretty sure that bytes stored in your program as:

Dim GzippedFile() As Byte = Array As Byte(55,23,64,193,22,87,43 ... )

will compile down to that size in bytes with just one small bit of Array overhead. Although it'd be spread across many (hundreds?) of lines, and it's possible that the B4X transpiler might choke on the virtual line length, even if everything else easily fits into the Java 64kB limits.
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Of course, it's a good solution. But what I was looking for is not to insert in the code to avoid passing the data manually since it is not a small file.

I will try the method that Erel suggested to me and then I'll let you know
 
Upvote 0
Top