Why can android only send binary data to a FTP server? - java

I have an simple understanding question: Why can I only send Binary Data from Android to a FTP server? I am currently learning it and now I understood it. With ByteArrayInputStream I am converting my string into bytes to send it binary. But why binary?

In a digital computer, all data are binary.
Are you talking about a lack of the "ASCII" mode that some FTP clients support? Those have always been problematic in the way they tend to corrupt data. Making an exact copy, without alterations, is a lot safer.

Everything is binary in the computer world.

Related

Convert Image from Little to Big Endian

I am trying to transfer an image saved to a raspberry pi from the rpi to an android application to display it. I am treating the raspberry pi as the server and the android app as the client. My server side is implemented using python. I am using pylab to save a figure to the raspberry pi and then later open the image and read the contents as a byte array. This byte array is then passed to the android app, written in java.
I can view the image on the rpi when I open it, but once it is sent to the android, something is happening to it that causes the incorrect number of bytes to be read and the image to be corrupted. I realized that java reads big endian while the raspberry pi byte order is little endian. I am not sure if this is what is causing the problem in transferring the image?
So, I am wondering if there is a way to either encode the byte array as big endian when it is sent from python or a way to decode the byte array as little endian when it is received by java. I tried simply reversing the image byte array in python but that did not work. Any suggestions would be very helpful!
I am not an expert in hardware differences between a Pi and other platforms, but this process can be performed using ByteBuffer.
You can get an instance of ByteBuffer using ByteBuffer.wrap(byteArray) or ByteBuffer.allocate(capacity).
You can then set the endian-ness of the buffer using buffer.order(ByteOrder.BIG_ENDIAN); or buffer.order(ByteOrder.LITTLE_ENDIAN);
The data can then be returned with buffer.get().

How to compress JSON

I have a webservice sending a huge JSON text to an Android app. There's about 20000 ID numbers. Unfortunately but perhaps not surprisingly it's timing out.
What options do I have? The easiest one that comes to mind is somehow compressing this data. Is there any way I can do this (PHP webservice, Java Android app) effectively?
Failing that, is there some technique to send JSON in parts? If so, how does that work? At what point is JSON considered too big to send in one part? Thank you
You can use GZIP in php and send as stream to client and then decode data with java in android
you can use this for gzip in php: GZIP
and Gzip in Android : GZIP
You could compress data with ob_gzhandler(). Put this call in your script before any output:
ob_start('ob_gzhandler');
After that, output will be compressed with gzip.
This is not a good solution, indeed. You should split JSON and send it as sequential smaller pieces. Otherwise, what will you do when even compressed data is too big?

Decoding binary files stored inside a database after being uploaded from a browser

In migrating from a CMS that stored files in the database, over to a system that stores them in AWS S3, I cant seem to find any options other than reverse engineering the format from Java (the old system) and implementing it all myself from scratch in python, using either the java code or rfc1867 as a reference.
I have database dumps containing long strings of encoded files.
I'm not 100% clear which binary file upload encoding has been used. But there is consistency between the first characters of each file types.
UEsDBBQA is the first 8 characters in a large number of the DOCX file formats, and UEsDBBQABgAIAAAA is the first 16 characters in more than 75% of the DOCX files.
JVBERi0xLj is the first 10 characters of many of the PDF files.
Every web application framework that allows file uploads has to decode these... so its a known problem. But I cannot find a way to decode these strings with either Python (my language of choice), or with some kind of command line decoding tool...
file doesnt recognise them.
hachoir doesnt recognise them.
Are there any simple tools I can just install, I dont care if they are in C, Perl, Python, Ruby, JavaScript or Mabolge, I just want a tool that can take the encoded string as input (file, stdin, I don't care) and output the decoded original files.
Or am I overthinking the algorithm to decode these files and it would be simpler than it looks and someone can show me how to decode them using pure python?
Most commonly used encoding algorithm to represent binary data as text is Base64. I just did a quick test on a PDF file in Java and I got exactly the same header character sequence when Base64-encoding it.
byte[] bytes = Files.readAllBytes(Paths.get("/test/test.pdf"));
String base64 = DatatypeConverter.printBase64Binary(bytes);
System.out.println(base64.substring(0, 10)); // JVBERi0xLj
So, you're most likely looking for a Base64 decoder.
I don't do Python, so here's a Google search suggestion and the first Stack Overflow link which appeared in the search results to date: Python base64 data decode.

Best way to store CMU Sphinx text output

I am currently building a recognition program with cmu sphinx. I would like to take the speech query that is converted to text by sphinx and store it as a data file (I was thinking either .txt file or .php [due to webserver using .php]). after the file is stored on the server, I already have the server taking the file, and giving me back the results I asked for (works perfectly). Just wanted some food for thought on how someone else would go about storing the text generated by sphinx, and what would be the most efficient file type (like I said I think .php would be the best filetype due to webserver, but if someone else has an opinion feel free to share). when the data is received (.xml format) I will have a synthesizer output the data from the webserver. I want the webserver to store past queries, and create a small offline server database. I also want the webserver to have multiple users queries stored.
thank you for your time. Look forward to any answers, or any food for thought. Cheers!

Microphone UDP live audio streaming

I'm trying write a java program to send live microphone data over UDP, then receive the data in VLC. I'm basically using the same code as in this post to package up the stream and send them over. When I receive the data in VLC, I get nothing. I see a bunch of input coming in but none of it is interpreted as audio data. It tries to resolve the information as mpga or mpgv, but I'm pretty sure it's being sent as raw audio. Is the problem on VLC's end? Should I configure VLC to receive a specific format? Or is the problem with my program not packaging the data in a way VLC can interpret it?
First thing you should do is capture the live microphone data to a file and figure out exactly what format it is. Then transfer the file to VLC (if that makes sense) to see if VLC can cope with it in that form.
If you are going to use UDP in the long term, you need to be sure that the audio format you are using can cope with the loss of chunks of data in the middle of the audio stream due to network packet loss. If not, you should use TCP rather than UDP.

Categories

Resources