inputstream

How to convert an InputStream to a DataHandler?

I'm working on a java web application in which files will be stored in a database. Originally we retrieved files already in the DB by simply calling getBytes on our result set: byte[] bytes = resultSet.getBytes(1); ... This byte array was then converted into a DataHandler using the obvious constructor: dataHandler=new DataHandler(byt...

Slowdowns when reading from an urlconnection's inputstream (even with byte[] and buffers)

Ok so after spending two days trying to figure out the problem, and reading about dizillion articles, i finally decided to man up and ask to for some advice(my first time here). Now to the issue at hand - I am writing a program which will parse api data from a game, namely battle logs. There will be A LOT of entries in the database(20+ ...

Android how to get access to raw resources that i put in res folder?

In J2ME, I've do this like that: getClass().getResourceAsStream("/raw_resources.dat"); But in android, I always get null on this, why? ...

Load files bigger than 1M from assets folder

I'm going crazy, I created a file object, so it can be read with ObjectInputStream, and I placed the assets folder. The method works with a file smaller than 1M, and give error with larger files. I read that is a limit of Android platform, but I also know that can be "easily" avoided. Those who have downloaded the game Reging Thunder, fo...

getResourceAsStream returns HttpInputStream not of the entire file

Hi, I am having a web application with an applet which will copy a file packed witht the applet to the client machine. When I deploy it to webserver and use: InputStream in = getClass().getResourceAsStream("filename") ; The in.available() always return a size of 8192 bytes for every file I tried, which means the file is corrupted wh...

How can I create constrained InputStream to read only part of the file?

I want to create an InputStream that is limited to a certain range of bytes in file, e.g. to bytes from position 0 to 100. So that the client code should see EOF once 100th byte is reached. ...

Can't get InputStream read to block...

I would like the input stream read to block instead of reading end of stream (-1). Is there a way to configure the stream to do this? Here's my Servlet code: PrintWriter out = response.getWriter(); BufferedReader in = request.getReader(); try { String line; int loop = 0; while (loop < 20) { ...

HttpClient response handler always returns closed stream

I'm new to Java development so please bear with me. Also, I hope I'm not the champion of tl;dr :). I'm using HttpClient to make requests over Http (duh!) and I'd gotten it to work for a simple servlet that receives an URL as a query string parameter. I realized that my code could use some refactoring, so I decided to make my own HttpRes...

Java RTSP get contents

Can I download the contents from an RTSP url in java? Just like we can get contents of an HTTP url as an InputStream... Thanks Chris ...

What is the proper way to code a read-while loop in Scala?

What is the "proper" of writing the standard read-while loop in Scala? By proper I mean written in a Scala-like way as opposed to a Java-like way. Here is the code I have in Java: MessageDigest md = MessageDigest.getInstance( "MD5" ); InputStream input = new FileInputStream( "file" ); byte[] buffer = new byte[1024]; int readLen; while...

Why reading my tcp inputstream lead a byte array fill in with null character only?

Hi everyone, I am not used to C# (I do C++ usually) and try to debug an application that is not mine, at all. My application tries to read a big line from a TCP socket. Let say around 140 000 characters. And it fails. Let me explain how. My code is here (inside a loop actually ) System.IO.Stream inputStream; ...

Java resource closing

Hi, I'm writing an app that connect to a website and read one line from it. I do it like this: try{ URLConnection connection = new URL("www.example.com").openConnection(); BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream())); String response = rd.readLine(); rd.close...

Why can php://input be read more than once despite the documentation saying otherwise?

The PHP documentation states that php://input can only be read once. In my application I need to read it twice, once for authentication purposes and once for actually processing the content, and both functions are handled by different, independent modules. The crazy thing is: it works. Can I count on this working everywhere, or is this...

Problem reading InputStream from Java Process (Runtime.getRuntime().exec() or ProcessBuilder)

Hi *, I'm trying to start a process externally with Java and can't read anything from its InputStream - dunno why! If I'm starting a process with commands like "ls", "ps" or "kill" everything works fine. I can start the process and get information either on the InputStream or the ErrorStream of the Process. If I try to use a command l...

Get the content of MultipartFile

I am trying to get the content of MultipartFile, which is obtained through MultipartHttpServletRequest.getFile(). There are 2 functions in MultipartFile, bytes[] getBytes() () InputStream getInputStream() What is the most efficient way to get the content? (which method would you use?) ...

Problem opening/downloading zip-file after decompression (Java/ZipInputStream)

The background Currently, I try to get a zip-file through a HTTP-servlet with a HTTP-request. The received zip-file contains three different files. These files contain information I want to filter out and doing this from the source is not an option (that's just how it is, though I am aware it would be much better). Because I cant filt...

Network IO hangs on BlackBerry OS5

I am having some problems with my network IO code on OS5 of BlackBerry. I keep getting sporadic hangs and eventually TCP timeout exceptions during my IO operations. I am using the 5.0 networking APIs for establishing the connection which works flawlessly every time. The problem is when doing the actual IO. I have a background worker th...

Android AssetManager/InputStream Exception

Doing Android 2.1 development. Can anybody explain to me why the following code generates a IOException and doesn't load the file? This exact code used to work, and as far as I can tell, it should still work. For reference, the Log.d() command correctly lists all files that I expect, and the files are correctly zipped into my .APK file. ...

How do I avoid closing an InputStream passed to my method that I wrap in Reader streams?

I'm creating a Java method that accepts a single InputStream as an argument. For the convenience of working with a character-based stream, I wrap the provided InputStream at the start of the method implementation as follows: public void doStuff(InputStream inStream) { BufferedReader reader = new BufferedReader(new InputStreamReader(...

Reading an audiostream in python.

Hi, Amazingly, in bash, you can do $ curl http://mp3.streampower.be/radio1-high.mp3 > test.mp3 with an audiostream and then ^C out, and you will have a working mp3 file, leading me to believe I could have this automated in python, but I can't find how. If i just do file('python.mp3', 'w').write(urllib2.urlopen("http://mp3.streampo...