Looping Error on Android Emulator

Android is trying to listen on the microphone, which isn’t available on the emulator, so it fills logcat with useless stack traces. To stop this, go to the Settings app in Android, and click: Apps and notifications App permissions Microphone Then disallow microphone use for all the apps.

Wrapping a ByteBuffer with an InputStream

There seem to be some bugs with the implementation referred to by Thilo, and also copy and pasted on other sites verbatim: ByteBufferBackedInputStream.read() returns a sign extended int representation of the byte it reads, which is wrong (value should be in range [-1..255]) ByteBufferBackedInputStream.read(byte[], int, int) does not return -1 when there are no bytes … Read more

What’s the fastest way to read from System.in in Java?

Is there any faster way of doing this in Java? Yes. Scanner is fairly slow (at least according to my experience). If you don’t need to validate the input, I suggest you just wrap the stream in a BufferedInputStream and use something like String.split / Integer.parseInt. A small comparison: Reading 17 megabytes (4233600 numbers) using … Read more

Android AudioTrack playing .wav file, getting only white noise

from your code i can see that you just read data from the wav file and just import them to the AudioTrack. Wav files have a small header as you can see here https://ccrma.stanford.edu/courses/422/projects/WaveFormat/ So you have to skip the header and point your file descriptor at the right place where the actual audio data … Read more

java.io.IOException: unexpected end of stream on Connection in android

I had the same problem using OKHttp3. The problem was that I didn’t close the connection for each request and for the client the same connection was available and for the server not, for this reason the server returns a error. The solution is indicating to each request to close the connection when it is … Read more

Convert InputStream to JSONObject

Since you’re already using Google’s Json-Simple library, you can parse the json from an InputStream like this: InputStream inputStream = … //Read from a file, or a HttpRequest, or whatever. JSONParser jsonParser = new JSONParser(); JSONObject jsonObject = (JSONObject)jsonParser.parse( new InputStreamReader(inputStream, “UTF-8”));

Determine the size of an InputStream

This is a REALLY old thread, but it was still the first thing to pop up when I googled the issue. So I just wanted to add this: InputStream inputStream = conn.getInputStream(); int length = inputStream.available(); Worked for me. And MUCH simpler than the other answers here. Warning This solution does not provide reliable results … Read more

Unable to read InputStream from Java Process (Runtime.getRuntime().exec() or ProcessBuilder)

I realize this is question is old, but I just experienced the same problem. In order to fix this I used this code.. List<String> commandAndParameters = …; File dir = …; // CWD for process ProcessBuilder builder = new ProcessBuilder(); builder.redirectErrorStream(true); // This is the important part builder.command(commandAndParameters); builder.directory(dir); Process process = builder.start(); InputStream is … Read more