Java convert JFIF file to JPG file - java

Is there a way to convert a .JFIF file to a .jpeg file without using any online tools? I want to do this in java. The problem is that I receive files as a JFIF file. I want to create a base64 string from that, but using that string will not display any images.

Related

How to detect an HTML file that had extension changed to Excel .xls

I have a java app that processes excel files from emails in an automated fashion (.xls, xlsx etc). I've noticed that some files are not native files. Opening in Excel will give a warning that the file is corrupt/badly formated. Opening in notepad++ clearly shows HTML
Unfortunately I can't just manually handle these files so I need a way to automatically spot them.
I noticed that when I use java.io.fiile object then with org.apache.tika.Tika I can detect the the type. So with the file object I can find out the extension, and with tika.detect() i can find that the format is called "text/html". (Not sure if this is the best way, but it seems to work with my singular example)
So I can then find these kinds of files using:
File file = getTheFileObject();
if ( tika.detect(file).equalsIgnoreCase("text/html") && file.getName().contains(".xls") ) { ... do what I want with the corrupt file... }
My problem comes when doing something similar with email attachments. To get the file from emails I'm using the com.microsoft.ews-java-api 2.0 and from this I can get a FileAttachment object which represents the file.
But when I attempt to use tika.detect() on this (same corrupt file) i get a different format output "application/octet-stream" instead of "text/html". Or get "application/vnd.ms-excel" using the FileAttachments own methods
How can I spot these corrupt files if I can't spot the html formated xls files?
FileAttachment attachment = getFileAttachment();
attachment.getContentType() //application/vnd.ms-excel
tika.detect(attachment.getContentStream()) //application/octet-stream
How would I spot an html file that has .xls file extension from the emails ews FileAttachment object? Will tika still help?

Parsing mp4 to raw audio file without download in JAVA

I need to parse mp4 file (which I get from URL), to raw audio file (FLAC) using JAVA, and I want to do that without actually download the file to my server.
I checked sannies/mp4parser library but the file need to be downloaded.
Is there any way to parse the mp4 to flac without download it?
Thanks

Two applications need to export and import a single file which needs to include data and images, best file type?

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

Is there a way to convert tiff image to Base64 without loading complete file into memory

I've a very large image file in TIFF format (upto 100MB), I need to convert this image into Base64 and then write to XML file. I am wondering if there is a way to stream read image file, convert it into Base64 and write to XML using Java IO streams without loading full file into memory all at one time.
Can't you just read small segments of the image file with a stream, convert to base 64, and output to xml? Converting to base64 shouldn't require reading the entire file.
Edit:
Standard Java API does not include a Base64 encoder.
Try Apache Commons Base64InputStream.

Java binary file (.raw) output

How can I write .raw files in Java? I have to use this output file as a source file for ParaView.
Unlike other binary file formats, RAW is camera specific: Each digital camera uses its own file format. See https://en.wikipedia.org/wiki/Raw_image_format
To read/write images in this format, you can use Jrawio

Categories

Resources