outputstream

What is InputStream & Output Stream? Why and when do we use them?

心已入冬 提交于 2019-11-27 05:44:26
Someone explain to me what InputStream and OutputStream are? I am confused about the use cases for both InputStream and OutputStream . If you could also include a snippet of code to go along with your explanation, that would be great. Thanks! Chip Uni The goal of InputStream and OutputStream is to abstract different ways to input and output: whether the stream is a file, a web page, or the screen shouldn't matter. All that matters is that you receive information from the stream (or send information into that stream.) InputStream is used for many things that you read from. OutputStream is used

How to check whether an OutputStream is closed

大憨熊 提交于 2019-11-27 03:44:19
问题 Is there anyway to check whether an OutputStream is closed without attempting to write to it and catching the IOException ? For example, consider the following contrived method: public boolean isStreamClosed(OutputStream out){ if( /* stream isn't closed */){ return true; }else{ return false; } } What could you replace /* stream isn't closed */ with? 回答1: The underlying stream may not know it its closed until you attempt to write to it (e.g. if the other end of a socket closes it) The simplest

How do I write to a .txt file in Android?

梦想与她 提交于 2019-11-27 03:21:48
问题 I have an app that needs to read and write to a text file. I have it reading, but I don't have it writing. The idea is that when I click the save button on the screen, its going to save all the info that has been put into the textviews into an array and the write each segment of the array into the text file. This is my code for the writing portion: public class AddOrModify extends Activity { private Button Savebtn; private Button Cancelbtn; private EditText NameofRoute; private EditText

How to use HttpsURLConnection through proxy by setProperty?

情到浓时终转凉″ 提交于 2019-11-27 03:16:29
问题 Network environment: Https Client<=============>Proxy Server<==============>Https Server 192.168.17.11<-----extranet------>192.168.17.22 10.100.21.10<----intranet----->10.100.21.11 ps: Http Client without default gateway, but it can ping to 10.100.21.11 Description: OS: Ubuntu 12.04 on 3 hosts Https Client: Implement with java(openjdk-6).Have one network-interface. Proxy Server: Apache2.2.Have two network-interfaces. Https Server: Tomcat6.Have one network-interface. I use two method to

Java - System.out effect on performance

放肆的年华 提交于 2019-11-27 02:21:36
问题 I've seen this question and it's somewhat similar. I would like to know if it really is a big factor that would affect the performance of my application. Here's my scenario. I have this Java webapp that can upload thousands of data from a Spreadsheet which is being read per row from top to bottom. I'm using System.out.println() to show on the server's side on what line the application is currently reading. - I'm aware of creating a log file. In fact, I'm creating a log file and at the same

How do I write to an OutputStream using DefaultHttpClient?

≡放荡痞女 提交于 2019-11-27 01:55:57
问题 How do I get an OutputStream using org.apache.http.impl.client.DefaultHttpClient ? I'm looking to write a long string to an output stream. Using HttpURLConnection you would implement it like so: HttpURLConnection connection = (HttpURLConnection)url.openConnection(); OutputStream out = connection.getOutputStream(); Writer wout = new OutputStreamWriter(out); writeXml(wout); Is there a method using DefaultHttpClient similar to what I have above? How would I write to an OutputStream using

Is there a Null OutputStream in Java?

若如初见. 提交于 2019-11-27 01:43:19
问题 I need to specify an OutputStream for an API I'm using, but I don't actually have a need for the output. Does Java have an OutputStream equivalent to > /dev/null ? 回答1: Java doesn't it would seem but Apache Commons IO does. Take a look at the following: https://commons.apache.org/proper/commons-io/javadocs/api-2.5/org/apache/commons/io/output/NullOutputStream.html Hope that helps. 回答2: /**Writes to nowhere*/ public class NullOutputStream extends OutputStream { @Override public void write(int

How to write data to two java.io.OutputStream objects at once?

守給你的承諾、 提交于 2019-11-26 22:49:13
I'm looking for magical Java class that will allow me to do something like this: ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); FileOutputStream fileStream = new FileOutputStream(new File("/tmp/somefile")); MultiOutputStream outStream = new MultiOutputStream(byteStream, fileStream); outStream.write("Hello world".getBytes()); Basically, I want tee for OutputStream s in Java. Any ideas? Thanks! Dave Newton Try the Apache Commons TeeOutputStream . Just roll your own. There isn't any magic at all. Using Apache's TeeOutputStream you would basically use the code below. Of course

Write an InputStream to an HttpServletResponse

南笙酒味 提交于 2019-11-26 22:23:33
问题 I have an InputStream that I want written to a HttpServletResponse. There's this approach, which takes too long due to the use of byte[] InputStream is = getInputStream(); int contentLength = getContentLength(); byte[] data = new byte[contentLength]; is.read(data); //response here is the HttpServletResponse object response.setContentLength(contentLength); response.write(data); I was wondering what could possibly be the best way to do it, in terms of speed and efficiency. 回答1: Just write in

How to convert an InputStream to a DataHandler?

徘徊边缘 提交于 2019-11-26 20:25:24
问题 I'm working on a java web application in which files will be stored in a database. Originally we retrieved files already in the DB by simply calling getBytes on our result set: byte[] bytes = resultSet.getBytes(1); ... This byte array was then converted into a DataHandler using the obvious constructor: dataHandler=new DataHandler(bytes,"application/octet-stream"); This worked great until we started trying to store and retrieve larger files. Dumping the entire file contents into a byte array