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.

74 questions
2
votes
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
  • 3,529
  • 2
  • 23
  • 31
2
votes
0 answers

Android, Writing video frames in real-time results in pauses

I am trying to capture video frames, encode it with MediaCodec, and save it into a file. The code that I am using is: public class AvcEncoder { private static String TAG = AvcEncoder.class.getSimpleName(); private MediaCodec mediaCodec; …
2
votes
2 answers

Java, send and receive a file with socket: is it necessary use bufferedinputstream and bufferedoutputstream?

I'm trying to write two methods for send and receive file with java socket in a client-server application and I have some doubts: I use FileInputStream and FileOutputStream. Are BufferedInputStream and BufferedOutputStream better? static protected…
2
votes
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
  • 260
  • 3
  • 11
2
votes
4 answers

Java BufferedOutputStream: How many bytes to write

This is more like a matter of conscience than a technological issue :p I'm writing some java code to dowload files from a server...For that, i'm using the BufferedOutputStream method write(), and BufferedInputStream method read(). So my question is,…
1
vote
2 answers

What happens when you write(byte[] b) to a BufferedOutputStream? (Java)

When you use the method write(byte[] b) to write to a BufferedOutputStream, the write method from FilterOutputStream is used. The documentation says: "The write method of FilterOutputStream calls its write method of three arguments with the…
user1209776
  • 157
  • 1
  • 3
  • 8
1
vote
3 answers

BufferedOutputStream not working with Korean characters as expected

I'm trying to write Korean characters to a File and it's writing some gibberish data which I need to work around for showing as Korean data when I open it in CSV. How can I achieve my requirement without the workaround of decoding back to UTF-8 and…
1
vote
1 answer

Can we read a file using BufferedReader and write the content to another file using BufferedOutputStream? and vice versa

I am learning about java io concepts and I need to clarify a doubt about it. I am trying to read a file using a reader like BufferedReader and write the same to OutputStream like BufferedOutputstream. Here is a sample of my code. import…
1
vote
1 answer

How can i copy png files? and Dynamic directory path

So I wrote this code that copies a file from a folder to another one! it works fine with .mp3 .wav .jpeg.jpg files but it doesn't work properly with .png files! (the image is destroyed or half of it is missed) Is there a way I can edit the code is…
Dhia Djobbi
  • 1,176
  • 2
  • 15
  • 35
1
vote
1 answer

Server and Client sending file Java

I am writing a program that has a client and server where the client will send a img file to the server. The code below is for the server where it will get stuck on that while loop from obIn.read blocking on its last run, so it never is able to…
Kayracer
  • 169
  • 3
  • 13
1
vote
1 answer

Can you prevent a BufferedOutputStream (java) from transmitting?

I"m trying to write a string to an OutputStream using public SSLSocket mClient; private BufferedOutputStream mOutputStream; .... mOutputStream = new BufferedOutputStream( mClient.getOutputStream() ); public synchronized void…
Alex
  • 11
  • 3
1
vote
1 answer

BufferedOuputStream make Blank file

I have the following code for upload file from client to server tcp but when i try to open manually the file is empty why the good weight.. I have look lot of post on stackOverflow but nothing make change Thx (Sorry for my bad…
E.P
  • 13
  • 4
1
vote
1 answer

Testing write(byte[]) on FileOutputStream vs. BufferedOutputStream

Is there an actual performance difference when using write(byte[]) methods from FileOutputStream and BufferedOutputStream? I tested both on HDD to write 500 MB file and the result was 13 and 12 seconds: try(FileOutputStream out = new…
user963241
  • 6,758
  • 19
  • 65
  • 93
1
vote
0 answers

HttpURLConnection on android to download in ranges

On attempting to download a simple text file using HttpURLConnection in two parts, I am facing an issue. Code: public class MainActivity extends AppCompatActivity { final String TAG = "MainActivity"; int file_size; String urlstring =…
1
vote
1 answer

convert long to byte[] returns unreadable format

I am trying to convert long to bytes because I want to write the time stamp in seconds in a file. Belwo are the method wich I am using to convert long to bytes[] and how I write them into a file.. What I am getting from the following line:…
Amrmsmb
  • 1
  • 27
  • 104
  • 226