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
1 answer

Incorrect printing of non-eglish characters with Java

I thought this was only an issue with Python 2 but have run into a similar issue now with java (Windows 10, JDK8). My searches have lead to little resolution so far. I read from 'stdin' input stream this value: Viļāni. When I print it to console…
Paul
  • 813
  • 11
  • 27
1
vote
1 answer

Get and display image in android from inputstream

Starting off by saying I'm new to the Android language and I need help with something. I'm trying to get an image from an inputstream connected to my java program and save it to the internal storage and after that I display it. However I'm not…
Buddvar
  • 13
  • 1
  • 5
1
vote
3 answers

Why won't input stream find a file outside of the class folder

I want to want to use input stream with a file "NewFile.java", the code I have works fine if the file is situated in the same folder as the .class file that is performing the action. But once I move I get null reference. I have tried using absolute…
AnonymousAlias
  • 1,149
  • 2
  • 27
  • 68
1
vote
0 answers

jcifs - How to copy folder from shared folder to local folder

I have to copy files and folders from a shared folder to a local folder (linux). I access to the shared folder using SmbFile and I copy the files using InputStream/OutputStream. I want to copy the folders with their contents too. How can I perform…
Pame1692
  • 229
  • 4
  • 12
1
vote
1 answer

Why Resume Downloading downloads corrupted file in Java Application?

In My Struts base Java web application , I have implemented download functionality with pause/resume. let me explain how my download works , actually file (e.g. image file, doc) will be converted to pdf in the server then it will start downloading…
Rahul Rabhadiya
  • 430
  • 5
  • 19
1
vote
2 answers

Downloaded files are corrupted when buffer length is > 1

I'm trying to write a function which downloads a file at a specific URL. The function produces a corrupt file unless I make the buffer an array of size 1 (as it is in the code below). The ternary statement above the buffer initialization (which I…
celoj
  • 13
  • 3
1
vote
1 answer

XMLStreamReader / InputStream xxe vulnerability showing up in Checkmarx report

These lines of code are causing an xxe vulnerability to show up in a Checkmarx report: InputStream is = connection.getInputStream(); XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader reader =…
Artanis
  • 561
  • 1
  • 7
  • 26
1
vote
0 answers

Content cuts off when trying to return all of URL http content

I'm trying to return the http content from a website. However, not all of the content shows. I'm using Android Studio 3.1.4, SDKVersion 27. For reference, this is part of an exercise in the online Udemy course: The Complete Android N Developer…
1
vote
1 answer

Downloading a PDF file with HttpUrlConnection and InputStream

I'm a beginner in Android development. I'm trying to figure out downloading files with AsyncTask. So far I've been able to bring down HttpUrlConnection and InputStream but I couldn't find anything about downloading the file from the URL. As I…
1
vote
1 answer

Socket programming: Input Stream seems to block Output Stream

I'm trying to code a server-client communicating application which uses two separate threads, one for input and one for output. I'm having a weird "deadlock" issue, though: when one thread reads input, but the client hasn't sent anything, the thread…
Nifty
  • 11
  • 1
  • 2
1
vote
1 answer

How to parse committed InputStream to JSONObject?

I commit an InputStream in from class1 to class2. Now I want to parse the InputStream in class2 to a JSONObject. try { JsonElement element = new JsonParser().parse(new InputStreamReader(in)); JSONObject jsonObject = new…
angelika285
  • 255
  • 1
  • 3
  • 12
1
vote
2 answers

Shouldn't we keep track of the offset when we write to an OutputStream?

The read() method inside copyFile() reads buf.length bytes from the input stream and then it writes them to the output stream from the start until len. public static boolean copyFile(InputStream inputStream, OutputStream out) { byte buf[] = new…
Themelis
  • 4,048
  • 2
  • 21
  • 45
1
vote
1 answer

Java - Is a Connection/Stream already closed if an Exception occurs and how to handle it properly?

I am wondering, if I have some sort of Connection or Stream in my code that should be closed to release ressources, what does it mean for the connection instance itself? Code example: CustomConnection connection; try{ connection = //some code…
patvax
  • 343
  • 3
  • 14
1
vote
3 answers

How to make (Java) program end automatically if input from PIPE is over using InputStream

This question could be better rephrased as: How do you detect EOF in InputStream without blocking I have a java program that is able to take input from System.in directly (without using a Scanner), I can also pipe input into the java program…
retodaredevil
  • 1,261
  • 1
  • 13
  • 20
1
vote
2 answers

Does IOUtils.toByteArray(inputStream) method internally close inputStream object?

Here is my code flow for which file content is getting lost and I think may be IOUtils.toByteArray() line is problem, please guide what is actually going wrong here. File content getting lost : InputStream stream =…
Abhishek
  • 1,558
  • 16
  • 28
1 2 3
99
100