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
19
votes
2 answers

Android: write failed: EPIPE (Broken pipe) Error on write file

I was trying to take screenshot of the Android screen programatically. I had done the following code: private void getsnap(){ try{ Process sh = Runtime.getRuntime().exec("su", null, null); OutputStream os = sh.getOutputStream(); …
18
votes
3 answers

How do you mock an output stream?

By 'output steam' i mean any object which receives a sequence of bytes, or characters or whatever. So, java.io.OutputStream, but also java.io.Writer, javax.xml.stream.XMLStreamWriter's writeCharacters method, and so on. I'm writing mock-based tests…
Tom Anderson
  • 46,189
  • 17
  • 92
  • 133
18
votes
3 answers

Convert OutputStream to ByteArrayOutputStream

I am trying to convert an OutputStream to a ByteArrayOutput Stream. I was unable to find any clear simple answers on how to do this. This question was asked in the title of the question on StackOverflow, but the body of the question aske how to…
Bill Smith
  • 187
  • 1
  • 1
  • 8
17
votes
6 answers

Are the C formatted I/O functions (printf, sprintf, etc) more popular than IOStream, and if so, why?

I've been looking through a lot of code made by others lately and happened to notice everyone uses "printf" style C functions a lot, but the C++ functions learned in school (cout, specifically) don't seem so popular. Is this a valid observation, and…
Russel
  • 3,609
  • 8
  • 33
  • 32
17
votes
3 answers

Sharing output streams through a JNI interface

I am writing a Java application that uses a C++ library through a JNI interface. The C++ library creates objects of type Foo, which are duly passed up through JNI to Java. Suppose the library has an output function void Foo::print(std::ostream…
Chris Conway
  • 55,321
  • 43
  • 129
  • 155
17
votes
2 answers

How to read/write a file in UTF-8 in Java?

I am getting this error: io.MalformedByteSequenceException: Invalid byte 2 of 2-byte UTF-8 sequence The solution is to read and write a file in UTF-8. My code is: InputStream input = null; OutputStream output = null; OutputStreamWriter…
Gaurav Wadhwani
  • 358
  • 2
  • 6
  • 16
17
votes
3 answers

Is an OutputStream in Java blocking? (Sockets)

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…
salbeira
  • 2,375
  • 5
  • 26
  • 40
16
votes
2 answers

How to read pdf file and write it to outputStream

I need to read a pdf file with filepath "C:\file.pdf" and write it to outputStream. What is the easiest way to do that? @Controller public class ExportTlocrt { @Autowired private PhoneBookService phoneBookSer; private void…
Juraj Vlahović
  • 400
  • 2
  • 4
  • 12
16
votes
3 answers

How to use HttpsURLConnection through proxy by setProperty?

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…
CJeremy
  • 209
  • 1
  • 3
  • 7
16
votes
2 answers

Java Networking: Explain InputStream and OutputStream in Socket

I have created a server by using ServerSocket. After that, I have created Client using Socket, and connect to this server. After that, I do "some stuff" with InputStream and OutputStream is taken from Socket Object. But, I don't really understand…
hqt
  • 29,632
  • 51
  • 171
  • 250
14
votes
1 answer

Benefits of using flush() close() in Android streams?

I know the general idea but I'm just not sure if it has an effect since the Android api states following: "Flushes this stream. Implementations of this method should ensure that any buffered data is written out. This implementation does…
Warpzit
  • 27,966
  • 19
  • 103
  • 155
14
votes
6 answers

When does a stream close if its not closed manually?

I would like to know when does a stream close if its not closed manually. By this I mean, will the stream be closed if the scope of its reference is no more? Consider the following sample scenario. Class A{ InputStream in; OutputStream out; A(){ …
Sree Karthik S R
  • 335
  • 2
  • 3
  • 10
14
votes
3 answers

broken pipe error while Capturing image in android

I am going to capture an image which is from an application in android, but there is some problem with Output Stream and there is an error with BROKEN PIPE with JAVA.IO. My code if below. Here is the problem with the write command function. I have…
Mikin Patel
  • 431
  • 2
  • 6
  • 15
14
votes
2 answers

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

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…
Chris Braswell
  • 235
  • 2
  • 4
  • 12
14
votes
6 answers

How do I zip on the fly and stream to Response.Output in real time?

I am trying to use the following code: I get a corrupted zip file. Why? The file names seem OK. Perhaps they are not relative names, and that's the problem? private void trySharpZipLib(ArrayList filesToInclude) { // Response…
Moshe
1 2
3
98 99