outputstream

Usage of FilterOutputStream

混江龙づ霸主 提交于 2019-12-06 08:53:14
问题 What is practical usage of FilterOutputStream in Java? From javadocs: This class is the superclass of all classes that filter output streams. These streams sit on top of an already existing output stream (the underlying output stream) which it uses as its basic sink of data, but possibly transforming the data along the way or providing additional functionality. For me it seems to have same methods as OutputStream (maybe it overrides them for some reason?). What kind of data "transformation"

StreamCorruptedException when sending Serialized objects via Bluetooth

我是研究僧i 提交于 2019-12-06 06:48:16
问题 I have a Serialized class that I need to send as an object via Bluetooth, and also implements Runnable. As such, I set a few variables first, then send it as an object to be executed by another Android device, which will then set its result into a variable, and send back the same object with the result in one of the variables. I have been using the following two methods to serialize my object and get a ByteArray before sending them through the OutputStream of my BluetoothSocket, and to

Is an OutputStream in Java blocking? (Sockets)

不问归期 提交于 2019-12-05 18:15:32
问题 I am currently writing naive network code for a project and a mate hinted me at the possibility that when I send a package of information from the server to all clients in an iterative fashion I might get intense lag when one of the clients is not responding properly. He is reknown for trolling so I was kind of sceptical when implementing a secondary thread that is now responsible to send data over to a client, having a queue that the Server simply adds the packages over that is then read by

Send a zero-data TCP/IP packet using Java

我只是一个虾纸丫 提交于 2019-12-05 18:01:38
My goal is to send a TCP packet with empty data field, in order to test the socket with the remote machine. I am using the OutputStream class's method of write(byte[] b). my attempt: outClient = ClientSocket.getOutputStream(); outClient.write(("").getBytes()); Doing so, the packet never show up on the wire. It works fine if "" is replaced by " " or any non-zero string. I tried jpcap, which worked with me, but didn't serve my goal. I thought of extending the OutputStream class, and implementing my own OutputStream.write method. But this is beyond my knowledge. Please give me advice if someone

Play/Akka integration with Java OutputStreams

喜欢而已 提交于 2019-12-05 17:17:40
I'm writing a Play! application which exposes a REST API allowing users to generate PDF reports. I'm constrained by the requirements to use a old Java API to do the actual report generation. That library has a method generate(OutputStream out, ...) , i.e. it takes a java.io.OutputStream where it writes the resulting report. My problem is integrating this with Play/Akka to serve the contents in Chunked Encoding. To that end, I need to create an Enumerator[Array[Byte]] which somehow contains the OutputStream from the Java library. I have come up with a working solution that uses a

Why should OutputStream be closed after inputstream in android

时光总嘲笑我的痴心妄想 提交于 2019-12-05 17:01:36
I am doing two succssive calls to my servlet from android in this way: //FIRST CONNECTION URL url = new URL("http://172.16.32.160:8080/xyz/check_availability"); HttpURLConnection connection =(HttpURLConnection) url.openConnection(); connection.setDoOutput(true); ObjectOutputStream out=new ObjectOutputStream(connection.getOutputStream()); String a="xya"; String b="xsw"; out.writeObject(a); out.flush(); ObjectInputStream in=new ObjectInputStream(connection.getInputStream()); String s=(String) in.readObject(); in.close(); out.close(); Toast.makeText(getApplicationContext(), "1", Toast.LENGTH_LONG

Does closing the socket close the stream?

元气小坏坏 提交于 2019-12-05 13:49:06
I am working in a legacy java application, In many files, socket and streams are used, where sockets are getting closed but not the streams, is this necessary to close all the streams before closing the socket. because I am getting "too many open files error", is this error because of not closing the streams..... closing the socket will automatically close the streams also? From the Socket Javadoc : Closing this socket will also close the socket's InputStream and OutputStream . So generally speaking, closing the socket should be enough to close both streams it created. Your "too many open

How should an InputStream and an OutputStream be closed?

空扰寡人 提交于 2019-12-05 10:36:48
I'm using the following code to close an InputStream and an OutputStream from a connection to a server: try { if (mInputStream != null) { mInputStream.close(); mInputStream = null; } if (mOutputStream != null) { mOutputStream.close(); mOutputStream = null; } } catch (IOException e) { e.printStackTrace(); } However, the streams are not closing, they are still alive. If I connect again there are two different InputStreams. No exception is being caught in the catch section. What am I doing wrong? Two problems with your posted code: The .close() calls should be handled in a finally block. This way

PHP: close output stream

为君一笑 提交于 2019-12-05 07:57:59
Is it possible to close the output stream of a PHP script? I have a script which needs to do some post processing, but during and after the post processing it won't send any data to the client anymore, so I'd like to close the connection before the post processing. Edit: In my application I have a cache which needs to be rebuild every now and then. However, I don't want to slow a user down. What I want is to determine at the end of the script if the cache needs to be rebuild. So I want to close the output stream first, so the user gets it's data, and then I want to rebuild the cache. It isn't

Android POST request using HttpURLConnection

喜欢而已 提交于 2019-12-05 03:16:12
问题 I'm trying to execute post request using HttpURLConnection but don't know how to do it correctly. I can successfully execute request with AndroidAsyncHttp client using following code: AsyncHttpClient httpClient = new AsyncHttpClient(); httpClient.addHeader("Content-type", "application/json"); httpClient.setUserAgent("GYUserAgentAndroid"); String jsonParamsString = "{\"key\":\"value\"}"; RequestParams requestParams = new RequestParams("request", jsonParamsString); httpClient.post("<server url>