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

At what point does wrapping a FileOutputStream with a BufferedOutputStream make sense, in terms of performance?

I have a module that is responsible for reading, processing, and writing bytes to disk. The bytes come in over UDP and, after the individual datagrams are assembled, the final byte array that gets processed and written to disk is typically between…
Thomas Owens
  • 107,741
  • 94
  • 299
  • 427
13
votes
1 answer

docker logs and buffered output

I want to continously print dots without newline (waiting behavior). This bash one-liner works fine on my machine: $ while true; do sleep 1; printf '.'; done .......^C However, when I run it in a Docker container, and when I try to read its output…
Elouan Keryell-Even
  • 828
  • 1
  • 11
  • 33
10
votes
1 answer

Sockets: BufferedOutputStream or just OutputStream?

In order to get the fastest transfer speeds over TCP in Java, which is better: Option A: InputStream in = socket.getInputStream(); OutputStream out = socket.getOutputStream(); Option B: BufferedInputStream in = new…
8
votes
2 answers

BufferedInputStream into byte[] to be send over a Socket to a Database

I have been looking around for an answer to this, but couldn't really find anything on it. Earlier today, I asked how I could make a File into a String through a byte array, and then back again, for retrieval later. What people told me, was that I…
OmniOwl
  • 4,893
  • 14
  • 52
  • 99
6
votes
3 answers

OkHttp buffers ~800kb before uploading data despite flush()

Im trying to publish upload progress for images, uploading them using okhttp as my client and mimecraft to package up the multipart file. I have added logs to write the bytecount when data gets written to the socket (in chunks of 4kb if i can tell…
Glenn.nz
  • 2,230
  • 2
  • 15
  • 20
5
votes
1 answer

Writing large files using BufferedOutputStream

I am trying read and write large files (larger than 100 MBs) using BufferedInputStream & BufferedOutputStream. I am getting Heap Memory issue & OOM exception. The code looks like : BufferedInputStream buffIn = new BufferedInputStream(iStream); /**…
user1229894
  • 61
  • 1
  • 1
  • 3
5
votes
4 answers

How does BufferedOutputStream actually work at a low level?

I understand the theory behind BufferedOutputStream. Bytes are written to a buffer array until it is full, and then written (flushed) to the underlying stream - the idea being that it is faster than writing byte-by-byte as there are fewer OS…
user1209776
  • 157
  • 1
  • 3
  • 8
3
votes
4 answers

How to copy files in JAVA by bufferedInputStream and bufferedOutputStream?

I would like to use bufferedInputStream and bufferedOutputStream to copy large binary files from source file to destination file. Here is my code: byte[] buffer = new byte[1000]; try { FileInputStream fis = new…
user4486171
3
votes
1 answer

How big can the sendbuffersize in java Socket class be set to?

I have an application using an FTP library to transfer files. Receiving files works good, and mostly sending files also. The problem occurs when I'm trying to send a large file (3 MB), in which the application hangs. No error message, no nothing. I…
Hippo
  • 115
  • 1
  • 9
2
votes
1 answer

How to serialize a HashMap with BufferedOutputStream in Java?

I have a very large HashMap of the format HashMap>, and I want to serialize it using BufferedOutputStream because I think that it will be more efficient than with a regular OutputStream. But how do I divide the HashMap in chunks…
S.D
  • 372
  • 1
  • 12
2
votes
2 answers

How does RandomAccessFile.seek() work?

As per the API, these are the facts: The seek(long bytePosition) method simply put, moves the pointer to the position specified with the bytePosition parameter. When the bytePosition is greater than the file length, the file length does not…
SirVirgin
  • 123
  • 2
  • 10
2
votes
1 answer

Unable to copy PDF file using FileInputStream

I am trying to copy a PDF file from 1 location to another, but once I run the following code, I am unable to open the PDF (it is showing the following error.) There was an error opening this document. The file is damaged and could not be…
Keen Sage
  • 1,799
  • 4
  • 21
  • 39
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
2 answers

How to change the underlying buffer size of BufferedOutputStream used by logback's FileAppender?

We are using logback as our logging framework. We noticed that the FileAppender uses ResilientFileOutputStream which is backed by an BufferedOutputStream. We are wondering if there's a way to configure the buffer size of this BufferedOutputStream…
1
2 3 4 5