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.

1482 questions
39
votes
7 answers

Log4J: How do I redirect an OutputStream or Writer to logger's writer(s)?

I have a method which runs asynchronously after start, using OutputStream or Writer as parameter. It acts as a recording adapter for an OutputStream or Writer (it's a third party API I can't change). How could I pass Log4J's internal OutputStream or…
39
votes
5 answers

How can an app use files inside the JAR for read and write?

I need to store data into files inside .jar file and read it again. I know that I can use Class.getResourceAsStream() method but it returns an InputStream that I can read from. But I look for a way to write.
Moataz Aahmed Mohammed
  • 1,307
  • 5
  • 22
  • 33
36
votes
7 answers

How to check whether an OutputStream is closed

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…
chrisbunney
  • 5,819
  • 7
  • 48
  • 67
35
votes
4 answers

Do I need to flush the servlet outputstream?

Do I need to "flush" the OutputStream from the HttpServletResponse? I already saw from to Should I close the servlet outputstream? that I don't need to close it, but it's not clear if I need to flush it. Should I expect it from the container as…
Carlos Aguayo
  • 543
  • 1
  • 4
  • 11
34
votes
5 answers

Why Java OutputStream.write() Takes Integer but Writes Bytes

I am writing an OutputStream, just noticed this in the OutputStream interface, public abstract void write(int b) throws IOException; This call write one byte to the stream but why it takes integer as an argument?
ZZ Coder
  • 74,484
  • 29
  • 137
  • 169
31
votes
3 answers

What is the use case for null(Input/Output)Stream API in Java?

With Java 11, I could initialize an InputStream as: InputStream inputStream = InputStream.nullInputStream(); But I am unable to understand a potential use case of InputStream.nullInputStream or a similar API for OutputStream i.e.…
Naman
  • 27,789
  • 26
  • 218
  • 353
31
votes
8 answers

How can I convert an InputStream to a DataHandler?

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…
pcorey
  • 850
  • 2
  • 9
  • 14
30
votes
3 answers

Testing what's written to a Java OutputStream

I am about to write junit tests for a XML parsing Java class that outputs directly to an OutputStream. For example xmlWriter.writeString("foo"); would produce something like foo to be written to the outputstream held inside the…
Ciryon
  • 2,637
  • 3
  • 31
  • 33
30
votes
6 answers

Java - How Can I Write My ArrayList to a file, and Read (load) that file to the original ArrayList?

I am writing a program in Java which displays a range of afterschool clubs (E.G. Football, Hockey - entered by user). The clubs are added into the following ArrayList: private ArrayList clubs = new ArrayList(); By the followng…
user2300264
  • 303
  • 1
  • 3
  • 5
27
votes
3 answers

Write an InputStream to an HttpServletResponse

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…
Sabry Shawally
  • 603
  • 2
  • 11
  • 24
24
votes
3 answers

Java: FilterInputStream what are the advantages and use compared to other streams

I’ve been reading on InputStream, FileInputStream, ByteArrayInputStream and how their use seems quite clear (output streams too). What I’m struggling is to understand the use of FilterInputStream & FilterOutputStream: What is the advantage of using…
Carlo Luther
  • 2,402
  • 7
  • 46
  • 75
23
votes
5 answers

How can I read a file to an InputStream then write it into an OutputStream in Scala?

I'm trying to use basic Java code in Scala to read from a file and write to an OutputStream, but when I use the usual while( != -1 ) in Scala gives me a warning "comparing types of Unit and Int with != will always yield true". The code is as…
Maurício Linhares
  • 39,901
  • 14
  • 121
  • 158
23
votes
7 answers

How to put data from an OutputStream into a ByteBuffer?

In Java I need to put content from an OutputStream (I fill data to that stream myself) into a ByteBuffer. How to do it in a simple way?
Rasto
  • 17,204
  • 47
  • 154
  • 245
20
votes
3 answers

How to upload a Java OutputStream to AWS S3

I create PDF docs in memory as OutputStreams. These should be uploaded to S3. My problem is that it's not possible to create a PutObjectRequest from an OutputStream directly (according to this thread in the AWS dev forum). I use aws-java-sdk-s3…
EagleBeak
  • 6,939
  • 8
  • 31
  • 47
20
votes
3 answers

How to make an image handler in NancyFx

I'm struggling to output an Image from byte[] out of my database in NancyFX to a web output stream. I don't have sample code close enough to even show at this point. I was wondering if anyone has tackled this problem and could post a snippet? I…
sethxian
  • 276
  • 2
  • 11
1
2
3
98 99