I have a string received from server(j2me application ). I want to write this string into a file which i have to dynamically create.
Related
We receive a BASE64 encoded representation of a courier label PDF in an xml file, which we store in the IFS of our AS400.
We would like to decode this BASE64 string and save it as a .PDF in the IFS so we can then either email it as an attachment or send it to a printer.
I have looked at the capability of the CPYSPLF command using the *PDF WSCST parameter, but this only seems relevant where we would have a Spooled File representation of the label we want to produce.
Does anyone know if this is possible via native iSeries commands/RPG?
One way is to
IFS_READ_UTF8 to load the XML file
XMLPARSE to make it a XML object
XML_TABLE to extract BASE64 data
BASE64_DECODE to decode B64 data to PDF binary stream
IFS_WRITE_BINARY to write that stream as a .pdf file
You could make it a pure sql prodecure, or a SQLRPGLE program.
You also could extract BASE64 date using RPGLE XML-INTO. The use Scott Klement's BASE64 SRVPGM to decode it, then write it to the IFS
This question already has answers here:
Excel to CSV with UTF8 encoding [closed]
(36 answers)
Closed 7 years ago.
I'm trying to implement a simple data import to my MVC application from .csv file.
To remove the need for user to save .csv file template in his computer and from going through the trouble of getting it in the first place, I created a button on my form that generates the template.
I generate a string from my model object in a writer class:
this.Writer.GetCswTemplate() returns string from viewModel (i.e. column1;colum2\r\n)
As per How to GetBytes() in C# with UTF8 encoding with BOM?
I force excel to open .csv file with UTF-8 encoding:
var templateResult = Encoding.UTF8.GetBytes(this.Writer.GetCswTemplate());
var preamble = Encoding.UTF8.GetPreamble();
var templateBytes = preamble.Concat(templateResult).ToArray();
to send the generated template to the user I use MVC File() helper:
return this.File(templateBytes, "application/csv", "filename.csv");
It works great, it generates the template, returns it to the user, opens it with Excel and shows all the special characters in it. If I open the generated file in Notepad++ I can see that it's encoding is UTF-8.
The problem occurs when a user fills the generated template and saves it inside Excel. For some reason Excel decides to change file encoding to ANSI.
Is there any way for me to prevent that? Did I miss something (Add some kind of header or something)?
Interestingly if I generate template with UTF-8 (without BOM), modify said file in excel and save it, Excel does not change its encoding to ANSI. The problem then is that Excel does not recognize the special characters inside template.
UTF-8 is an encoding set that can contain any Unicode character. Unfortunately, not all applications can encode files in UTF-8 by default, and Microsoft Excel is one of them.
Instead of Unicode, Excel encodes CSV files using ANSI
One would either need to ask the user to open the file in notepad and save in the correct format (to much work!) or work out some detection/conversion logic.
I have an HTTP endpoint where user uploads file. I need to read the file contents and then store it to DB. I can read it to Buffer and getting string from it.
The problem is, then file content is not UTF-8 I can see "strange" symbols in output string.
Is that possible somehow to detect the encoding of Buffer contents and serialise it to string correctly?
In my j2me application, The RecordStore name is "UserAns", and the entered data is stored in the '0000003-User-Ans.db' file.
I can fetch the data from '0000003-User-Ans.db' file and display it on Emulator.
But when I run the application on device, then it can't display any data.
So, how can I add '0000003-User-Ans.db' file into Application Jar File ?
RecordStore internals is device dependent. The .db file that works on emulator will not work on real devices.
However, you could store your initial data in a different format, say csv, for example, and have an import procedure running at the very first time the application is executed (your RecordStore will be empty then).
Update after comments
Let's say you only have one "table" to initiate: Product. With columns: id, name, price. And that there is a Product Java class with corresponding attributes. A csv sample would be
1, Pen, 1
2, Clip, 0.05
3, Eraser, 0.5
Have this content stored in a file inside the jar, for example, products.csv. Open this file and parse each line to create a Product instance. Convert each instance to a byte array and create a record entry for each of them.
Next time the application is initiated the RecordStore will not be empty and a Product instance can be created for each record found.
I am using jazzlib package in j2me application to compress the xml file in zip format using ZipOutputStream and the send the compress stream to the server as a string . I am able to do unzip the in mobile using ZipInputStream. But in server i am not able to unzip , i got
EOF exception. when i copy the compressed stream from console and put into browser, the empty space put special character like [] in compressed stream. I didnt understand what happened. Plz help
You send the compressed stream as a String? That's your problem(s) right there:
compressed data is binary data (i.e. byte[]).
String is designed to handle textual (Unicode) data and not arbitrary binary data
converting arbitrary binary data to String is bound to lead to problems
So if you want to handle (send/receive/...) binary data, make sure you never use a String/Reader/Writer to handle the data anywhere in the process. Stay with byte[]/InputStream/OutputStream.