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.

279 questions
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,010
  • 12
  • 43
  • 88
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
  • 455
  • 1
  • 4
  • 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
  • 502
  • 2
  • 9
  • 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,058
  • 25
  • 90
  • 151
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
  • 793
  • 9
  • 26
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
  • 477
  • 4
  • 23
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,532
  • 14
  • 37
  • 53
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){ …
B. Clay Shannon
  • 1,055
  • 124
  • 399
  • 759
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
  • 1,934
  • 12
  • 22
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,001
  • 4
  • 27
  • 46
3
votes
3 answers

How to kill a BufferedInputStream .read() call

I'm working on writing a program to download very large files (~2GB) from a server. I've written the program to be able to resume partially finished downloads, In order to simulate a bad internet connection, I've been pulling my ethernet cord out of…
3
votes
2 answers

Convert a BufferedInputStream to a File

I am loading a image from the web to the local android phone. The code that I have for writing to a file is as follows BufferedInputStream bisMBImage=null; InputStream isImage = null; URL urlImage = null; …
vikramjb
  • 1,335
  • 3
  • 25
  • 48
3
votes
2 answers

android convert bitmap to bufferedinputstream

Newb question; I've got a bitmap in memory; Private Bitmap MyPicture; Then later, I fill that MyPicture from imager from the camera. I need to upload that photo using the FTP client from the apache commons. fcon.storeFile("filename", new…
Dee
  • 1,488
  • 2
  • 15
  • 28
1 2
3
18 19