Questions tagged [outputstream]

An abstract mechanism for writing data to a stream in Java and C#

An OutputStream is an abstract mechanism for writing data to a stream in Java and C#. A stream is usually comprised of data to write to a local file, or data being transmitted to a remote server over a network protocol such as HTTP or FTP.

An OutputStream is abstract, and doesn't describe the type of data that is being written. Typically you would implement one of the subclasses instead, such as FileOutputStream, which more appropriately describes the type of data being handled, and provides additional methods appropriate for that data type.

1409 questions
362
votes
12 answers

How to convert OutputStream to InputStream?

I am on the stage of development, where I have two modules and from one I got output as a OutputStream and second one, which accepts only InputStream. Do you know how to convert OutputStream to InputStream (not vice versa, I mean really this way)…
Waypoint
  • 15,705
  • 36
  • 110
  • 167
302
votes
9 answers

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

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!
Bohemian
  • 5,777
  • 11
  • 36
  • 47
148
votes
6 answers

Write string to output stream

I have several output listeners that are implementing OutputStream. It can be either a PrintStream writing to stdout or to a File, or it can be writing to memory or any other output destination; therefore, I specified OutputStream as (an) argument…
yart
  • 6,695
  • 10
  • 33
  • 36
139
votes
5 answers

Can you explain the HttpURLConnection connection process?

I am using HTTPURLConnection to connect to a web service. I know how to use HTTPURLConnection but I want to understand how it works. Basically, I want to know the following: On which point does HTTPURLConnection try to establish a connection to the…
Arci
  • 6,327
  • 20
  • 65
  • 95
131
votes
7 answers

Byte[] to InputStream or OutputStream

I have a blob column in my database table, for which I have to use byte[] in my Java program as a mapping and to use this data I have to convert it to InputStream or OutputStream. But I don't know what happens internally when I do so. Can anyone…
GuruKulki
  • 24,340
  • 43
  • 131
  • 192
130
votes
7 answers

Is it necessary to close each nested OutputStream and Writer separately?

I am writing a piece of code: OutputStream outputStream = new FileOutputStream(createdFile); GZIPOutputStream gzipOutputStream = new GZIPOutputStream(outputStream); BufferedWriter bw = new BufferedWriter(new…
Adon Smith
  • 1,739
  • 7
  • 16
  • 19
122
votes
9 answers

Is there a Null OutputStream in Java?

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?
Brandon Yarbrough
  • 33,119
  • 22
  • 98
  • 134
97
votes
6 answers

Should one call .close() on HttpServletResponse.getOutputStream()/.getWriter()?

In Java Servlets, one can access the response body via response.getOutputStream() or response.getWriter(). Should one call .close() on this OutputStream after it has been written to? On the one hand, there is the Blochian exhortation to always close…
Steven Huwig
  • 17,999
  • 8
  • 53
  • 78
76
votes
10 answers

Connecting an input stream to an outputstream

update in java9: https://docs.oracle.com/javase/9/docs/api/java/io/InputStream.html#transferTo-java.io.OutputStream- I saw some similar, but not-quite-what-i-need threads. I have a server, which will basically take input from a client, client A, and…
jbu
  • 14,925
  • 29
  • 80
  • 100
66
votes
5 answers

How to output a character as an integer through cout?

#include using namespace std; int main() { char c1 = 0xab; signed char c2 = 0xcd; unsigned char c3 = 0xef; cout << hex; cout << c1 << endl; cout << c2 << endl; cout << c3 << endl; } I expected…
xmllmx
  • 33,981
  • 13
  • 121
  • 269
58
votes
2 answers

Preferred way to use Java ZipOutputStream and BufferedOutputStream

In Java does it matter whether I instantiate a ZipOutputStream first, or the BufferedOutputStream first? Example: FileOutputStream dest = new FileOutputStream(file); ZipOutputStream zip = new ZipOutputStream(new BufferedOutputStream(dest)); // use…
jjathman
  • 12,156
  • 7
  • 27
  • 33
45
votes
4 answers

Why is it good to close() an inputstream?

Why is it necessary to close() java.io.InputStream or its subclasses? Now with java.io.OutputStream, say FileOutputStream, after writing to a file, if we don't close() the output stream, the data that we intended to write in the file remains in the…
Aditya Singh
  • 2,275
  • 1
  • 17
  • 38
40
votes
5 answers

Writing to ZipArchive using the HttpContext OutputStream

I've been trying to get the "new" ZipArchive included in .NET 4.5 (System.IO.Compression.ZipArchive) to work in a ASP.NET site. But it seems like it doesn't like writing to the stream of HttpContext.Response.OutputStream. My following code example…
Daniel Sørensen
  • 403
  • 1
  • 5
  • 7
38
votes
5 answers

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

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…
daveslab
  • 9,280
  • 21
  • 55
  • 86
36
votes
1 answer

How to put the content of a ByteBuffer into an OutputStream?

I need to put the contents of a java.nio.ByteBuffer into an java.io.OutputStream. (wish I had a Channel instead but I don't) What's the best way to do this? I can't use the ByteBuffer's array() method since it can be a read-only buffer. I also may…
Jason S
  • 171,795
  • 155
  • 551
  • 900
1
2 3
93 94