I have to upload a file attachment and send it via an HTTP GET request to a server location. I am using IBM websphere integration designer to implement this functionality.
I have the attachment as a byte array and it has to be converted to an Excel .csv file.
Please help me understand how to write a .csv file using a byte array.
If you have a byte array. Let's say.
byte[] byteArray = ThisIsWhereMyByteArrayIsComingFrom.getArray();
String convertedString = new String(byteArray);
That gets the string value of whatever your byte array is. Then you can either, use a csv library to output whatever it is to a file.
Related
I'm trying to get a .png file to render in a WebView after getting the file through an apache HttpClient get request. I'm actually reading the HttpResponse contents into a simple byte array -> (evaluating the contents into a String when debugging).
It appears if I convert those bytes into a string to compare with the actual file, they look different. Is there a specific way to retrieve .png file
using the apache HttpClient?
example compare, my test is on the left and actual file on right
I am getting a base64 PDF input as part of a request from my client, I need to convert this file into to File Input Stream to use with the PDF BOX library. I am trying to achieve this without writing the file onto drive and directly reading the base64 pdf into File Input Stream.
What I am able to do:
Convert base64 encoded pdf to File and write on the drive
Read the file into a File Input Stream
What I want to do:
Convert base64 encoded PDF to File input stream to use it with PDFBOX.
I am trying to avoid writing the file onto the disk.
In pdfbox you can load a pdf from an InputStream. it does not need to be FileInputStream.
Using the following code you can get an inputStream of the decoded pdf.
Note: depending on the scheme used to encode pdf you may need to use: .getMimeDecoder() instead of .getDecoder().
InputStream decoded = java.util.Base64.getDecoder().wrap(inputStream);
PDDocument.load(decoded);
I'm trying to create an Android app able to upload and download PDF files to a server, I've already included in my code a method able to download a PDF from an URL such as "http://www.aaaa.com/myfile.pdf" and display it by using intent.
But I want to know if there is a way to encode a Pdf into a byte array and viceversa decode a byte array to PDF file (I'm using mongoDB)
Thanks to everyone :)
import java.nio.file.*;
Path pdfFilePath = Paths.get("/file/path/your_file.pdf");
// Read file to byte array
byte[] pdfByteArray = Files.readAllBytes(pdfFilePath );
// Write byte array to file
Files.write(pdfFilePath , pdfByteArray);
i created a mule flow which accepts a file as inputstream and convert into byte array and attach that file to the particular SalesForce case.
Can it possible that i could convert the file(coming as inputstream) to the pdf format and attach to Salesforce case.
PDF is a special format so directly it will not create PDF. You can use libraries like Apache FOP or iText to create PDF output.
So I read a file into a byte array and then I break it up into chunks and send it across the network with UDP.
Path path = Paths.get("files_upload/music.mp3");
byte[] objectBytes = Files.readAllBytes(path);
On the server I read all the chunks into a buffer and I end up with the same byte[] objectBytes as I had on the client. Now I want to write the file to disk using the original file name which is music.mp3 in this case. So how can I get the file name from the array of bytes?
The array of bytes doesn't contain the file name. You'd have to send it separately. You can call getFileName on your path, and then turn that into a byte array using getBytes() on the resulting string.
String fileName = path.getFileName();
byte[] fileNameBytes = fileName.getBytes();
You can then send this first and read it on the other end. Note, this wont contain the whole path, only the name of the file (music.mp3 in your case).
By the way, are you sure you want to be using UDP? What if you lose a packet or two when the data is being transferred? How do you detect that on the server?