inputstream

Unexpected status line: ICY 200 OK for URL openStream() method?

白昼怎懂夜的黑 提交于 2019-12-21 12:29:40
问题 According to changes for kitakt 4.4 there were some problems with playing shoutcast streams (those returning "ICY" instead of "HTTP/1.x" response). So solution for kitkat was to reregister "icy" protocol prefix in JVM once before we opened a stream by this: try { java.net.URL.setURLStreamHandlerFactory( new java.net.URLStreamHandlerFactory(){ public java.net.URLStreamHandler createURLStreamHandler( String protocol ) { Log.d( LOG, "Asking for stream handler for protocol: '" + protocol + "'" );

Java - Read line using InputStream [duplicate]

家住魔仙堡 提交于 2019-12-21 07:29:23
问题 This question already has answers here : How to read a large text file line by line using Java? (21 answers) Closed 4 months ago . I use InputStream to read some data, so I want to read characters until new line or '\n'. 回答1: You should use BufferedReader with FileInputStreamReader if your read from a file BufferedReader reader = new BufferedReader(new FileInputStreamReader(pathToFile)); or with InputStreamReader if you read from any other InputStream BufferedReader reader = new

How to get the underlying String from a JsonParser (Jackson Json)

时光毁灭记忆、已成空白 提交于 2019-12-21 06:59:25
问题 Looking through the documentation and source code I don't see a clear way to do this. Curious if I'm missing something. Say I receive an InputStream from a server response. I create a JsonParser from this InputStream. It is expected that the server response is text containing valid JSON, such as: {"iamValidJson":"yay"} However, if the response ends up being invalid JSON or not JSON at all such as: Some text that is not JSON the JsonParser will eventually throw an exception. In this case, I

Is there an explanation for the behavior of this Java ByteBuffer?

青春壹個敷衍的年華 提交于 2019-12-21 05:22:39
问题 I need to convert numerical values into byte arrays. For example, to convert a long to a byte array, I have this method: public static byte[] longToBytes(long l) { ByteBuffer buff = ByteBuffer.allocate(8); buff.order(ByteOrder.BIG_ENDIAN); buff.putLong(l); return buff.array(); } It's pretty straightforward - take a long, allocate an array that can hold it, and throw it in there. Regardless of what the value of l is, I will get an 8 byte array back that I can then process and use as intended.

How do I peek at the first two bytes in an InputStream?

我与影子孤独终老i 提交于 2019-12-21 03:10:37
问题 Should be pretty simple: I have an InputStream where I want to peek at (not read) the first two bytes, i.e. I want the "current position" of the InputStream to stil be at 0 after my peeking. What is the best and safest way to do this? Answer - As I had suspected, the solution was to wrap it in a BufferedInputStream which offers markability. Thanks Rasmus. 回答1: For a general InputStream, I would wrap it in a BufferedInputStream and do something like this: BufferedInputStream bis = new

Connecting a Laser Distance Measurer (Bosch Disto GLM 50 C) with Smartphone (Android Studio)

孤人 提交于 2019-12-20 20:17:43
问题 I got stuck at a special problem (I think). For a study project I have to make an Android application that can connect to a Laser Distance Measurer (Bosch GLM 50 C Distometer). So far I went through countless tutorials and hints here at Stackoverflow and other sources. I'm new to Android and am sligthly overwhelmed. The task is to create an app, that reads the measured distance on the Bosch device and display/save it on the smartphone via Bluetooth. Now my concrete question is: Is it possible

Connecting a Laser Distance Measurer (Bosch Disto GLM 50 C) with Smartphone (Android Studio)

佐手、 提交于 2019-12-20 20:17:33
问题 I got stuck at a special problem (I think). For a study project I have to make an Android application that can connect to a Laser Distance Measurer (Bosch GLM 50 C Distometer). So far I went through countless tutorials and hints here at Stackoverflow and other sources. I'm new to Android and am sligthly overwhelmed. The task is to create an app, that reads the measured distance on the Bosch device and display/save it on the smartphone via Bluetooth. Now my concrete question is: Is it possible

java convert inputStream to base64 string

╄→гoц情女王★ 提交于 2019-12-20 18:28:05
问题 There is a way to convert inputStream to a String, and encode it to base64, right? In my function, I get InputStream param, and need to insert it into the BLOB field in my Oracle database table. Is there a way to do that? (my database object contains string field to save the image, but I don't find any way to convert the inputStream to string in base64 format) Thank you! 回答1: You can try something like this using the Base64 API. InputStream finput = new FileInputStream(file); byte[]

How to use NIO to write InputStream to File?

ε祈祈猫儿з 提交于 2019-12-20 17:40:27
问题 I am using following way to write InputStream to File : private void writeToFile(InputStream stream) throws IOException { String filePath = "C:\\Test.jpg"; FileChannel outChannel = new FileOutputStream(filePath).getChannel(); ReadableByteChannel inChannel = Channels.newChannel(stream); ByteBuffer buffer = ByteBuffer.allocate(1024); while(true) { if(inChannel.read(buffer) == -1) { break; } buffer.flip(); outChannel.write(buffer); buffer.clear(); } inChannel.close(); outChannel.close(); } I was

Fast way to compare inputstreams

喜欢而已 提交于 2019-12-20 11:19:11
问题 I have a problem, I need to compare two inputstreams fast. Today I have a function like this: private boolean isEqual(InputStream i1, InputStream i2) throws IOException { try { // do the compare while (true) { int fr = i1.read(); int tr = i2.read(); if (fr != tr) return false; if (fr == -1) return true; } } finally { if (i1 != null) i1.close(); if (i2 != null) i2.close(); } } But it's really slow. I want to use buffered reads but have not come up with a good way of doing it. Some extra stuff