Questions tagged [bufferedoutputstream]

An abstract mechanism for writing data to a stream via a buffer, for improved writing performance

An BufferedOutputStream is a wrapper around an OutputStream, whereby the data being written is buffered locally before being written to the stream. Buffering can be either fully-buffered or partially-buffered. Fully-buffered is where the entire contents are written to a local buffer before it is sent over the OutputStream. Partially-buffered is where a small portion of the data is held in a local buffer, and once the buffer is full, that data is written to the stream and the buffer is emptied.

An OutputStream is usually buffered to improve performance, as it allows data to be written to a network of file in large efficient chunks, rather than a number of smaller writes. This removes the overhead and performance impact of the multiple small writes. The downside, however, is that the buffer consumes some memory and has some CPU impact, but these downsides are usually very tiny, and are far outweighed by the benefits of buffering.

72 questions
1
vote
2 answers

Client doesn't recognize end of file stream

I'm making File Transfer Thread with java Here is Server's Code (fileWriter = new BufferedOutputStream(fileTransferSocket.getOutputStream())) try { BufferedInputStream fileReader = new BufferedInputStream(new…
1
vote
1 answer

BufferedOutputStream multiple lines Write in File

I have a little problem with a function I made. I want that everytime I give a string to this function, it will save me to a new Line in the same file, but actually now is saving only the last string Im givving. It's like overwriting again and…
Nicholas
  • 2,559
  • 1
  • 21
  • 28
1
vote
3 answers

How to write in file by BufferedOutputStream?

I want to copy data from demo1.txt to demo2.txt, although I can do it by BufferedReader, I want to copy by BufferedInputStream / BufferedOutputStream. Please show me how to do this. import java.io.*; class stream4 { public static void…
vimalraturi
  • 333
  • 1
  • 4
  • 14
1
vote
3 answers

Save length of byte array in a Byte array

I am writing in a BufferedOutputStream three times: b1 = baos1.toByteArray(); b2 = baos2.toByteArray(); …
1
vote
3 answers

BufferedOutputStream not writing to standardIO

I am attempting to use the BinaryStdOut.java class provided by Robert Sedgwick in his Algorithms 4E textbook. The code for this class is freely available on his website, but for ease of reference, I will show relevant snippets of it here. In the…
sven
  • 121
  • 4
  • 11
1
vote
1 answer

Sending audio dircetly to the speakers java

The title basically tells my story, I would like to send audio directly to the speaker system from a java program, i was thinking of trying to write directly to the speakers in /dev/ in linux using bytes obtained from an audio file, which i'm not…
Terra
  • 25
  • 9
1
vote
0 answers

How to write part of header using BufferedOutputStream?

I want to write a ~20000 bytes to a replace the same number of bytes of file at offset OFFSET using a BufferedOutputStream. I try to do this with the following code: headerOffset = 12000; headerSize = 20000; byte[] ba = new…
DannyClay
  • 250
  • 3
  • 10
1
vote
1 answer

Android - BufferedOutputStream doesn't flush

I have a problem with a BufferedOutputStream. I want to send a kml file from an Android device to a java server through a socket connection. (The connection is ok, i am already able to exchange data with a PrintWriter in an other part of my…
ZarkDev
  • 1,027
  • 1
  • 12
  • 23
0
votes
1 answer

Speed on file reading / writing by BufferedInputStream / BufferedOutputStream

Got two questions. What does actually the program do if coded bis.read() instead of bis.read(bys)? (It works at any rate though much slower.) Why is bos.write(bys) much faster than bos.write(bys, 0, len)? (I expected that both are same in speed in…
0
votes
0 answers

adobe air file download issue

If the file size on the server is 0 during adobe air download, an io error occurs. When downloading directly to the server side api url, the file is flushed well. Download using bufferedInputStream and bufferedOutputStream. When downloading air…
0
votes
0 answers

Java TCP BufferedOutputStream reconnection strategy

I have an application that has to send data via TCP socket to another application. This is a 1 way stream from client to server. When sending data the client must retry/reconnect and try to insure all data is sent should the receiver/listener/server…
Steve Fitzsimons
  • 3,190
  • 7
  • 24
  • 57
0
votes
1 answer

BufferOutputStream only writes to larger pieces of data and not when < 40kb

My goal here is to decrypt an entire file into another file. This output loop for some reason will not write to addmsgOut if the cypherBufStream (a BufferedInputStream reading an input file) is too small i.e. around 128 bytes. When bringing in…
0
votes
0 answers

POST Request with String parameter in Java

I am trying to send a post request from my Android App to Express server. I create a JSON, then convert it to a string, when I log it it looks something like: {"customerID":"testID" "productID":"testID", "productCategory":"testCategory",…
0
votes
0 answers

BufferedOutputStream write method taking too long

I am using BufferedOutputstream write method to write to a file. But it is taking ages to complete. I have same code running on AIX OS and its working just fine, but on RHEL 7.6 its not working as required. Java version is 1.6 Code: File…
Sarshad
  • 29
  • 4
0
votes
0 answers

Using ByteArrayOutputStream along with BufferedOutputStream to avoid memory issues, is it good idea?

I am working on spring boot application which needs to send the workbook created by apache poi workbook document to the client via REST API, although I am able to send it, I wanted to know the efficient way to send the file over the wire. I wrote…