Can somebody help me in ByteArrayinputStream read(Byte[]) is not blocking.

I am setting String "User" in inputStream now Once it is read and inputsteram is blocking for other input i want to send
another strign in input Stream i.e "password" so first "User" will print and then it will print "Password", but ins.read(buff) method is not blocking and returning -1 after reading "User".
Following is the program:
package abc;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
public class InStream {
InputStream in;
String value;
boolean flag=true;
Inner inc;
InputStream getInStream() {
ByteArrayInputStream bais = new ByteArrayInputStream(value.getBytes());
return bais;
void setValue(String value) {
try {
this.value=value;
} catch (Exception e) {
void execute() {
try {
setValue("User");
inc = new Inner();
inc.start();
Thread.sleep(10);
setValue("Password");
inc.ins=getInStream();
} catch (Exception e) {
e.printStackTrace();
class Inner extends Thread {
InputStream ins;
public void run() {
try {
int retRead = 0;
byte[] buff = new byte[2048];
String receivedStr=null;
ins = getInStream();
do{
retRead = ins.read(buff);
receivedStr = new String(buff, 0, retRead);
System.out.println(receivedStr);
}while (retRead>0);
System.out.println("Out");
} catch (Exception e) {
e.printStackTrace();
public static void main(String[] args){
InStream instream=new InStream();
instream.execute();
}

You create that byte[] input stream once and use it to read its contents into a large buffer. So it is read to the end at the first time, and the next reading will indicate the end.
What is the problem?
ins = getInStream();
do{
retRead = ins.read(buff);
receivedStr = new String(buff, 0, retRead);
System.out.println(receivedStr);
}while (retRead>0);
System.out.println("Out");
} catch (Exception e) {
e.printStackTrace();
}

Similar Messages

Maybe you are looking for

  • How to Read from multiple channels

    Dear Sir I am acquiring data using FP-RTD-122 using OPC Client software. I ahve made one socket for that and i am using command CWDataSocket1.AccessMode = cwdsReadAutoUpdate CWDataSocket1.URL = "opc://localhost/National Instruments.OPCFieldPoint/FP R

  • Volume Slider not working in DV6-2150US

    I have HP Pavilion Notebook DV6-2150US, Win 7.  Just discovered a few days ago that the volume slider and quick launch mute button stopped working.  I searched the old posts but don't know if this relates to other issues mentioned.

  • Frontrow is Jerky

    Since upgrading from Leopard to Snow Leopard, Frontrow now plays the videos very Jerky. Irregardless of downloaded digital content from iTunes or a DVD. Can anyone say if they have the same problem or a reason why this may be occurring on my machine?

  • How to use a collection in ADF

    Hi all, How to use the collection in ADF. Thanks in advance C.Karukkuvel

  • Shocking HDMI connection

    I've been using my BT youview box connected to my Panasonic TV with the BT supplied HDMI cable successfully for several months. But for the last two weeks I've encountered a variety of problems e.g. Box locks up and will not respond to remote control