Questions tagged [bufferedinputstream]

An abstract mechanism for reading a data stream into a buffer, for improved reading performance

An BufferedInputStream is a wrapper around an InputStream, whereby the data being read is buffered locally. Buffering can be either fully-buffered or partially-buffered. Fully-buffered is where the entire contents of the InputStream is held locally in a variable. Partially-buffered is where a small portion of the stream data is held in a local variable, and as you read data from the buffer, those bytes are replaced with the next X bytes from the stream - ie the buffer overwrites itself as the data is consumed from it.

An InputStream is usually buffered to improve performance, as it allows data to be read from a network of file in large efficient chunks, rather than a number of smaller reads. This removes the overhead and performance impact of the multiple small reads. 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.

291 questions
5
votes
2 answers

Java buffered base64 encoder for streams

I have lots of PDF files that I need to get its content encoded using base64. I have an Akka app which fetch the files as stream and distributes to many workers to encode these files and returns the string base64 for each file. I got a basic…
fforbeck
  • 130
  • 1
  • 3
  • 12
5
votes
1 answer

reading data from a textfile and displaying it on the textview

i am trying to read data from a textfile "temp.txt" which is in my raw folder and displaying the contents of the file on the text view "text" whenever a button "button" is clicked, but my app crashes while doing so, there is quite a possibility that…
Asad
  • 49
  • 1
  • 5
5
votes
1 answer

How to Create a string from a BufferedInputStream using bytes?

I am trying to read a text file and create a string. I am using following code: String FILENAME = "file.txt"; File file = getApplicationContext().getFileStreamPath(FILENAME); int size = (int) file.length(); System.out.println("size: "+size); …
Piscean
  • 3,069
  • 12
  • 47
  • 96
5
votes
5 answers

Effect on the original InputStream after wrapping with BufferedInputStream

Suppose I have a method that take in an InputStream. This method need to wrap this InputStream with a BufferedInputStream to use its mark and reset functionality. However, the passed in InputStream might still be used by the caller of the…
Zekareisoujin
  • 465
  • 1
  • 5
  • 19
5
votes
2 answers

Socket reading using BufferedInputStream

I'm using Java's BufferedInputStream class to read bytes sent to a socket. The data to the socket is HTTP form so generally is a header with defined content-length, then some content. The problem I'm having is that sometimes…
Adam
  • 532
  • 3
  • 11
  • 22
4
votes
2 answers

Sending a databse via ftp - Getting a different file

I'm currently using this code to send a database over ftp (Using apache commons) File file = getDatabasePath("database"); FTPClient ftp = new FTPClient(); try { ftp.connect(InetAddress.getByName(domain)); ftp.login(username, password); …
4
votes
1 answer

BufferedStream chaining Scala (or Java)

Assuming that I have to write to a binary file. I can use the following code val fos = new FileOutputStream("fileName") and then use fos.write(bytes) Is it always a good idea to chain it with a buffered stream? as in: val fos = new…
Jus12
  • 17,824
  • 28
  • 99
  • 157
4
votes
2 answers

Java BufferedReader arabic text file problem

Problem: Arabic words in my text files read by java show as series of question marks : ?????? Here is the code: File[] fileList = mainFolder.listFiles(); BufferedReader bufferReader = null; Reader reader = null; …
Saher Ahwal
  • 9,015
  • 32
  • 84
  • 152
4
votes
1 answer

BufferedInputStream or FileInputStream IOException

I've just released an Android app that parses a local file and make some process with the data. Some days ago one of my customers has reported me an error, each time he tries to process his file the app crashes. This is the error log he sent…
Wonton
  • 1,033
  • 16
  • 33
4
votes
1 answer

Issue in reading french word from text file in java/android

I'm trying to read a french file contents (character by character) and checking there ascii value to do some operation.Everything works fine containing english alphabet but for character like àéèé, i'm facing some issue. For Example if my file…
Pranesh Sahu
  • 595
  • 5
  • 26
4
votes
4 answers

Reading HttpURLConnection InputStream - manual buffer or BufferedInputStream?

When reading the InputStream of an HttpURLConnection, is there any reason to use one of the following over the other? I've seen both used in examples. Manual Buffer: while ((length = inputStream.read(buffer)) > 0) { os.write(buf, 0,…
stormin986
  • 7,672
  • 15
  • 42
  • 54
4
votes
1 answer

How do I access the returned value from a Web API Method in Android?

After being confused about how to do so (as can be seen here and here, I am now successfully connecting to my server app and the appropriate RESTful method with this code: public void onFetchBtnClicked(View v){ if(v.getId() == R.id.FetchBtn){ …
4
votes
1 answer

Can BufferedInputStream.read(byte[] b, int off, int len) ever return 0? Are there significant, broken InputStreams that might cause this?

Is it ever possible for BufferedInputStream(byte[] b, int off, int len) to return 0? READER'S DIGEST VERSION (you can read the rest below, for context, but I think it boils down to this:) Are there InputStreams (i.e. SocketInputStream,…
JVMATL
  • 2,064
  • 15
  • 25
4
votes
3 answers

Buffer Size for BufferedInputStream

How to determine the size of Buffer, while using Buffered Input Stream for reading batch of files? Is it based on the File size?I'm using, byte[] buf = new byte[4096]; If i increase the buffer size,it will read quickly?
user2507974
  • 122
  • 1
  • 2
  • 15
4
votes
4 answers

How can I make a new buffered reader object that starts reading from where another stopped?

I have a buffered reader that reads a large file line-by-line to remove duplicate lines. Instead of loading the whole file in the memory I'd like to do this by using two buffered readers: The first iterates over fixed portions of the file, loading…
Hady Elsahar
  • 2,121
  • 4
  • 29
  • 47
1 2
3
19 20