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
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…
0
votes
0 answers

Exception by BufferedOutputStream.flush: Attempt to invoke virtual method 'void java.io.OutputStream.write(byte[], int, int)'

An app gets the following exception occasionally: Stack trace: java.lang.NullPointerException: Attempt to invoke virtual method 'void java.io.OutputStream.write(byte[], int, int)' on a null object reference at…
Hong
  • 17,643
  • 21
  • 81
  • 142
0
votes
0 answers

How to skip EOF while dealing with mutiple documents?

My ByteArrayOutputStream contains data for multiple documents (Thus having more that 1 EOF). While I try to send the output using BufferedOutputStream, it only passes the data for the last document (probably because it overwrites all other docs but…
05_pingpong
  • 77
  • 1
  • 2
  • 13
0
votes
1 answer

Can we append multiple data into a bufferedoutputStream?

I have data from 3 files in a ByteArrayOutputStream variable. But when I try to pass it on through BufferedOutputStream, it only sends the data for the last file. byte [] finalData = new byte[64000]; finalData = outputStream.toByteArray(); …
05_pingpong
  • 77
  • 1
  • 2
  • 13
0
votes
2 answers

How to store primitives using BufferedOutputStream

Hello everyone I'm in my second semester of CS and we are on the subject of file IO using InputStreams and OutputStreams, everything was relatively simple until this subject for me. I am a little confused with the BufferedOutputStream class. I…
Philip Verso
  • 23
  • 1
  • 5
0
votes
1 answer

Images in apache POI XWPF document have color distortion

I am attempting to design a report template which has many(hundreds of) images being referred to by hyperlinks. I want the document to be under 25Mb (for email and other reasons), so I'm trying to compress the images using the following code: //I…
0
votes
2 answers

Writing accelerometer sensor data to file is out of order

I am developing an Android app which will write the timestamp and 3-axis accelerometer sensor data (timestamp,ax,ay,az) to a csv file . I am getting two problems first is that timestamp of few entries are not written in ascending order in file (see…
0
votes
2 answers

HTTP Server issues

Hi guys i have a very basic http server coded in about 30 minutes for an assignment and have come across a very weird problem. We were specified to use only BufferedOutputStream instead of a StreamWriter as there is apparently an issue with using…
A Merz
  • 25
  • 6
0
votes
1 answer

Does saving files in a ".zip" folder speed up file write time to network drive?

I know that when I write a new file to a folder that ends in ".zip" it compresses the file. This is when using BufferedOutputStream in JAVA and saving to a windows file system. I'm saving these files to a network drive, so the write time is…
Chris
  • 49
  • 4
0
votes
0 answers

Impact of writing to multiple opened files

I am trying to optimize the logging system of an Android application which causes some unwanted latency. There are multiple files opened which log different parts and should be kept separate. I am not very familiar with low-level filesystem design…
Radu Ionescu
  • 3,462
  • 5
  • 24
  • 43
0
votes
0 answers

BufferedOutputStream Android (Writing to external storage)

I have a problem writing to the external storage in android simulator. If you track down the BufferedOutputStream in the attached screenshot. For some reason when I write to the internal storage, to cache, or external storage using…
Yousef Imran
  • 1,071
  • 2
  • 10
  • 16
0
votes
1 answer

Java ZipOutputStream writes some files but not others

I am using Java's ZipOutputStream class to write a large zip file. It works fine when the zip file only has 1000 subfiles and subfolders. It also works fine when the zip file only has 10000 subfiles and subfolders. But, for some reason, when I ramp…
0
votes
2 answers

How do I use Buffered streams to append to a file in Java?

I have the following code, but I'm not sure that i'm doing everything correctly in terms of efficiency/flushing/closing streams. Some advice would greatly help, thank you OutputStream out = null; try { out = new…
Kamilski81
  • 14,409
  • 33
  • 108
  • 161
0
votes
2 answers

For-loop not executing File writing commands

I have a program that is supposed to generate a file with a random integer name and append 200 characters of data to each file. I have already succeeded in being able to create a file: BufferedOutputStream bos = new…
mirvine
  • 126
  • 1
  • 2
  • 14
0
votes
1 answer

java file receive stops

I'm using sockets for file transfer in java. Here is the Client code for(int i = 0;i < fileList.size();i++) { String filename = (String)fileList.get(i); RequestFile(filename); try { BufferedOutputStream fileWriter = new…