inputstream

Reading from a ZipInputStream into a ByteArrayOutputStream

I am trying to read a single file from a java.util.zip.ZipInputStream, and copy it into a java.io.ByteArrayOutputStream (so that I can then create a java.io.ByteArrayInputStream and hand that to a 3rd party library that will end up closing the stream, and I don't want my ZipInputStream getting closed). I'm probably missing something bas...

How do you pipe an inputstream to a zipped file as it's read in with Java?

I'm wanting to execute a program and as it runs read in it's output and pipe out the output into a zipped file. The output of the program can be quite large so the idea is to not hold too much in memory - just to send it to the zip as I get it. ...

How do I peek at the first two bytes in an InputStream?

Should be pretty simple: I have an InputStream where I want to peek at (not read) the first two bytes, i.e. I want the "current position" of the InputStream to stil be at 0 after my peeking. What is the best and safest way to do this? Answer - As I had suspected, the solution was to wrap it in a BufferedInputStream which offers markabil...

JavaScript, inputstream and DIB?

Hi all, Is there any useful way to load DIB into inputstream and get a handle to it and all that in JavaScript (js) ? ...

run oracle sql script from java

i have a bunch of sql scripts that should upgrade the database when the java web application starts up. i tried using the ibatis scriptrunner, but it fails gloriously when defining triggers, where the ";" character does not mark an end of statement. now i have written my own version of a script runner, which basically does the job, but...

Creating a byte array from a stream

What is the preffered method for creating a byte array from an input stream? Here is my current solution with .NET 3.5. Is it still a better idea to read and write chunks of the stream? Stream s; byte[] b; using (BinaryReader br = new BinaryReader(s)) { b = br.ReadBytes(s.Length); } ...

Given a Java InputStream, how can I determine the current offset in the stream?

I'd like something like a generic, re-usable getPosition() method that will tell me the number of bytes read from the starting point of the stream. Ideally, I would prefer this to work with all InputStreams, so that I don't have to wrap each and every one of them as I get them from disparate sources. Does such a beast exist? If not, c...

Input Audio as a Stream in CF 3.5

I googled around and coulnd't really find an answer. How do I open an audio input device (namely a microphone) as a stream (preferably) on a CE/WinMobile device using Compact Framework? I looked at WindowsMobile.DirectX, at various classes that contained Audio in their name and nothing seemed to do the trick. What I want to do is basi...

In Java how do a read/convert an InputStream in to a string?

If you have java.io.InputStream object how should you process that object and produce a String? Suppose I have an InputStream that contains text data, and I want to convert this to a String (for example, so I can write the contents of the stream to a log file). What is the easiest way to take the InputStream and convert it to a Strin...

Good design: How to pass InputStreams as argument?

Hello! I've got a big file on which I'm opening a FileInputStream. This file contains some files each having an offset from the beginning and a size. Furthermore I've got a parser that should evaluate such a contained file. File file = ...; // the big file long offset = 1734; // a contained file's offset long size = 256; // a containe...

StreamReader problem - Unknown file encoding (western iso 88591)

When reading data from the Input file I noticed that the ¥ symbom was not being read by the StreamReader. Mozilla Firefox showed the input file type as Western (ISO-8859-1). After playing around with the encoding parameters I found it worked successfully for the following values: System.Text.Encoding.GetEncoding(1252) // (western iso 8...

C/C++: Capture characters from standard input without waiting for enter to be pressed

I can never remember how I do this because it comes up so infrequently for me. But in C or C++, what is the best way to read a character from standard input without waiting for a newline (press enter). Also ideally it wouldn't echo the input character to the screen. I just want to capture keystrokes with out effecting the console screen...

When is InputStream available when uploading a large file?

When is PostedFile.InputStream available when uploading a large file? I'd like to pass a Stream to another process and I'm hoping that if a large file was being uploaded that I can pass the Stream straight to that new process w/o writing to the file system. Since the process and/or upload could take a while, I'm wondering if I can star...

Lightweight java.io.InputStream implementation that supports mark() & reset()

Good day, Currently, we are using ByteArrayInputStream for our reset-able InputStream. My problem with it is that it consumes a lot of memory (it loads all the bytes it represents in memory unlike some other InputStream implementations). My question then is, is there any lighter implementation of InputStream which supports mark() & rea...

Read pdf uploadstream one page at a time with java

I am trying to read a pdf document in a j2ee application. For a webapplication I have to store pdf documents on disk. To make searching easy I want to make a reverse index of the text inside the document; if it is OCR. With the PDFbox library its possible to create a pdfDocument object wich contains an entire pdf file. However to pres...

Android InputStream Internet Disconnect

Hello, In my Android program, I have some code that downloads a file. This works fine, but since on a cell phone, you can be disconnected at any time, I need to change it do it reconnects and resumes the download when you are halfway through and somebody calls/you lose cell reception/etc. I cannot figure out how to detect the InputStream...

What's the best way to monitor an InputStream?

I'm reading a file in via apache.commons.FtpClient. This works fine 99.9% of the time but sometimes it just dies in the read() method... InputStream inStream = ftp.retrieveFileStream(path + file.getName()); String fileAsString = ""; if(inStream == null){ return; } while((c = inStream.read()) != -1){ //this is where the code someti...

java inputstream read blocking

According to the java api, the InputStream.read() is described as: If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown. I have a while(true) loop doing a read and I a...

Best way to use an InputStream regarding persistance and XML

Hi, I have a REST webservice that listens to POST requests and grabs hold of an XML payload from the client and stores it initially as an InputStream i.e. on the Representation object you can call getStream(). I want to utilise the XML held in the InputStream and I am begining to think it would be wise to persist it, so I can interroga...

why does java's inputstream.close() block?

My Java program uses ProcessBuilder (with redirectErrorStream set true) and has a loop that runs the processes's inputstream's read method, which is blocking. The external program I'm calling then comes to a stop waiting for input og stdin. I now want to kill the process. Is this not done by (in a seperate thread) calling the process's d...