Questions tagged [inputstream]

An abstract mechanism for reading a data stream in Java

An InputStream is an abstract mechanism for reading a data stream in Java. A stream is usually comprised of data obtained from a local file, or data being transmitted from a remote server over a network protocol such as HTTP or FTP.

An InputStream is abstract, and doesn't describe the type of data that is being read. Typically you would implement one of the subclasses instead, such as FileInputStream, which more appropriately describes the type of data being handled, and provides additional methods appropriate for that data type.

Streamed data is typically consumed as it is read. In other words, you read the data from the stream starting from the first byte and ending at the last byte. You are usually able to skip over bytes that you don't want to handle, but you can't typically go back to a previous position in the stream, unless you implement some kind of buffering mechanism. In general, you should treat all streamed data as being once-only, and thus you should manually retain any information that you wish to refer to later.

4382 questions
1
vote
2 answers

How to extract the byte [] array from a PdfDocument

After a lot of researching, I still can't find a way to extract a byte[] from a PdfDocument object. How can I achieve this? I've tried with FileInputStream, but actually I don't have the "physical path" of the PdfDocument because I'm creating one…
Nexussim Lements
  • 535
  • 1
  • 15
  • 47
1
vote
4 answers

getInputStream throws Exception

I'm trying to invoke a webservice and parse the returned XML, so my invoke URL is…
Houssem
  • 2,069
  • 3
  • 27
  • 42
1
vote
1 answer

How to retrieve & share bitmap from device folder

I am building a meme generator app. So far, the app does everything I need it to do but I want to add 1 more functionality. The app saves the meme as a bitmap on my device. I want to add a functionality where, if the user wishes to share the meme…
1
vote
1 answer

Getting a file as a resource on classpath

I'm trying to read a keystore as a resource. Sample code below. The problem I'm running into is that inputStream remains null. import java.io.InputStream; import java.util.List; import org.linguafranca.pwdb.kdbx.KdbxCreds; import…
Lone Wanderer
  • 160
  • 4
  • 15
1
vote
1 answer

Corrupted file is generated with FileInputStream and outstream : java, android

Currently I am working to implement a SQlite db backup feature in my application with stream. when I backup the database it works and the file has data as I have verified it through "Db browser for SQlite". But when try to restore through…
Irfan Ul Haq
  • 1,065
  • 1
  • 11
  • 19
1
vote
0 answers

How to get the encoding of a java.io.InputStream

I have a service, which gets a java.io.InputStream and the datas from it to build a mime massage and send it with the help of a SMTPServer to the given address. The problem is, that the char encoding of the incoming emails is bad, it cannot send the…
Peter
  • 11
  • 1
1
vote
1 answer

Java convert a pdf returned as Rest API response to text

I have to consume as rest api API(/getconstomerList) from my java code that returns a pdf file. I need to read the PDF file and convert it to String. I tried doing this with tika BodyContentHandler handler = new BodyContentHandler(10 * 1024 *…
Lucie
  • 127
  • 1
  • 2
  • 12
1
vote
1 answer

Android - Arduino Bluetooth communication: app stops reading inputstream

I'm trying to process an analog pressure sensor signal on Arduino Uno and sends an output string to my Android app UI via Bluetooth. I've established a BT connection between the app and the HC-05 module and was able to get the inputStream on the UI…
rsayed
  • 11
  • 2
1
vote
1 answer

Why does reading input stream from a zip file on the classpath not read properly in Java?

I have a valid zip file on my classpath (Java 8). It is 302617 bytes long. I would like to copy it to a temp folder for expansion and further processing in my application, using standard ApacheCommons IO Utils. If I read it as a file, e.g.: …
otter606
  • 335
  • 1
  • 4
  • 21
1
vote
2 answers

Read from BufferedReader for a specific Duration

So, I'm reading from a BufferedReader. Everything goes fine, until I add one condition. I need to read from BufferedReader for a specific duration of time. This is what I'm doing right now. while ((line = br.readLine()) != null …
nirvair
  • 4,001
  • 10
  • 51
  • 85
1
vote
1 answer

When (how often) to open/close input/output streams?

I am trying to write an FTP client program and I have input and output streams to transfer files between server and my computer. When I was thinking about how to design the class, I couldn't decide on whether to open up a new InputStream every time…
C. O.
  • 125
  • 9
1
vote
0 answers

IOUtils.copyLarge not working for compressed input

I am attempting to transfer a gzipped file using IOUtils.copyLarge. When I transfer from a GZIPInputStream to a non-compressed output, it works fine, but when I transfer the original InputStream (attempting to leave it compressed) the end result is…
foobarbaz
  • 508
  • 1
  • 10
  • 27
1
vote
3 answers

What's a more memory-efficient way of taking part of a byte[]?

I've got a ByteArrayOutputStream of stereo audio data. Currently I'm doing this, which I know is bad: WaveFileWriter wfw = new WaveFileWriter(); AudioFormat format = new AudioFormat(Encoding.PCM_SIGNED, 44100, 16, 1, 2, 44100, false); byte[]…
fredley
  • 32,953
  • 42
  • 145
  • 236
1
vote
1 answer

Android attachment / file picker into InputStream string

I want to create a similar function as below image. Allow user to select image / pdf file from device and convert the file into inputstream as string and sent to server. I had go through this Attaching a file of any type in Android application? and…
Shawn.Y
  • 181
  • 3
  • 14
1
vote
1 answer

How to fix "Exception in thread "main" java.net.SocketException: Connection reset"

I am trying to set up a java program that would send and receive a file. I know there are similar things for this problem on this website, but I was having trouble after reading those. I followed this video:…
Bert
  • 15
  • 1
  • 3