inputstream

java inputStream Freezing

Im trying to run a thread that goes to a socket, grabs the input stream, and reads it. Im creating hundreds of these threads and have set the timeout for reading and yet the thread still stays at the read() line. public void readPack() { socket.setSoTimeout(4*1000); if (socket.isConnected()) { buffer parse = new buffer(); ...

BitmapFactory.decodeStream(inputStream) always return null when some bytes are wrong.

Hi there! I'm building an android app and I'm currently having trouble retrieving a bitmap from an URL. Here is the code I'm using : public static Bitmap bmpFromURL(URL imageURL){ Bitmap result = null; try { HttpURLConnection connection = (HttpURLConnection)imageURL .openConnection(); connection.setDoInput(t...

Java input stream limit: protecting against DoS attacks

I'm coding a tool, that, given any URL, would periodically fetch its output. The problem is that an output could be not a simple and lightweight HTML page (expected in most cases), but some heavy data stream (i.e. straight from /dev/urandom, possible DoS attack). I'm using java.net.URL + java.net.URLConnection, setting connection and re...

Java proxy connection

Im connecting to a proxy and then from the proxy i connect to the server i want. Sometimes the host that the proxy is connected to disconnects and I don't know that happens. Is there something i can send to the proxy server that will tell me if it is connected to the server or not? Or is there a message that the proxy sends to me if it d...

Reading persistence.xml from a POJO

Hi, I have created an EJB3 project and a JPA project. I'm trying to create a helper class(which will be in a separate project/jar) that will return the Persistence Unit Name from the persistance.xml file which is in the META-INF folder of my JPA project. How can I read this file as an Input Stream? I can parse the values once I get a ...

Store BLOB in Android's SQLite using SQLOpenHelper

Is there a way to store a BLOB into Android's SQLite using SQLOpenHelper? My BLOB of type InputStream. ...

Runtime.getRuntime().exec("C:\cygwin\bin\bash.exe") has no input to read

I'm trying to execute a new process and read from its input stream in Java. I have successfully used Runtime.getRuntime().exec(String) to start and receive input from several processes. However, when I try to use exec on some other processes, the input stream's read method blocks, and it appears that there is no input. What might be caus...

Java: What sense could it make not to close an InputStream after it ended?

InputStream implements Closeable. I understand, that closing an InputStream which not ended yet, could make sense to free some underlying resources, and, leaving it open, could make sense to let other methods continue to read from it. But, what sense could it have not to close an InputStream after it ended? And if it doesn't make sense...

Does FileInputStream.skip() do a seek?

Hi all, I want to copy the last 10MB of a possibly large file into another file. Ideally I would use FileInputStream, skip() and then read(). However I'm unsure if the performance of skip() will be bad. Is skip() typically implemented using a file seek underneath or does it actually read and discard data? I know about RandomAccessFi...

Difference between skipBytes and skip of DataInputStream?

Hi! I wonder now, what is the difference between the two methods: DataInputStream.skipBytes and DataInputStream.skip. I am aware of the fact that skip must come from InputStream and skipBytes from DataInput, but still, is there any difference. You know, when using streams in J2ME, things get pretty tricky so I need to know! Would the ...

What does InputStream.available() do in Java?

What does InputStream.available() do in Java? I read the documentation, but I still cannot make it out. The doc says: Returns the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream. The next caller might be the same thread or or another thre...

Java : The constructor JSONTokener(InputStreamReader) is undefined

Hi, I have a quite strange issue with Java, I'm getting an error on some machines only, I would like to know if there is any way I can avoid that: This is the line of code concerned: JSONTokener jsonTokener = new JSONTokener( new InputStreamReader(is, "UTF-8")); This is the error I get on some machines The file *.j...

Get server output while using javax.mail

Hello, I need to implement POP3, IMAP and SMTP servers availability and identity checking by connecting to them, authorizing and comparing expected server output with received server output while doing previously mentioned operations. I'm using Java, so not to reinvent the wheel, I'm also using javax.mail implementation. Everything wor...

Reading USB input stream on linux

Hello, I'm currently working on an embedded linux machine. Im trying to read a USB devices input stream but for some reason I dont have any such thing in my /dev directory. I would assume it would be something like /dev/ttyUSB01 or /dev/input/usb or something similar but it's not there. dmesg returns the following [ 195.863911] input: G...

Java process.getInputStream() has nothing to read, deadlocks child

I am having an issue with some process wrapping, and it's only occurring in Windows XP. This code works perfectly in Windows 7. I'm really stumped as to why the streams are empty in XP. I've also tried using the String[] version of Process.Exec() and it made no difference. I am using the following class to read from the process' STDO...

BufferedInputStream isn't marking

A BufferedInputStream that I have isn't marking correctly. This is my code: public static void main(String[] args) throws Exception { byte[] b = "HelloWorld!".getBytes(); BufferedInputStream bin = new BufferedInputStream(new ByteArrayInputStream(b)); bin.mark(3); while (true){ byte[] buf = new byte[4096]; ...

Playing an audio file from FTP in JavaFx

I have a scenario. I have an audio file on an FTP location. Its a JSP applicaiton. I want to do streaming on my webpage. What I am thinking to open an inputstream on that file that is on ftp location. And connect that input stream to JavaFx player. (never coded Javafx before) So JavaFx will play that buffer. My approach is right? ...

why is my PipedOutputStream deadlocking?

I am trying to implement a threaded circular buffer with PipedInputStream & PipedOutputStream but it is locking everytime when I get to mHead.write in the Decoder runnable. I thought there was no chance for deadlocks when using separate threads. private class DecoderTask implements Runnable{ @Override public void run() { ...

How to detect illegal UTF-8 byte sequences to replace them in java inputstream?

Hi! The file in question is not under my control. Most byte sequences are valid UTF-8, it is not ISO-8859-1 (or an other encoding). I want to do my best do extract as much information as possible. The file contains a few illegal byte sequences, those should be replaces with the replacement character. It's not an easy task, it think it...

SD card writing fails?

Can someone please tell me where I'm going wrong with this piece of code? Basically I want the app to download a .png file, display it to the user and also save it to the sd card for future reference. It seems to be all going fine until the while ((len = webstream.read(buffer)) > 0) part; as the debugger doesn't reach the breakpoint I've...